5 // Created by Ruben Beltran del Rio on 8/13/13.
6 // Copyright (c) 2013 Abuguet. All rights reserved.
14 #include "SDL2_image/SDL_image.h"
16 // TODO: Move these guys to a config header file
17 #define SCREEN_WIDTH 640
18 #define SCREEN_HEIGHT 480
22 SDL_Renderer
*renderer
;
28 if (SDL_Init(SDL_INIT_VIDEO
) < 0) {
29 printf("Could not initialize SDL");
33 // Load the window and renderer
34 window
= SDL_CreateWindow("Super Polarity", SDL_WINDOWPOS_CENTERED
, SDL_WINDOWPOS_CENTERED
, 0, 0, SDL_WINDOW_OPENGL
| SDL_WINDOW_FULLSCREEN_DESKTOP
);
36 renderer
= SDL_CreateRenderer(window
, -1, 0);
38 // Set linear quality for scaling, and the "logical" window size.
39 SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY
, "linear");
40 SDL_RenderSetLogicalSize(renderer
, SCREEN_WIDTH
, SCREEN_HEIGHT
);
44 SDL_DestroyTexture(benHead
);
45 SDL_DestroyRenderer(renderer
);
46 SDL_DestroyWindow(window
);
52 SDL_Surface
*benSurface
;
53 benSurface
= IMG_Load("data/img/static/ben.png");
54 benHead
= SDL_CreateTextureFromSurface(renderer
, benSurface
);
59 SDL_FreeSurface(benSurface
);
62 void render (SDL_Renderer
*renderer
) {
63 SDL_SetRenderDrawColor(renderer
, 255, 255, 255, 255);
64 SDL_RenderClear(renderer
);
65 SDL_RenderCopyEx(renderer
, benHead
, NULL
, &benRect
, angle
, NULL
, SDL_FLIP_NONE
);
66 SDL_RenderPresent(renderer
);
70 angle
= (Uint32
)(angle
+ dt
/ 5) % 360;
73 int main(int argc
, const char * argv
[])
76 // SDL Initialization. TODO: Should have an initializer.
77 Uint32 startFrame
= 0;
92 startFrame
= SDL_GetTicks();
93 dt
= startFrame
- lastTime
;
94 lastTime
= startFrame
;
97 while (SDL_PollEvent(&event
)) {
98 if (event
.type
== SDL_QUIT
) {
106 endFrame
= SDL_GetTicks();
108 /* see if we have time to sleep */
109 delay
= 1000 / FPS
- (endFrame
- startFrame
);
110 if (delay
> 1000 / FPS
) {