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