Trying to figure out SDL pixel manipulation?

Posted by NoobScratcher on Game Development See other posts from Game Development or by NoobScratcher
Published on 2012-10-03T13:16:19Z Indexed on 2012/10/03 15:52 UTC
Read the original article Hit count: 291

Filed under:
|

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

© Game Development or respective owner

Related posts about sdl

Related posts about pixel