/ Published in: C
WIP
Expand |
Embed | Plain Text
#if 0 #include "SDL/include/SDL.h" #include "SDL/SDL_GfxPrimitives/SDL_gfxPrimitives.h" #pragma comment (lib, "SDL/lib/SDL.lib") #pragma comment (lib, "SDL/SDL_GfxPrimitives/SDL_GfxPrimitives_Static.lib") #endif enum color {BLACK, RED, GREEN, BLUE, CYAN, MAGENTA, YELLOW, WHITE, COLOR_MAX}; static SDL_Surface* Screen; static Uint32 Colors [COLOR_MAX] = {0x000000ff, 0xff0000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff, 0xff00ffff, 0xffff00ff, 0xffffffff}; void clear_screen(); void draw_rectangle( int X1, int Y1, int X2, int Y2, enum color C ); int get_screen_height(); void update_screen(); int poll_key(); int get_key(); int is_key_down( int key ); int init_graph(); /* ---------------------------- CLEAR SCREEN ---------------------------- */ void clear_screen() { boxColor (Screen, 0, 0, Screen->w - 1, Screen->h - 1, Colors[BLACK]); } /* ---------------------------- DRAW RECTANGLE --------------------------- */ void draw_rectangle ( int X1, int Y1, /* Upper left corner of the rectangle. */ int X2, int Y2, /* Lower right corner of the rectangle. */ enum color C ) /* Rectangle color. */ { boxColor ( Screen, X1, Y1, X2, Y2-1, Colors[C] ); } /* ---------------------------- GET_SCREEN_HEIGHT ---------------------- */ int get_screen_height() { return Screen->h; } /* ---------------------------- UPDATE_SCREEN ---------------------------- */ void update_screen() { SDL_Flip(Screen); } /* ---------------------------- POLL_KEY-------------------------------- */ /* Keyboard input. */ int poll_key() { SDL_Event event; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: return event.key.keysym.sym; case SDL_QUIT: exit(3); } } return -1; } /* ---------------------------- GET_KEY --------------------------------- */ /* Keyboard input. */ int get_key() { SDL_Event event; while (1) { SDL_WaitEvent(&event); if (event.type == SDL_KEYDOWN) break; if (event.type == SDL_QUIT) exit(3); }; return event.key.keysym.sym; } /* ---------------------------- IS_KEY_DOWN ------------------------------ */ /* Keyboard input. */ int is_key_down (int key) { Uint8* Keytable; int Numkeys; SDL_PumpEvents(); Keytable = SDL_GetKeyState(&Numkeys); return Keytable[Key]; } /* ---------------------------- GRAPHICAL INITIALIZATION ----------------- */ int init_graph() { const SDL_VideoInfo *info; Uint8 video_bpp; Uint32 videoflags; /* Initialize SDL. */ if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError()); return 1; } atexit(SDL_Quit); /* Alpha blending doesn't work well at 8-bit color. */ info = SDL_GetVideoInfo(); if ( info->vfmt->BitsPerPixel > 8 ) video_bpp = info->vfmt->BitsPerPixel; else video_bpp = 16; videoflags = SDL_SWSURFACE | SDL_DOUBLEBUF; /* Set 640x480 video mode. */ if ( (Screen=SDL_SetVideoMode(640,480,video_bpp,videoflags)) == NULL ) { fprintf( stderr, "Couldn't set %ix%i video mode: %s\n", 640, 480, SDL_GetError() ); return 2; } return 0; }
You need to login to post a comment.
