eobish
view src/main.cc @ 1:bc0996863c79
foo
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 17 Jan 2015 18:40:49 +0200 |
parents | |
children | cdbcae5b3b98 |
line source
1 #include <stdio.h>
2 #include <SDL/SDL.h>
4 static void display();
5 static bool proc_event(SDL_Event *ev);
6 static void set_pal_entry(int idx, int r, int g, int b);
8 static SDL_Surface *fbsurf;
10 int main(int argc, char **argv)
11 {
12 SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER);
14 if(!(fbsurf = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE))) {
15 fprintf(stderr, "failed to set video mode\n");
16 return 1;
17 }
18 set_pal_entry(1, 255, 0, 0);
20 for(;;) {
21 SDL_Event ev;
22 while(SDL_PollEvent(&ev)) {
23 if(!proc_event(&ev)) {
24 goto done;
25 }
26 }
28 display();
29 }
31 done:
32 SDL_Quit();
33 return 0;
34 }
36 void display()
37 {
38 if(SDL_MUSTLOCK(fbsurf)) {
39 SDL_LockSurface(fbsurf);
40 }
42 unsigned char *pixels = (unsigned char*)fbsurf->pixels;
43 for(int i=0; i<fbsurf->w * fbsurf->h; i++) {
44 *pixels++ = 1;
45 }
47 if(SDL_MUSTLOCK(fbsurf)) {
48 SDL_UnlockSurface(fbsurf);
49 }
51 SDL_Flip(fbsurf);
52 }
54 static bool proc_event(SDL_Event *ev)
55 {
56 switch(ev->type) {
57 case SDL_KEYDOWN:
58 if(ev->key.keysym.sym == SDLK_ESCAPE) {
59 return false;
60 }
61 break;
63 default:
64 break;
65 }
66 return true;
67 }
69 static void set_pal_entry(int idx, int r, int g, int b)
70 {
71 SDL_Color col;
72 col.r = r;
73 col.g = g;
74 col.b = b;
76 SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1);
78 /*palette[idx].r = r;
79 palette[idx].g = g;
80 palette[idx].b = b;*/
81 }