Rev 9172 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9172 | Rev 9288 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "SDL.h" |
1 | #include "SDL.h" |
2 | #include |
2 | #include |
Line 3... | Line -... | ||
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 | - | ||
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 | { |
3 | |
46 | SDL_Surface *screen; |
- | |
47 | SDL_Event event; |
- | |
48 | 4 | SDL_Surface* screen; |
|
49 | int keypress = 0; |
- | |
Line 50... | Line 5... | ||
50 | int h=0; |
5 | static int done = 0; |
51 | - | ||
52 | if (SDL_Init(SDL_INIT_VIDEO) < 0 ) return 1; |
- | |
53 | 6 | ||
54 | if (!(screen = SDL_SetVideoMode(WIDTH, HEIGHT, DEPTH, SDL_FULLSCREEN|SDL_HWSURFACE))) |
7 | int main() |
- | 8 | { |
|
55 | { |
9 | SDL_Event event; |
56 | SDL_Quit(); |
10 | if(SDL_Init(SDL_INIT_VIDEO) < 0) exit(0); |
57 | return 1; |
- | |
58 | } |
11 | atexit(SDL_Quit); |
59 | 12 | screen = SDL_SetVideoMode(320, 200, 8, SDL_SWSURFACE); |
|
60 | while(!keypress) |
- | |
61 | { |
13 | while(!done) |
62 | DrawScreen(screen,h++); |
14 | { |
63 | while(SDL_PollEvent(&event)) |
15 | while(SDL_PollEvent(&event)) |
64 | { |
16 | { |
- | 17 | switch(event.type) |
|
65 | switch (event.type) |
18 | { |
66 | { |
19 | case SDL_KEYDOWN: |
67 | case SDL_QUIT: |
20 | case SDL_QUIT: |
68 | keypress = 1; |
21 | done=1; |
69 | break; |
- | |
70 | case SDL_KEYDOWN: |
22 | break; |
71 | keypress = 1; |
23 | default: |
72 | break; |
24 | break; |
73 | } |
25 | } |
74 | } |
- | |
75 | } |
- | |
76 | - | ||
77 | SDL_Quit(); |
26 | } |