Create

This function creates a new texture.

Syntax

Parameters

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;
}