Skip to content

Instantly share code, notes, and snippets.

@henriquerichter
Last active July 24, 2017 19:13
Show Gist options
  • Select an option

  • Save henriquerichter/7b317c3d00fb07a810ac9eb9e4581014 to your computer and use it in GitHub Desktop.

Select an option

Save henriquerichter/7b317c3d00fb07a810ac9eb9e4581014 to your computer and use it in GitHub Desktop.
Simple SDL Window
#include <iostream>
#include <SDL.h>
int w = 800;
int h = 600;
SDL_Window *window = NULL;
SDL_Surface *screenSurface = NULL;
void mainLoop();
void initSDL();
void cleanUp();
int main(int argc, char *argv[])
{
initSDL();
mainLoop();
cleanUp();
return 0;
}
void initSDL()
{
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
printf("Could not create SDL Window");
exit(-1);
}
else
{
window = SDL_CreateWindow("Main Window", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
if (window == NULL)
{
printf("Could not create SDL Window");
exit(-1);
}
}
}
void mainLoop()
{
bool running = true;
while (running)
{
SDL_Event event;
while (SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:
running = false;
break;
default:
break;
}
}
}
}
void cleanUp()
{
SDL_DestroyWindow(window);
SDL_Quit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment