Skip to content

Instantly share code, notes, and snippets.

@abma
Created August 3, 2014 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abma/a722346b7ad601d17ee8 to your computer and use it in GitHub Desktop.
Save abma/a722346b7ad601d17ee8 to your computer and use it in GitHub Desktop.
sdl2 example app
#include <SDL2/SDL.h>
#include <stdio.h>
#undef main
static bool process_events( void )
{
/* Our SDL event placeholder. */
SDL_Event event;
/* Grab all the events off the queue. */
while( SDL_PollEvent( &event ) ) {
switch( event.type ) {
case SDL_KEYDOWN:
break;
case SDL_QUIT:
/* Handle quit requests (like Ctrl-c). */
return false;
break;
}
}
return true;
}
int main(int argc, char* argv[]) {
SDL_Window *window; // Declare a pointer
SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2
// Create an application window with the following settings:
window = SDL_CreateWindow(
"An SDL2 window", // window title
SDL_WINDOWPOS_UNDEFINED, // initial x position
SDL_WINDOWPOS_UNDEFINED, // initial y position
640, // width, in pixels
480, // height, in pixels
SDL_WINDOW_OPENGL // flags - see below
);
// Check that the window was successfully made
if (window == NULL) {
// In the event that the window could not be made...
printf("Could not create window: %s\n", SDL_GetError());
return 1;
}
// The window is open: enter program loop (see SDL_PollEvent)
bool running = true;
while( running ) {
/* Process incoming events. */
running = process_events( );
}
// Close and destroy the window
SDL_DestroyWindow(window);
// Clean up
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment