SDL Course: Picture loading of course design

Source: Internet
Author: User
Tags printf

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.