]> git.r.bdr.sh - rbdr/super-polarity/blob - src/main.c
97d1e38facb0e054e792dff023ba7ce5f343f534
[rbdr/super-polarity] / src / main.c
1 //
2 // main.c
3 // Super Polarity
4 //
5 // Created by Ruben Beltran del Rio on 8/13/13.
6 // Copyright (c) 2013 Abuguet. All rights reserved.
7 //
8
9 #include <stdio.h>
10 #include <time.h>
11
12 #include "SDL2/SDL.h"
13
14 // TODO: Move these guys to a config header file
15 #define SCREEN_WIDTH 640
16 #define SCREEN_HEIGHT 480
17 #define FPS 30
18
19 int main(int argc, const char * argv[])
20 {
21
22 // SDL Initialization. TODO: Should have an initializer.
23 SDL_Window *window;
24 SDL_Renderer *renderer;
25 Uint32 startFrame;
26 Uint32 endFrame;
27 Uint32 delay;
28 int done;
29
30 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
31 printf("Could not initialize SDL");
32 exit(1);
33 }
34
35 window = SDL_CreateWindow("Super Polarity", 50, 50, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_BORDERLESS);
36
37 renderer = SDL_CreateRenderer(window, -1, 0);
38
39 done = 0;
40
41 // Event Loop.
42 while (!done) {
43 startFrame = SDL_GetTicks();
44 SDL_Event event;
45 while (SDL_PollEvent(&event)) {
46 if (event.type == SDL_QUIT) {
47 done = 1;
48 }
49 }
50
51 endFrame = SDL_GetTicks();
52
53 /* see if we have time to sleep */
54 delay = 1000 / FPS - (endFrame - startFrame);
55 if (delay > 1000 / FPS) {
56 delay = 1000 / FPS;
57 }
58 SDL_Delay(delay);
59 }
60
61 SDL_Quit();
62
63 return 0;
64 }
65