• Advertisement

Archived

This topic is now archived and is closed to further replies.

getPixel in SDL

This topic is 5502 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

im trying to do a getpixel function in SDL.. i read the example but somehow it doesn''t work.. i have a 16 bits depth surface i locked it before getting the pixel. and im doing that: Uint16 *getPixel(SDL_Surface *surf, int x, int y) { Uint16 *pixel = (Uint16 *)surf->pixels + y * surf->pitch + x * 2; return pixel; } the pixel returned by the function i use it in the SDL_GetRGB.. but the r,g,b paramteres doesn''t get the real values.. why is that?

Share this post


Link to post
Share on other sites
Advertisement
The problem is that you are casting your pointer to a Uin16 pointer before adding the offset, try this:

Uint16 *pixel= (Uint16 *)(surf->pixels+y*surf->pitch + x*2);

If you have a Uin16 pointer and add a certain value ''i'' to it, in fact you are adding ''2*i'' to it, since each element has size = 2 bytes.

I hope this helps

Share this post


Link to post
Share on other sites
SDL changes the bpp that you pass in the SDL_SetVideoMode..

the problem was that SDL gives me a 24 bpp depth and i was mulptiplying it by 2.

one other thing.. i had to cast it to Uint32 to work well.

thanks for your concern

Share this post


Link to post
Share on other sites

  • Advertisement