Trying to figure out SDL pixel manipulation?
- by NoobScratcher
Hello so I've found code that plots a pixel in an SDL Screen Surface :
void putpixels(int x, int y, int color)
{
unsigned int *ptr = (unsigned int*)Screen->pixels;
int lineoffset = y * (Screen->pitch / 4 );
ptr[lineoffset + x ] = color;
}
But I have no idea what its actually doing here this is my thoughts.
You make an unsigned integer to hold the unsigned int version of pixels
then you make another integer to hold the line offset and it equals to multiply by pitch which is then divided by 4 ...
Now why am I dividing it by 4 and what is the pitch and why do I multiply it??
Why must I change the lineoffset and add it to the x value then equal it to colors?
I'm soo confused.. ;/
I found this function here - http://sol.gfxile.net/gp/ch02.html