Texture.lock

Lock the texture to manipulate its pixeldata

Locks the thexture meaning that the texture can't be used for anything untill its $(CU unlock) method is called

A pointer is returned. It points to the pixeldata wich can be manipulated. The length of the pixeldata is the textures width*height. The value for a pixel at location x, y can be obtained by getting the element at index y * width + x

class Texture
uint*
lock
()

Return Value

Type: uint*

A pointer to the pixeldata,

Examples

auto window = new Window(800, 400, "myTestWindow"); //create a window
auto texture = new Texture(window, 300, 100); //create a texture
uint* pixels = texture.lock() //lock the texture and get the pixeldata pointer
pixels[10 * texture.getWidth() + 20] = 0x00FF0000; // make the pixel at position 20, 10 red
texture.lock() //now were done manipulating the pixels, unlock the texture

// render the texture to the window
SDL_RenderCopy(window.getRenderer(), texture.getTexture(), SDL_Rect(0,0,300,100), SDL_Rect(0,0,800,400));
SDL_RenderPresent(window.getRenderer());

Meta