-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Santiago Romero escribi?:
Does anybody have a simple example of the use of SDL_image
to load a .jpeg/.png file, set a colorkey to (0,0,0) and
blit it in the screen to (100,100), by example?
thx a lot for any help!
Something like this ?
#include <stdio.h>
#include <SDL.h>
#include <SDL_image.h>
int main(int argc, char **argv)
{
int exited=0;
SDL_Surface *screen, *image;
SDL_Rect rect;
if(SDL_Init(SDL_INIT_VIDEO)<0){
fprintf(stderr,"Couldn't initialise SDL: %i\n",
SDL_GetError());
exit(1);
}
atexit(SDL_Quit);
screen=SDL_SetVideoMode(640,480,16,SDL_SWSURFACE);
if(screen==NULL){
fprintf(stderr,“Couldn’t set video mode: %s\n”,
SDL_GetError());
exit(1);
}
image=IMG_Load("/windoc/face.jpg");
if(image==NULL){
fprintf(stderr,“Couldn’t load image\n”);
exit(1);
}
if(SDL_SetColorKey(image,SDL_RLEACCEL,SDL_MapRGB(image->format,0,0,0))
0){
fprintf(stderr,“Couldn’t ser color key: %s\n”,SDL_GetError());
exit(1);
}
image=SDL_DisplayFormat(image);
rect.x=100;rect.y=100;rect.w=image->w;rect.h=image->h;
SDL_BlitSurface(image,0,screen,&rect);
SDL_UpdateRects(screen,1,&rect);
while(exited==0){
SDL_Event event;
if(SDL_PollEvent(&event)==1){
if((event.type==SDL_KEYDOWN &&
event.key.keysym.sym==SDLK_ESCAPE) ||
(event.type==SDL_QUIT))exited=1;
}
}
return 0;
}
Un saludo.
Jes?s Carrete Monta?a ----> KUANTIKO___________________________________________
| .~. |
| /V\ jrcarmon(arroba)teleline.es |
| // \ Linux Registered |
| /( )\ User #158442 |
| ^`~’^ |
|___________________________________________|
Clave p?blica PGP disponible por e-mail.
-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1i for non-commercial use http://www.pgpi.com/
iQA/AwUBOV3fwVXBzV6UX+HYEQJvaACfcBW5DsSitmDpaGOEXC1EERkKMekAoN/Q
QIt2x28m00dNAx4LbbwUplFC
=nBvD
-----END PGP SIGNATURE-----