X-Git-Url: https://git.r.bdr.sh/rbdr/super-polarity/blobdiff_plain/626ab5162bc9b461fde36ab6b6bc58ed066a7945..7407ac7ff7e7b43ce35771f386e7b259a9c1ba58:/src/main.c?ds=sidebyside diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..97d1e38 --- /dev/null +++ b/src/main.c @@ -0,0 +1,65 @@ +// +// main.c +// Super Polarity +// +// Created by Ruben Beltran del Rio on 8/13/13. +// Copyright (c) 2013 Abuguet. All rights reserved. +// + +#include +#include + +#include "SDL2/SDL.h" + +// TODO: Move these guys to a config header file +#define SCREEN_WIDTH 640 +#define SCREEN_HEIGHT 480 +#define FPS 30 + +int main(int argc, const char * argv[]) +{ + + // SDL Initialization. TODO: Should have an initializer. + SDL_Window *window; + SDL_Renderer *renderer; + Uint32 startFrame; + Uint32 endFrame; + Uint32 delay; + int done; + + if (SDL_Init(SDL_INIT_VIDEO) < 0) { + printf("Could not initialize SDL"); + exit(1); + } + + window = SDL_CreateWindow("Super Polarity", 50, 50, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS); + + renderer = SDL_CreateRenderer(window, -1, 0); + + done = 0; + + // Event Loop. + while (!done) { + startFrame = SDL_GetTicks(); + SDL_Event event; + while (SDL_PollEvent(&event)) { + if (event.type == SDL_QUIT) { + done = 1; + } + } + + endFrame = SDL_GetTicks(); + + /* see if we have time to sleep */ + delay = 1000 / FPS - (endFrame - startFrame); + if (delay > 1000 / FPS) { + delay = 1000 / FPS; + } + SDL_Delay(delay); + } + + SDL_Quit(); + + return 0; +} +