Getting SDL_Surface Pixel Values
Hi, I'll like to get the RGB (and eventually A) values of an SDL Surface. I keep getting a segementation error. Here's the Code: void CSprite::getpixel(int x, int y) { SDL_LockSurface( State[mframe].image ); char * pData; pData = (char*)State[mframe].image->pixels; pData+=(y*State[mframe].image->pitch); pData+=(x*State[mframe].image->format->BytesPerPixel); SDL_PixelFormat *fmt = State[mframe].image->format; Uint8 *lr, *lg, *lb; //-- Craps out here Uint32 pixel = *(Uint32 *)pData; SDL_GetRGB(pixel, fmt, lr, lg, lb); SDL_UnlockSurface( State[mframe].image ); } Can anyone help me? Thanks in advance
Uint8 *lr, *lg, *lb;//-- Craps out hereUint32 pixel = *(Uint32 *)pData;SDL_GetRGB(pixel, fmt, lr, lg, lb);
lr,lg,and lb are pointers to nowhere, the SDL_GetRGB call is writing to random memory. Try this:
Uint8 lr, lg, lb;Uint32 pixel = *(Uint32 *)pData;SDL_GetRGB(pixel, fmt, &lr, ≶, &lb);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement