Create
This function creates a new texture.
Syntax
- static Texture* Create(int width, int height, int format=Texture::RGBA, int flags=0, int frames=1, int samples=0)
Parameters
- width: the width of the new texture.
- height: the width of the new texture.
- format: the format of the texture.
- flags: this value can be Texture::Mipmaps or zero.
- frames: the number of animation frames. This value can be any number above zero.
- samples: the number of texture samples per pixel. A value of zero will disable texture multisampling. Note that not all graphics drivers support multisampled textures.
Example
#include "Leadwerks.h"
using namespace Leadwerks;
int main(int argc, const char *argv[])
{
Leadwerks::Window* window = Leadwerks::Window::Create();
Context* context = Context::Create(window);
Texture* texture = Texture::Create(256, 256);
char* pixels = (char*)malloc(texture->GetMipmapSize(0));
char r, g, b;
for (int x = 0; x < 256; x++)
{
for (int y = 0; y < 256; y++)
{
int p = (x*texture->GetWidth() + y) * 4;
memcpy(&r, pixels + p + 0, 1);
memcpy(&g, pixels + p + 1, 1);
memcpy(&b, pixels + p + 2, 1);
if (x < 128)
{
if (y < 128)
{
r = 0; g = 0; b = 255;
}
else
{
r = 255; g = 0; b = 0;
}
}
else
{
if (y < 128)
{
r = 255; g = 0; b = 0;
}
else
{
r = 0; g = 0; b = 255;
}
}
memcpy(pixels + p + 0, &r, 1);
memcpy(pixels + p + 1, &g, 1);
memcpy(pixels + p + 2, &b, 1);
}
}
texture->SetPixels(pixels);
while (true)
{
if (window->Closed() || window->KeyDown(Key::Escape)) return false;
context->SetColor(0, 0, 0, 0);
context->Clear();
//Display the texture on screen
context->SetColor(1, 1, 1, 0);
context->DrawImage(texture, 0, 0);
context->Sync();
}
return 0;
}