Subversion Repositories Kolibri OS

Rev

Rev 9204 | Details | Compare with Previous | Last modification | View Log | RSS feed

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