Rev 8215 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8215 | maxcodehac | 1 | #include "SDL.h" |
2 | #include |
||
3 | |||
9172 | turbocat | 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) |
||
8215 | maxcodehac | 10 | { |
9172 | 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; |
||
17 | *pixmem32 = colour; |
||
8215 | maxcodehac | 18 | } |
9172 | turbocat | 19 | |
20 | |||
21 | void DrawScreen(SDL_Surface* screen, int h) |
||
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); |
||
41 | } |
||
42 | |||
43 | |||
44 | int main(int argc, char* argv[]) |
||
45 | { |
||
46 | SDL_Surface *screen; |
||
47 | SDL_Event event; |
||
48 | |||
49 | int keypress = 0; |
||
50 | int h=0; |
||
51 | |||
52 | if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
||
53 | |||
54 | if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE))) |
||
55 | { |
||
56 | SDL_Quit(); |
||
57 | return 1; |
||
58 | } |
||
59 | |||
60 | while(!keypress) |
||
61 | { |
||
62 | DrawScreen(screen,h++); |
||
63 | while(SDL_PollEvent(&event)) |
||
64 | { |
||
65 | switch (event.type) |
||
66 | { |
||
67 | case SDL_QUIT: |
||
68 | keypress = 1; |
||
69 | break; |
||
70 | case SDL_KEYDOWN: |
||
71 | keypress = 1; |
||
72 | break; |
||
73 | } |
||
74 | } |
||
75 | } |
||
76 | |||
77 | SDL_Quit(); |
||
78 | return 0; |
||
79 | }>>>> |