First test rendering / skelton Game Loop / utility Textureloader
This commit is contained in:
@@ -1,17 +1,64 @@
|
||||
#include <iostream>
|
||||
#include <SDL2/SDL_image.h>
|
||||
|
||||
#include "DarkRP2D.h"
|
||||
#include "utility/utility.h"
|
||||
|
||||
void DarkRP2D::create() {
|
||||
|
||||
|
||||
void DarkRP2D::create(SDL_Renderer *gRenderer) {
|
||||
this->gRenderer = gRenderer;
|
||||
|
||||
//Load PNG texture
|
||||
gTexture = utility::loadTexture( "assets/police_officer.png", gRenderer);
|
||||
|
||||
}
|
||||
|
||||
void DarkRP2D::loop(float deltaTime) {
|
||||
unsigned int ups = 0;
|
||||
unsigned int acc = 0;
|
||||
void DarkRP2D::loop(unsigned int deltaTime) {
|
||||
accumulator += deltaTime;
|
||||
acc += deltaTime;
|
||||
|
||||
//Process Input
|
||||
|
||||
skippedFrames = 0;
|
||||
while (accumulator >= MS_PER_UPDATE && skippedFrames <= MAX_FRAMESKIP) {
|
||||
accumulator -= MS_PER_UPDATE;
|
||||
update(0.0f);
|
||||
ups++;
|
||||
skippedFrames++;
|
||||
}
|
||||
|
||||
if(acc >= 1000) {
|
||||
std::cout << "Updates per second: " << ups << std::endl;
|
||||
acc -= 1000;
|
||||
ups = 0;
|
||||
}
|
||||
render(0.0f);
|
||||
}
|
||||
|
||||
void DarkRP2D::update(float deltaInSec) {
|
||||
|
||||
}
|
||||
|
||||
void DarkRP2D::resize() {
|
||||
void DarkRP2D::render(float deltaInSec) {
|
||||
//Clear screen
|
||||
SDL_RenderClear( gRenderer );
|
||||
|
||||
//Render texture to screen
|
||||
SDL_RenderCopy( gRenderer, gTexture, NULL, NULL );
|
||||
|
||||
//Update screen
|
||||
SDL_RenderPresent( gRenderer );
|
||||
}
|
||||
|
||||
void DarkRP2D::resize(int width, int height) {
|
||||
|
||||
}
|
||||
|
||||
void DarkRP2D::dispose() {
|
||||
|
||||
//Free loaded image
|
||||
SDL_DestroyTexture( gTexture );
|
||||
gTexture = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user