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