SDL Process: Drawing of curriculum design

Source: Internet
Author: User
Tags printf

In my last article in the SDL series I've covered the installation process for SDL and its detailed steps, so let's start our SDL journey.

This article focuses on how to use SDL to make a simple color automatic palette.

According to the SDL official documentation, it is easy to get the steps to create a screen:

First we want to initialize a video and then get a sdl_surface;

Sdl_init (Sdl_init_video);

Sdl_surface *screen = Sdl_setvideomode (640,480,32,sdl_swsurface);

If the function call succeeds, everything is OK,

SDL provides users with a lot of paint APIs, which are in the Sdl_gfxprimitives.h file

Here we only use one of them to achieve our function.

Boxrgba (Sdl_surface * DST, Sint16 x1, Sint16 y1, Sint16 x2,    
  Sint16 y2, Uint8 R, Uint8 G, Uint8 B, Uint8 a);

This function will enable us to show the patterns we want to draw on DST ... Does it feel so high? It's that simple.

Below I will put the specific code posted for everyone to share under ...

#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)    
 {    
  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;    
 }    
 int i = 255;    
 for (; I >= 0; i--)    
 {    
  sdl_fillrect (screens, &screen->clip_rect, 0x0);    
  Boxrgba (screens, 255, 0, 0, i);    
  Sdl_delay (a);    
  Sdl_updaterects (Screen,1,&screen->clip_rect);    
          
 }    
 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/832855

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.