Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Created November 7, 2017 10:27
Show Gist options
  • Save rdeioris/ec07529f55b0336a1ad6203b103c503d to your computer and use it in GitHub Desktop.
Save rdeioris/ec07529f55b0336a1ad6203b103c503d to your computer and use it in GitHub Desktop.
First SDL program
#define SDL_MAIN_HANDLED
#ifdef _WIN32
#include <SDL.h>
#else
#include <SDL2/SDL.h>
#endif
#include <stdio.h>
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
0 // flags - see below
);
// Check that the window was successfully created
if (window == NULL) {
// In the case that the window could not be made...
fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
return 1;
}
// The window is open: could enter program loop here (see SDL_PollEvent())
SDL_Delay(3000); // Pause execution for 3000 milliseconds, for example
// 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