Last active
July 24, 2017 19:13
-
-
Save henriquerichter/7b317c3d00fb07a810ac9eb9e4581014 to your computer and use it in GitHub Desktop.
Simple SDL Window
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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