#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <SDL/SDL.h>
#include <windows.h>
#include <time.h>
SDL_Surface *screen = NULL;
void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
{
int bpp = surface->format->BytesPerPixel;
Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
switch(bpp) {
case 1:
*p = pixel;
break;
case 2:
*(Uint16 *)p = pixel;
break;
case 3:
if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
p[0] = (pixel >> 16) & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = pixel & 0xff;
}
else
{
p[0] = pixel & 0xff;
p[1] = (pixel >> 8) & 0xff;
p[2] = (pixel >> 16) & 0xff;
}
break;
case 4:
*(Uint32 *)p = pixel;
break;
}
}
static void draw ()
{
srand(time(0));
Uint32 color;
color = SDL_MapRGB (screen->format, rand()%255, rand()%255, rand()%255);
for (int x = 0; x < 640; x++)
{
for (int y = 0; y < 480; y++)
{
color = SDL_MapRGB (screen->format, rand()%255, rand()%255, rand()%255);
putpixel(screen,x,y,color);
}
}
SDL_Flip(screen);
}
int main (int argc, char *argv[])
{
SDL_Init (SDL_INIT_VIDEO);
screen = SDL_SetVideoMode (640,480, 32,0);
SDL_WM_SetCaption ("Application", NULL);
int done = 0;
while (!done)
{
SDL_Event event;
while (SDL_PollEvent (&event))
{
switch (event.type)
{
case SDL_KEYDOWN:
break;
case SDL_QUIT:
done = 1;
break;
default:
break;
}
}
draw ();
}
return 0;
}
|