#include <stdio.h>
#include <time.h>
+#include <math.h>
#include "SDL2/SDL.h"
#include "SDL2_image/SDL_image.h"
SDL_Window *window;
SDL_Renderer *renderer;
-SDL_Surface *benHead;
+SDL_Texture *benHead;
+SDL_Rect benRect;
+double angle = 0;
void init () {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
// Set linear quality for scaling, and the "logical" window size.
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");
SDL_RenderSetLogicalSize(renderer, SCREEN_WIDTH, SCREEN_HEIGHT);
-
+}
+
+void close () {
+ SDL_DestroyTexture(benHead);
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+}
+
+void loadAssets() {
// Load the surface.
- // benHead = IMG_Load("data/img/static/ben.png");
+ SDL_Surface *benSurface;
+ benSurface = IMG_Load("data/img/static/ben.png");
+ benHead = SDL_CreateTextureFromSurface(renderer, benSurface);
+ benRect.x = 230;
+ benRect.y = 150;
+ benRect.w = 180;
+ benRect.h = 180;
+ SDL_FreeSurface(benSurface);
}
void render (SDL_Renderer *renderer) {
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_RenderClear(renderer);
+ SDL_RenderCopyEx(renderer, benHead, NULL, &benRect, angle, NULL, SDL_FLIP_NONE);
SDL_RenderPresent(renderer);
}
-int mainC(int argc, const char * argv[])
+void update (dt) {
+ angle = (Uint32)(angle + dt / 5) % 360;
+}
+
+int main(int argc, const char * argv[])
{
// SDL Initialization. TODO: Should have an initializer.
- Uint32 startFrame;
- Uint32 endFrame;
+ Uint32 startFrame = 0;
+ Uint32 endFrame = 0;
+ Uint32 lastTime = 0;
+ Uint32 dt;
Uint32 delay;
int done;
+
+ init();
+ loadAssets();
done = 0;
// Event Loop.
while (!done) {
startFrame = SDL_GetTicks();
+ dt = startFrame - lastTime;
+ lastTime = startFrame;
+
SDL_Event event;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_QUIT) {
}
}
+ update(dt);
render(renderer);
endFrame = SDL_GetTicks();
SDL_Delay(delay);
}
- SDL_Quit();
+ close();
return 0;
}