sdl prob
I think that the getpixel function (existed in sdl documentation) gets the color of the coordinate indicated by x and y
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
Uint32 getpixel(SDL_Surface *surface, int x, int y)
{
int bpp = surface->format->BytesPerPixel;
/* Here p is the address to the pixel we want to retrieve */
Uint8 *p = (Uint8 *)surface->pixels + y * surface->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; /* shouldn't happen, but avoids warnings */
}
}
|
my problem is that, I want to compare it with the white/black color ,so how can I do that?
I tried this way but it does not work
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
int main(int argc,char *argv[])
{
SDL_Init(SDL_INIT_VIDEO);
SDL_Surface *screen = SDL_SetVideoMode(600,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF);
SDL_Event event;
bool pass = true;
SDL_Color color = {0,0,0};/// Black color
if(color==getpixel(screen,0,0)
pass = false;
while(pass)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
pass = false;
break;
}
}
SDL_FreeSurface(screen);
SDL_Quit();
return 0;
}
|
the error
C:\Documents and Settings\Techno01\Bureau\sdl\main.cpp|83|error: no match for 'operator==' in 'color == getpixel(screen, 0, 0)'| |
Pretty much exactly what it says. SDL_Color has no operator== defined for it. You have to define what it means for one SDL_Color to equal another.
So how can I know that the color return by the getpixel function is white or any other color ?
can you help me with this one?
Topic archived. No new replies allowed.