Hari's Corner
Humour, comics, tech, law, software, reviews, essays, articles and HOWTOs intermingled with random philosophy now and thenA (very simple) SDL Program
Filed under:
Tutorials and HOWTOs by
Hari
Posted on Sat, Jul 29, 2006 at 18:10 IST (last updated: Wed, Jul 16, 2008 @ 20:43 IST)
#include <SDL/SDL.h> #include <SDL/SDL_keyboard.h> #include <SDL/SDL_keysym.h> #include <SDL/SDL_image.h> #include <iostream> SDL_Surface* screen; int main () { if ( SDL_Init (SDL_INIT_VIDEO) != 0) { std::cerr << "Cannot initialize SDL"; return -1; } atexit (SDL_Quit); screen = SDL_SetVideoMode (640, 480, 16, SDL_HWSURFACE); if (screen == NULL) { std::cerr << "Unable to set video mode"; return -1; } SDL_Surface* img = IMG_Load ("sdl_test.png"); SDL_Surface* img_format = SDL_DisplayFormat (img); SDL_FreeSurface (img); SDL_BlitSurface (img_format, NULL, screen, NULL); SDL_Flip (screen); SDL_FreeSurface(img_format); SDL_Event event; while (1) { while (SDL_PollEvent (&event)) { switch (event.type) { case SDL_KEYUP: if (event.key.keysym.sym == 'q') exit (0); break; case SDL_QUIT: exit (0); } } } }
Comments closed
The blog owner has closed further commenting on this entry.
No comments yet
There are no comments for this article yet.