diff options
| author | Ben Beltran <ben@freshout.us> | 2013-08-13 08:33:55 -0500 |
|---|---|---|
| committer | Ben Beltran <ben@freshout.us> | 2013-08-13 08:33:55 -0500 |
| commit | 7407ac7ff7e7b43ce35771f386e7b259a9c1ba58 (patch) | |
| tree | 83caf3d0544aeb0ca8f638a3849f8649d1ef083a /src/main.c | |
| parent | 626ab5162bc9b461fde36ab6b6bc58ed066a7945 (diff) | |
First commit. Hello SDL.
Diffstat (limited to 'src/main.c')
| -rw-r--r-- | src/main.c | 65 |
1 files changed, 65 insertions, 0 deletions
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 <stdio.h> +#include <time.h> + +#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; +} + |