Here's another example. This one fills the screen with a blue gradient background.
In the spirit of keeping it short and sweet, I've left out error checking, and not really made allowances for different screen sizes, etc... Obviously, you'd want to add these niceties in a real app.
Here's another example. This one fills the screen with a blue gradient background.
In the spirit of keeping it short and sweet, I've left out error checking, and not really made allowances for different screen sizes, etc... Obviously, you'd want to add these niceties in a real app.
And without further ado....
/*******************************************************
gradient.c
********************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <SDL.h>
int main (int argc, char *argv[])
{
SDL_Surface *screen;
SDL_Rect section;
SDL_PixelFormat pixel;
int count1, count2;
Uint32 color;
SDL_Init (SDL_INIT_VIDEO);
atexit(SDL_Quit);
screen = SDL_SetVideoMode (800, 600, 0, SDL_HWSURFACE);
count2 = 255;
for (count1 = 0; count1 < 600; count1++)
{
section.x = 0;
section.y = count1;
section.w = 800;
section.h = 1;
color = SDL_MapRGB (screen->format, 0x00, 0x00, count2 - (count1 / 3));
SDL_FillRect (screen, §ion, color);
}
SDL_UpdateRect (screen, 0, 0, 800, 600);
sleep (5);
return 0;
}