SetPixels
This function sets the pixel data of a texture.
Syntax
- void SetPixels(const char* buf, int miplevel=0, int framenumber=0, int cubeface=0)
Parameters
- buf: the memory buffer to read the pixel data from.
- miplevel: the mipmap level to set the pixel data for.
- framenumber: the animation frame number to set the pixel data for.
- cubeface: the cubemap face to set the mipmap level for.
Remarks
The Texture::GetMipmapSize() function should be used to ensure the supplied memory buffer is the correct size.
This function is not available in Lua.
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::Load("Materials/Grass/grass01.tex");
//Create a buffer to store pixel data in
char* pixels = (char*)malloc(texture->GetMipmapSize(0)*8);
//Get the pixel data from the texture and invert it
texture->GetPixels(pixels);
char r, g, b;
for (int x = 0; x < 512; x++)
{
for (int y = 0; y<512; 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);
r = 255 - r;
g = 255 - g;
b = 255 - b;
memcpy(pixels + p + 0, &r, 1);
memcpy(pixels + p + 1, &g, 1);
memcpy(pixels + p + 2, &b, 1);
}
}
//Set the modified pixel data
texture->SetPixels(pixels);
free(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;
}