]> git.r.bdr.sh - rbdr/super-polarity/blob - src/main.c
Add image loading.
[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 #include "SDL2_image/SDL_image.h"
14
15 // TODO: Move these guys to a config header file
16 #define SCREEN_WIDTH 640
17 #define SCREEN_HEIGHT 480
18 #define FPS 30
19
20 SDL_Window *window;
21 SDL_Renderer *renderer;
22 SDL_Surface *benHead;
23
24 void init () {
25 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
26 printf("Could not initialize SDL");
27 exit(1);
28 }
29
30 // Load the window and renderer
31 window = SDL_CreateWindow("Super Polarity", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 0, 0, SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN_DESKTOP);
32
33 renderer = SDL_CreateRenderer(window, -1, 0);
34
35 // Set linear quality for scaling, and the "logical" window size.
36 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
37 SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
38
39 // Load the surface.
40 // benHead = IMG_Load("data/img/static/ben.png");
41 }
42
43 void render (SDL_Renderer *renderer) {
44 SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
45 SDL_RenderClear(renderer);
46 SDL_RenderPresent(renderer);
47 }
48
49 int mainC(int argc, const char * argv[])
50 {
51
52 // SDL Initialization. TODO: Should have an initializer.
53 Uint32 startFrame;
54 Uint32 endFrame;
55 Uint32 delay;
56 int done;
57
58
59 done = 0;
60
61 // Event Loop.
62 while (!done) {
63 startFrame = SDL_GetTicks();
64 SDL_Event event;
65 while (SDL_PollEvent(&event)) {
66 if (event.type == SDL_QUIT) {
67 done = 1;
68 }
69 }
70
71 render(renderer);
72
73 endFrame = SDL_GetTicks();
74
75 /* see if we have time to sleep */
76 delay = 1000 / FPS - (endFrame - startFrame);
77 if (delay > 1000 / FPS) {
78 delay = 1000 / FPS;
79 }
80 SDL_Delay(delay);
81 }
82
83 SDL_Quit();
84
85 return 0;
86 }
87