As we speak in the previous chapter, we discuss how to display a picture on the sdl_surface.
No more talk of nonsense ... Just cut to the chase. The basic functions we use in this step are
Sdl_surface * Sdlcall img_load (const char *file);
The function argument is the picture file name,
Careful people will ask a question, how this picture is also a sdl_sruface* ah, yes, is a sdl_sruface*
The picture we have on our own screen is to put this picture on our own screen, but we should be able to understand the movie now. That is to switch the number of pictures per second, then what is our specific steps:?
1. Initialize a sdl_video, build our own sdl_sruface*
2. Load the picture, generate a sdl_sruface* again
Sdl_surface *pic = img_load (const char *file);
3. Paste the sdl_surface of the picture on the sdl_sruface of the screen
Sdl_blitsurface (pic,0,screen,0);
4. Refresh the screen, this can have at least two different methods, I will no longer be here tired to state ...
5. Release the resources, this must not forget ... Avoid, programming must develop a good habit, good habit is half of success.
#include <SDL.h>
#include <SDL_gfxPrimitives.h>
#include <SDL_image.h>
#include < sdl_rotozoom.h>
#include <SDL_ttf.h>
#include <stdio.h>
int main (int argc,char *argv[])
{
if (Sdl_init (Sdl_init_video) < 0 | | | Ttf_init () < 0)
{
printf ("Init error\n");
return-1;
}
Sdl_surface *screen = Sdl_setvideomode (640,480,32,sdl_swsurface);
if (!screen)
{
printf ("Init video mode error\n");
return-1;
}
Sdl_surface *pic = img_load ("Sample.bmp");
if (!pic)
{
printf ("Load bmp error\n");
return-1;
}
Sdl_blitsurface (pic,0,screen,0);
Sdl_updaterect (screen,0,0,0,0);
Sdl_freesurface (pic);
Sdl_delay ();
Ttf_quit ();
Sdl_quit ();
return 0;
}
This article is from the "Late Evening" blog, please be sure to keep this source http://yiluohuanghun.blog.51cto.com/3407300/833361