but this don’t return me the rgb code, it returns me an non-sense
number that isn’t correct.
frog is a global struct that have the position of a sprite (frog.pos)
, i want to know if the upper left corner of the sprite (800x600
screen size) is over the “black zone” of the mask of the background.
Uint32 GetPixel(SDL_Surface *surf, int x, int y)
{
//This function returns pixels color
int bpp = surf->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surf->pixels + y * surf->pitch + x * bpp;
switch (bpp)
{
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0;
}
}
then use SDL_GetRGB to convert the Uint32 color value into pixel rgb format.— http://gamescreators.sf.net Linux game developing community
----- Original Message -----
From: ferranf@gmail.com (f)
To: sdl at libsdl.org
Date: Mon, 3 Jul 2006 21:06:34 +0200
Subject: [SDL] truble to get the color of a surface pixel
i need to get the color of a pixel of specific position of a surface,
i’m trying something like this:
but this don’t return me the rgb code, it returns me an non-sense
number that isn’t correct.
frog is a global struct that have the position of a sprite (frog.pos)
, i want to know if the upper left corner of the sprite (800x600
screen size) is over the “black zone” of the mask of the background.
Uint32 GetPixel(SDL_Surface *surf, int x, int y)
{
//This function returns pixels color
int bpp = surf->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surf->pixels + y * surf->pitch + x * bpp;
switch (bpp)
{
case 1:
return *p;
case 2:
return *(Uint16 *)p;
case 3:
if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
return p[0] << 16 | p[1] << 8 | p[2];
else
return p[0] | p[1] << 8 | p[2] << 16;
case 4:
return *(Uint32 *)p;
default:
return 0;
}
}
then use SDL_GetRGB to convert the Uint32 color value into pixel rgb format.
-----Original Message-----
From: f <@f11>
To: sdl at libsdl.org
Date: Mon, 3 Jul 2006 21:06:34 +0200
Subject: [SDL] truble to get the color of a surface pixel
i need to get the color of a pixel of specific position of a surface,
i’m trying something like this:
but this don’t return me the rgb code, it returns me an non-sense
number that isn’t correct.
frog is a global struct that have the position of a sprite (frog.pos)
, i want to know if the upper left corner of the sprite (800x600
screen size) is over the “black zone” of the mask of the background.