1.使用sdl显示bmp格式的图片,但是由于是初级,所以有点小问题。
#include<SDL.h>
//#include<iostream>
#include<stdio.h>
void display_bmp(char *fileName)
{
}
int main()
{
printf("initializesdl \n");
if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO ) == -1)
{
return 1;
}//iniif
atexit(SDL_Quit);
SDL_Surface *screen;
screen = SDL_SetVideoMode(640,480,8,SDL_SWSURFACE|SDL_ANYFORMAT);
if(screen ==NULL)
return 2;
SDL_Surface *img;
img = SDL_LoadBMP("hello.bmp");
if(img == NULL)
exit(2);
if(img->format->palette && screen->format->palette)
{
SDL_SetColors(screen,img->format->palette->colors,0,
img->format->palette->ncolors);
}
/* Blit onto the screen surface */
if(SDL_BlitSurface(img, NULL, screen, NULL) < 0)
fprintf(stderr, "BlitSurface error: %s\n", SDL_GetError());
SDL_UpdateRect(screen, 0, 0, img->w, img->h);
while(1);
/* Free the allocated BMP surface */
SDL_FreeSurface(img);
return 0;
}