Subversion Repositories Kolibri OS

Rev

Rev 9204 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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