eobish
diff src/main.cc @ 0:465ca72c9657
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 17 Jan 2015 18:37:28 +0200 |
parents | |
children | cdbcae5b3b98 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/main.cc Sat Jan 17 18:37:28 2015 +0200 1.3 @@ -0,0 +1,81 @@ 1.4 +#include <stdio.h> 1.5 +#include <SDL/SDL.h> 1.6 + 1.7 +static void display(); 1.8 +static bool proc_event(SDL_Event *ev); 1.9 +static void set_pal_entry(int idx, int r, int g, int b); 1.10 + 1.11 +static SDL_Surface *fbsurf; 1.12 + 1.13 +int main(int argc, char **argv) 1.14 +{ 1.15 + SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER); 1.16 + 1.17 + if(!(fbsurf = SDL_SetVideoMode(320, 240, 8, SDL_SWSURFACE))) { 1.18 + fprintf(stderr, "failed to set video mode\n"); 1.19 + return 1; 1.20 + } 1.21 + set_pal_entry(1, 255, 0, 0); 1.22 + 1.23 + for(;;) { 1.24 + SDL_Event ev; 1.25 + while(SDL_PollEvent(&ev)) { 1.26 + if(!proc_event(&ev)) { 1.27 + goto done; 1.28 + } 1.29 + } 1.30 + 1.31 + display(); 1.32 + } 1.33 + 1.34 +done: 1.35 + SDL_Quit(); 1.36 + return 0; 1.37 +} 1.38 + 1.39 +void display() 1.40 +{ 1.41 + if(SDL_MUSTLOCK(fbsurf)) { 1.42 + SDL_LockSurface(fbsurf); 1.43 + } 1.44 + 1.45 + unsigned char *pixels = (unsigned char*)fbsurf->pixels; 1.46 + for(int i=0; i<fbsurf->w * fbsurf->h; i++) { 1.47 + *pixels++ = 1; 1.48 + } 1.49 + 1.50 + if(SDL_MUSTLOCK(fbsurf)) { 1.51 + SDL_UnlockSurface(fbsurf); 1.52 + } 1.53 + 1.54 + SDL_Flip(fbsurf); 1.55 +} 1.56 + 1.57 +static bool proc_event(SDL_Event *ev) 1.58 +{ 1.59 + switch(ev->type) { 1.60 + case SDL_KEYDOWN: 1.61 + if(ev->key.keysym.sym == SDLK_ESCAPE) { 1.62 + return false; 1.63 + } 1.64 + break; 1.65 + 1.66 + default: 1.67 + break; 1.68 + } 1.69 + return true; 1.70 +} 1.71 + 1.72 +static void set_pal_entry(int idx, int r, int g, int b) 1.73 +{ 1.74 + SDL_Color col; 1.75 + col.r = r; 1.76 + col.g = g; 1.77 + col.b = b; 1.78 + 1.79 + SDL_SetPalette(fbsurf, SDL_LOGPAL | SDL_PHYSPAL, &col, idx, 1); 1.80 + 1.81 + /*palette[idx].r = r; 1.82 + palette[idx].g = g; 1.83 + palette[idx].b = b;*/ 1.84 +}