pitch set by LockTexture is 0 to 3 bytes larger than window width * pixel size (RGB24)

When resizing the window and locking the texture created from the renderer of the window on SDL_WINDOWEVENT_SIZE_CHANGED, the pitch set by locking is 0 to 3 bytes larger than the new window width * size of 1 pixel (3 (bytes) with SDL_PIXELFORMAT_RGB24).

How would I write to a x, y window coordinate?

Neither y * width * 3 + x * 3 nor y * pitch + x * 3 produce correct results (after unlocking) in cases where the “larger” is not 0. (operating on the pixels pointer set by locking)

EDIT: I memcpy 1 pixel = 3 bytes of RGB to that computation

That’s padding bytes added for optimization. Why? Probably it’s aligned for SIMD. You can ignore them or write to them safely, doesn’t matter.

1 Like

Hi, i thank you for your answer.

So these padding bytes are at the end of each “row”.

Thus y * pitch + x * 3 writes the whole texture (for every x, y within width, height).

I see this does, I didn’t adjust a second place in my code before.

1 Like