Subversion Repositories Kolibri OS

Rev

Rev 8215 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 8215 Rev 9172
Line 1... Line 1...
1
#include "SDL.h"
1
#include "SDL.h"
2
#include 
2
#include 
Line -... Line 3...
-
 
3
 
-
 
4
#define WIDTH 640
-
 
5
#define HEIGHT 480
-
 
6
#define BPP 4
-
 
7
#define DEPTH 32
-
 
8
 
-
 
9
void setpixel(SDL_Surface *screen, int x, int y, Uint8 r, Uint8 g, Uint8 b)
-
 
10
{
-
 
11
    Uint32 *pixmem32;
-
 
12
    Uint32 colour;  
-
 
13
 
-
 
14
    colour = SDL_MapRGB( screen->format, r, g, b );
-
 
15
 
-
 
16
    pixmem32 = (Uint32*) screen->pixels  + y + x;
-
 
17
    *pixmem32 = colour;
-
 
18
}
-
 
19
 
3
 
20
 
-
 
21
void DrawScreen(SDL_Surface* screen, int h)
4
SDL_Surface* screen;
22
{
-
 
23
    int x, y, ytimesw;
-
 
24
 
-
 
25
    if(SDL_MUSTLOCK(screen))
-
 
26
    {
-
 
27
        if(SDL_LockSurface(screen) < 0) return;
-
 
28
    }
-
 
29
 
-
 
30
    for(y = 0; y < screen->h; y++ )
-
 
31
    {
-
 
32
        ytimesw = y*screen->pitch/BPP;
-
 
33
        for( x = 0; x < screen->w; x++ )
-
 
34
        {
-
 
35
            setpixel(screen, x, ytimesw, (x*x)/256+3*y+h, (y*y)/256+x+h, h);
-
 
36
        }
-
 
37
    }
-
 
38
    if(SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen);
-
 
39
 
-
 
40
    SDL_Flip(screen);
Line -... Line 41...
-
 
41
}
5
static int done = 0;
42
 
6
 
43
 
-
 
44
int main(int argc, char* argv[])
7
int main()
45
{
-
 
46
    SDL_Surface *screen;
-
 
47
    SDL_Event event;
-
 
48
 
-
 
49
    int keypress = 0;
8
{
50
    int h=0;
-
 
51
 
-
 
52
    if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1;
-
 
53
   
9
	SDL_Event event;
54
    if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE)))
10
	if(SDL_Init(SDL_INIT_VIDEO) < 0) exit(0);
55
    {
-
 
56
        SDL_Quit();
-
 
57
        return 1;
11
	atexit(SDL_Quit);
58
    }
12
	screen = SDL_SetVideoMode(320, 200, 8, SDL_SWSURFACE);
59
 
-
 
60
    while(!keypress)
13
	while(!done)
61
    {
14
		{
62
         DrawScreen(screen,h++);
15
		while(SDL_PollEvent(&event))
63
         while(SDL_PollEvent(&event))
16
		{
64
         {      
17
			switch(event.type)
-
 
18
			{
65
              switch (event.type)
19
				case SDL_KEYDOWN:
66
              {
20
				case SDL_QUIT:
67
                  case SDL_QUIT:
21
				 done=1;
68
                      keypress = 1;
-
 
69
                      break;
22
				 break;
70
                  case SDL_KEYDOWN:
23
				default:
71
                       keypress = 1;
24
				 break;
72
                       break;
25
			}
73
              }
-
 
74
         }
-
 
75
    }
-
 
76
 
26
		}
77
    SDL_Quit();