SDL_Surface* imagen = SDL_LoadBMP( "imagen.bmp" );
Uint32 key = getpixel( imagen, 0, imagen->h );
SDL_SetColorKey( imagen, SDL_SRCCOLORKEY, key );
// Nota, código obtenido del wiki de SDL
// http://www.libsdl.org/cgi/docwiki.cgi/Pixel_20Access
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 */
}
}
Uint32 key = getpixel( imagen, 0, imagen->h - 1 );
SDL_SetColorKey( imagen, SDL_SRCCOLORKEY, key );
while (SDL_PollEvent(&evento))
{
if (evento.type== SDL_KEYDOWN)
{
switch (evento.key.keysym.sym)
{
case SDLK_ESCAPE: bucle= false; break;
case SDLK_p: avion.CfgPosicion(0,0); break;
case SDLK_m: avion.Mover(3,0); break;
case SDLK_a: avion.CfgAlpha(12,1); break;
}
}
}
void Clear(SDL_Surface *surface, Uint32 color)
{
SDL_Rect rect={0, 0, surface->w, surface->h};
SDL_FillRect(surface, &rect, color);
}
// Color negro para el fondo
Uint32 color=SDL_MapRGB(screen->format, 0, 0, 0);
// Limpia la pantalla, suponemos que screen es la surface
// que nos retornó SDL_SetVideoMode
Clear(screen, color);
Uint8 *keyboard=SDL_GetKeyState(0);
if (keyboard[SDLK_RIGHT])
avion.Mover(3,0);
Volver a Sobre las bibliotecas multimedia
Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 0 invitados