Formatted classes
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
#include "Texture.h"
|
||||
#include "Shader.h"
|
||||
|
||||
class Assets {
|
||||
class Assets
|
||||
{
|
||||
private:
|
||||
std::map<std::string, Texture2D> textures;
|
||||
std::map<std::string, Shader> shaders;
|
||||
@@ -25,8 +26,6 @@ class Assets {
|
||||
Shader getShader(std::string name);
|
||||
Texture2D loadTexture(const GLchar *file, GLboolean alpha, std::string name);
|
||||
Texture2D getTexture(std::string name);
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,20 +6,25 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
BitmapFont::BitmapFont(std::string fontLocation) {
|
||||
BitmapFont::BitmapFont(std::string fontLocation)
|
||||
{
|
||||
FT_Library ft;
|
||||
if(FT_Init_FreeType(&ft)) {
|
||||
if (FT_Init_FreeType(&ft))
|
||||
{
|
||||
std::cout << "ERROR::FreeType: Could not init FreeType Library" << std::endl;
|
||||
}
|
||||
FT_Face face;
|
||||
if(FT_New_Face(ft, fontLocation.c_str(), 0, &face)){
|
||||
if (FT_New_Face(ft, fontLocation.c_str(), 0, &face))
|
||||
{
|
||||
std::cout << "ERROR::FreeType: Failed to load font" << std::endl;
|
||||
}
|
||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Disable byte-alignment restriction
|
||||
for(GLubyte c = 0; c < 128; c++) {
|
||||
for (GLubyte c = 0; c < 128; c++)
|
||||
{
|
||||
//Map bitmaps to chars
|
||||
if(FT_Load_Char(face, c, FT_LOAD_RENDER)) {
|
||||
if (FT_Load_Char(face, c, FT_LOAD_RENDER))
|
||||
{
|
||||
std::cout << "ERROR::FreeType: Could not load Glyph: " << c << std::endl;
|
||||
continue;
|
||||
}
|
||||
@@ -35,8 +40,7 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
||||
0,
|
||||
GL_RED,
|
||||
GL_UNSIGNED_BYTE,
|
||||
face->glyph->bitmap.buffer
|
||||
);
|
||||
face->glyph->bitmap.buffer);
|
||||
// Set texture options
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
@@ -46,8 +50,7 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
||||
texture,
|
||||
glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
|
||||
glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
|
||||
face->glyph->advance.x
|
||||
};
|
||||
face->glyph->advance.x};
|
||||
characters.insert(std::pair<GLchar, Character>(c, character));
|
||||
}
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //Reset byte-alignment restriction
|
||||
@@ -70,7 +73,8 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
void BitmapFont::drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color) {
|
||||
void BitmapFont::drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color)
|
||||
{
|
||||
s.Use();
|
||||
s.SetVector3f("textColor", color, true);
|
||||
s.SetMatrix4("projection", projection, true);
|
||||
@@ -97,8 +101,7 @@ void BitmapFont::drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLf
|
||||
|
||||
{xpos, ypos + h, 0.0, 0.0},
|
||||
{xpos + w, ypos, 1.0, 1.0},
|
||||
{ xpos + w, ypos + h, 1.0, 0.0 }
|
||||
};
|
||||
{xpos + w, ypos + h, 1.0, 0.0}};
|
||||
// Render glyph texture over quad
|
||||
glBindTexture(GL_TEXTURE_2D, ch.texID);
|
||||
// Update content of VBO memory
|
||||
|
||||
@@ -8,14 +8,16 @@
|
||||
|
||||
#include "Shader.h"
|
||||
|
||||
struct Character {
|
||||
struct Character
|
||||
{
|
||||
GLuint texID;
|
||||
glm::ivec2 size;
|
||||
glm::ivec2 bearing;
|
||||
GLuint advance;
|
||||
};
|
||||
|
||||
class BitmapFont {
|
||||
class BitmapFont
|
||||
{
|
||||
public:
|
||||
BitmapFont(std::string fontLocation);
|
||||
void drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color);
|
||||
|
||||
@@ -2,37 +2,44 @@
|
||||
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
|
||||
void OrtographicCamera::setPosition(glm::vec2 position) {
|
||||
void OrtographicCamera::setPosition(glm::vec2 position)
|
||||
{
|
||||
this->cameraPos = position;
|
||||
}
|
||||
|
||||
glm::vec2 OrtographicCamera::getPosition() {
|
||||
glm::vec2 OrtographicCamera::getPosition()
|
||||
{
|
||||
return this->cameraPos;
|
||||
}
|
||||
|
||||
void OrtographicCamera::setZoomLevel(float newZoom) {
|
||||
void OrtographicCamera::setZoomLevel(float newZoom)
|
||||
{
|
||||
this->zoom = newZoom;
|
||||
}
|
||||
|
||||
void OrtographicCamera::zoomIn(float targetZoom) {
|
||||
void OrtographicCamera::zoomIn(float targetZoom)
|
||||
{
|
||||
zoom -= targetZoom;
|
||||
}
|
||||
|
||||
void OrtographicCamera::translate(glm::vec2 target) {
|
||||
void OrtographicCamera::translate(glm::vec2 target)
|
||||
{
|
||||
cameraPos = cameraPos - target;
|
||||
}
|
||||
|
||||
void OrtographicCamera::smoothTranslate(glm::vec2 target) {
|
||||
|
||||
void OrtographicCamera::smoothTranslate(glm::vec2 target)
|
||||
{
|
||||
}
|
||||
|
||||
glm::mat4 OrtographicCamera::getViewMatrix() {
|
||||
glm::mat4 OrtographicCamera::getViewMatrix()
|
||||
{
|
||||
glm::mat4 view(1);
|
||||
view = glm::translate(view, glm::vec3(-cameraPos, 0.f));
|
||||
return view;
|
||||
}
|
||||
|
||||
glm::mat4 OrtographicCamera::getProjectionMatrix() {
|
||||
glm::mat4 OrtographicCamera::getProjectionMatrix()
|
||||
{
|
||||
//Dies gibt die Größe des kamera auschnittes an die in die welt zeigt (Frustum)
|
||||
int width = 800;
|
||||
int height = 600;
|
||||
@@ -42,12 +49,13 @@ glm::mat4 OrtographicCamera::getProjectionMatrix() {
|
||||
return projection;
|
||||
}
|
||||
|
||||
glm::mat4 OrtographicCamera::getCombinedMatrix() {
|
||||
glm::mat4 OrtographicCamera::getCombinedMatrix()
|
||||
{
|
||||
glm::mat4 combined;
|
||||
combined = getProjectionMatrix() * getViewMatrix();
|
||||
return combined;
|
||||
}
|
||||
|
||||
void OrtographicCamera::update() {
|
||||
|
||||
void OrtographicCamera::update()
|
||||
{
|
||||
}
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
|
||||
class OrtographicCamera {
|
||||
class OrtographicCamera
|
||||
{
|
||||
private:
|
||||
glm::vec2 cameraPos;
|
||||
float zoom;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
#include "screens/GameScreen.h"
|
||||
#include "Utility.h"
|
||||
|
||||
DarkRP2D::~DarkRP2D() {
|
||||
DarkRP2D::~DarkRP2D()
|
||||
{
|
||||
std::cout << "Game got destroyed!" << std::endl;
|
||||
#ifndef NDEBUG
|
||||
ImGui_ImplSdlGL3_Shutdown();
|
||||
@@ -21,7 +22,8 @@ DarkRP2D::~DarkRP2D() {
|
||||
delete renderer;
|
||||
}
|
||||
|
||||
void DarkRP2D::create () {
|
||||
void DarkRP2D::create()
|
||||
{
|
||||
std::cout << "Game got created!" << std::endl;
|
||||
assets = new Assets();
|
||||
assets->loadTexture("police_officer.png", true, "police_officer");
|
||||
@@ -43,18 +45,21 @@ void DarkRP2D::create () {
|
||||
#endif
|
||||
}
|
||||
|
||||
void DarkRP2D::loop(unsigned int delta) {
|
||||
void DarkRP2D::loop(unsigned int delta)
|
||||
{
|
||||
static unsigned int accumulator = 0, ups = 0, fps = 0, acc = 0;
|
||||
accumulator += delta;
|
||||
acc += delta;
|
||||
|
||||
while(accumulator >= 17) {
|
||||
while (accumulator >= 17)
|
||||
{
|
||||
accumulator -= 17;
|
||||
update(delta);
|
||||
ups++;
|
||||
}
|
||||
|
||||
if(acc >= 1000) {
|
||||
if (acc >= 1000)
|
||||
{
|
||||
std::cout << "Updates per second: " << ups << " Frames per Second: " << fps << std::endl;
|
||||
acc -= 1000;
|
||||
ups = 0;
|
||||
@@ -64,11 +69,13 @@ void DarkRP2D::loop(unsigned int delta) {
|
||||
fps++;
|
||||
}
|
||||
|
||||
void DarkRP2D::update(unsigned int delta) {
|
||||
void DarkRP2D::update(unsigned int delta)
|
||||
{
|
||||
gameScreen->update();
|
||||
}
|
||||
|
||||
void DarkRP2D::render(unsigned int delta) {
|
||||
void DarkRP2D::render(unsigned int delta)
|
||||
{
|
||||
renderer->clear();
|
||||
#ifndef NDEBUG
|
||||
ImGui_ImplSdlGL3_NewFrame(gWindow);
|
||||
@@ -106,5 +113,6 @@ void DarkRP2D::render(unsigned int delta) {
|
||||
SDL_GL_SwapWindow(gWindow);
|
||||
}
|
||||
|
||||
void DarkRP2D::resize(int width, int height){
|
||||
void DarkRP2D::resize(int width, int height)
|
||||
{
|
||||
}
|
||||
@@ -5,14 +5,14 @@ class DarkRP2D;
|
||||
#include <SDL.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "Assets.h"
|
||||
#include "Renderer.h"
|
||||
#include "input/InputHandler.h"
|
||||
#include "BitmapFont.h"
|
||||
#include "screens/Screen.h"
|
||||
|
||||
class DarkRP2D {
|
||||
class DarkRP2D
|
||||
{
|
||||
private:
|
||||
SDL_Window *gWindow;
|
||||
Assets *assets;
|
||||
@@ -21,7 +21,6 @@ class DarkRP2D {
|
||||
Screen *gameScreen;
|
||||
|
||||
public:
|
||||
|
||||
DarkRP2D(SDL_Window *gWindow) : gWindow(gWindow) {}
|
||||
~DarkRP2D();
|
||||
void create();
|
||||
@@ -29,7 +28,6 @@ class DarkRP2D {
|
||||
void update(unsigned int delta);
|
||||
void render(unsigned int delta);
|
||||
void resize(int width, int height);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <SDL_image.h>
|
||||
#include <GL/glew.h>
|
||||
|
||||
|
||||
#include "Desktoplauncher.h"
|
||||
#include "DarkRP2D.h"
|
||||
#include "Utility.h"
|
||||
@@ -18,9 +17,11 @@ static bool gameQuit = false;
|
||||
void dispose();
|
||||
bool initSDL();
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
//Init SDL_Window, SDL_Surface, SDL_Renderer
|
||||
if(!initSDL()) {
|
||||
if (!initSDL())
|
||||
{
|
||||
dispose();
|
||||
return 1;
|
||||
}
|
||||
@@ -29,7 +30,8 @@ int main(int argc, char *argv[]) {
|
||||
DarkRP2D resA(gWindow);
|
||||
resA.create();
|
||||
unsigned int lastTime = SDL_GetTicks(), currentTime, elapsedTime;
|
||||
while( !gameQuit ) {
|
||||
while (!gameQuit)
|
||||
{
|
||||
currentTime = SDL_GetTicks();
|
||||
elapsedTime = currentTime - lastTime;
|
||||
lastTime = currentTime;
|
||||
@@ -40,32 +42,38 @@ int main(int argc, char *argv[]) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Game::exit() {
|
||||
void Game::exit()
|
||||
{
|
||||
gameQuit = true;
|
||||
}
|
||||
|
||||
namespace Game {
|
||||
namespace Game
|
||||
{
|
||||
float DDPI, HDPI, VDPI;
|
||||
}
|
||||
|
||||
bool initSDL() {
|
||||
bool initSDL()
|
||||
{
|
||||
int result = SetProcessDPIAware(); // NEEDED or SDL_GetDisplayDPI returns wrong numbers
|
||||
cout << "Result: " << result << endl;
|
||||
//Init SDL
|
||||
if(SDL_Init(SDL_INIT_VIDEO) < 0 ) {
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
{
|
||||
cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
|
||||
return false;
|
||||
}
|
||||
//Init Window
|
||||
uint32_t WindowFlags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL;
|
||||
gWindow = SDL_CreateWindow("SDL TEST", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Game::SCREEN_WIDTH, Game::SCREEN_HEIGHT, WindowFlags);
|
||||
if( gWindow == NULL) {
|
||||
if (gWindow == NULL)
|
||||
{
|
||||
cout << "Window could not be created! SDL_Error: " << SDL_GetError() << endl;
|
||||
return false;
|
||||
}
|
||||
//Read in Display DPI
|
||||
int returnDisplayDPI = SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(gWindow), &Game::DDPI, &Game::HDPI, &Game::VDPI);
|
||||
if(returnDisplayDPI != 0) {
|
||||
if (returnDisplayDPI != 0)
|
||||
{
|
||||
cout << "DisplayDPI cannot be loaded! SDL_ERROR: " << SDL_GetError() << endl;
|
||||
}
|
||||
cout << "DPI: DDPI: " << Game::DDPI << " HDPI: " << Game::HDPI << " VPDI: " << Game::VDPI << endl;
|
||||
@@ -77,30 +85,36 @@ bool initSDL() {
|
||||
//Init OpenGL Renderer
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
glcontext = SDL_GL_CreateContext(gWindow);
|
||||
if(glcontext == NULL) {
|
||||
if (glcontext == NULL)
|
||||
{
|
||||
cout << "Could not create OpenGL Context: " << SDL_GetError() << endl;
|
||||
return false;
|
||||
}
|
||||
//Init GLEW
|
||||
glewExperimental = GL_TRUE;
|
||||
GLenum err = glewInit();
|
||||
if(GLEW_OK != err) {
|
||||
if (GLEW_OK != err)
|
||||
{
|
||||
cout << "Init of Glew failed: " << glewGetErrorString(err) << endl;
|
||||
return false;
|
||||
}
|
||||
//Init debug callback function
|
||||
#ifndef NDEBUG
|
||||
if (GLEW_ARB_debug_output) {
|
||||
if (GLEW_ARB_debug_output)
|
||||
{
|
||||
Utility::printInfo(Utility::GLEW, "Supporting ARB debug output!");
|
||||
}
|
||||
if (GLEW_AMD_debug_output) {
|
||||
if (GLEW_AMD_debug_output)
|
||||
{
|
||||
Utility::printInfo(Utility::GLEW, "Supporting AMD debug output!");
|
||||
}
|
||||
if (GLEW_KHR_debug) {
|
||||
if (GLEW_KHR_debug)
|
||||
{
|
||||
Utility::printInfo(Utility::GLEW, "Supporting KHR debug output!");
|
||||
}
|
||||
|
||||
if(glDebugMessageCallback) {
|
||||
if (glDebugMessageCallback)
|
||||
{
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
Utility::printInfo(Utility::OpenGL, "Register OpenGL debug callback");
|
||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||
@@ -112,14 +126,17 @@ bool initSDL() {
|
||||
0,
|
||||
&unusedIds,
|
||||
true);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
Utility::printWarning(Utility::OpenGL, "glDebugMessageCallback not available");
|
||||
}
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
|
||||
void dispose() {
|
||||
void dispose()
|
||||
{
|
||||
SDL_GL_DeleteContext(glcontext);
|
||||
SDL_DestroyWindow(gWindow);
|
||||
SDL_Quit();
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Game {
|
||||
namespace Game
|
||||
{
|
||||
|
||||
const int SCREEN_WIDTH = 800;
|
||||
const int SCREEN_HEIGHT = 600;
|
||||
@@ -15,8 +16,7 @@ extern float HDPI;
|
||||
//vertical DPI of the display used while starting
|
||||
extern float VDPI;
|
||||
|
||||
|
||||
void exit();
|
||||
|
||||
}
|
||||
} // namespace Game
|
||||
#endif
|
||||
19
src/Mesh.cpp
19
src/Mesh.cpp
@@ -3,8 +3,8 @@
|
||||
#include <GL/glew.h>
|
||||
#include <iostream>
|
||||
|
||||
|
||||
Mesh::Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices, Texture2D texture) {
|
||||
Mesh::Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices, Texture2D texture)
|
||||
{
|
||||
this->texture = texture;
|
||||
this->vertices = vertices;
|
||||
this->indices = indices;
|
||||
@@ -12,7 +12,8 @@ Mesh::Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices, Te
|
||||
setupMesh();
|
||||
}
|
||||
|
||||
void Mesh::setupMesh() {
|
||||
void Mesh::setupMesh()
|
||||
{
|
||||
//Create VAO & Bind
|
||||
glGenVertexArrays(1, &VAO);
|
||||
glBindVertexArray(VAO);
|
||||
@@ -36,21 +37,25 @@ void Mesh::setupMesh() {
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
Mesh::~Mesh()
|
||||
{
|
||||
std::cout << "Deleting Mesh" << std::endl;
|
||||
glDeleteBuffers(1, &VBO);
|
||||
glDeleteBuffers(1, &EBO);
|
||||
glDeleteBuffers(1, &VAO);
|
||||
}
|
||||
|
||||
unsigned int Mesh::getIndicesCount() const {
|
||||
unsigned int Mesh::getIndicesCount() const
|
||||
{
|
||||
return indices.size();
|
||||
}
|
||||
|
||||
void Mesh::bindVAO() const {
|
||||
void Mesh::bindVAO() const
|
||||
{
|
||||
glBindVertexArray(this->VAO);
|
||||
}
|
||||
|
||||
void Mesh::bindTexture() const {
|
||||
void Mesh::bindTexture() const
|
||||
{
|
||||
texture.Bind();
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@
|
||||
|
||||
//Aggregate class -> so following construction is available
|
||||
//Vertex2D{glm::vec2(-0.5f,-0.5f), glm::vec2(0.0f,1.0f)}
|
||||
struct Vertex2D {
|
||||
struct Vertex2D
|
||||
{
|
||||
glm::vec2 position;
|
||||
glm::vec2 texCoord;
|
||||
};
|
||||
|
||||
class Mesh {
|
||||
class Mesh
|
||||
{
|
||||
private:
|
||||
unsigned int VBO, VAO, EBO;
|
||||
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
#include "Renderer.h"
|
||||
#include <GL/glew.h>
|
||||
|
||||
Renderer::Renderer() {
|
||||
Renderer::Renderer()
|
||||
{
|
||||
glClearColor(1.f, 1.f, 1.f, 1.f);
|
||||
}
|
||||
|
||||
void Renderer::draw(const Mesh& mesh, Shader& shader) {
|
||||
void Renderer::draw(const Mesh &mesh, Shader &shader)
|
||||
{
|
||||
//Bind texture of mesh
|
||||
mesh.bindTexture();
|
||||
mesh.bindVAO();
|
||||
@@ -13,6 +15,7 @@ void Renderer::draw(const Mesh& mesh, Shader& shader) {
|
||||
glDrawElements(GL_TRIANGLES, mesh.getIndicesCount(), GL_UNSIGNED_INT, 0);
|
||||
}
|
||||
|
||||
void Renderer::clear() const {
|
||||
void Renderer::clear() const
|
||||
{
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
@@ -4,7 +4,8 @@
|
||||
#include "Mesh.h"
|
||||
#include "Shader.h"
|
||||
|
||||
class Renderer {
|
||||
class Renderer
|
||||
{
|
||||
public:
|
||||
Renderer();
|
||||
void draw(const Mesh &mesh, Shader &shader);
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
Shader &Shader::Use() {
|
||||
Shader &Shader::Use()
|
||||
{
|
||||
glUseProgram(this->ID);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Shader::Compile(const GLchar* vertexSource, const GLchar* fragmentSource, const GLchar* geometrySource) {
|
||||
void Shader::Compile(const GLchar *vertexSource, const GLchar *fragmentSource, const GLchar *geometrySource)
|
||||
{
|
||||
GLuint sVertex, sFragment, gShader;
|
||||
// Vertex Shader
|
||||
sVertex = glCreateShader(GL_VERTEX_SHADER);
|
||||
@@ -42,54 +44,63 @@ void Shader::Compile(const GLchar* vertexSource, const GLchar* fragmentSource, c
|
||||
glDeleteShader(gShader);
|
||||
}
|
||||
|
||||
void Shader::SetFloat(const GLchar *name, GLfloat value, GLboolean useShader) {
|
||||
void Shader::SetFloat(const GLchar *name, GLfloat value, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform1f(glGetUniformLocation(this->ID, name), value);
|
||||
}
|
||||
void Shader::SetInteger(const GLchar *name, GLint value, GLboolean useShader) {
|
||||
void Shader::SetInteger(const GLchar *name, GLint value, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform1i(glGetUniformLocation(this->ID, name), value);
|
||||
}
|
||||
void Shader::SetVector2f(const GLchar *name, GLfloat x, GLfloat y, GLboolean useShader) {
|
||||
void Shader::SetVector2f(const GLchar *name, GLfloat x, GLfloat y, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform2f(glGetUniformLocation(this->ID, name), x, y);
|
||||
}
|
||||
void Shader::SetVector2f(const GLchar *name, const glm::vec2 &value, GLboolean useShader) {
|
||||
void Shader::SetVector2f(const GLchar *name, const glm::vec2 &value, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y);
|
||||
}
|
||||
void Shader::SetVector3f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLboolean useShader) {
|
||||
void Shader::SetVector3f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform3f(glGetUniformLocation(this->ID, name), x, y, z);
|
||||
}
|
||||
void Shader::SetVector3f(const GLchar *name, const glm::vec3 &value, GLboolean useShader) {
|
||||
void Shader::SetVector3f(const GLchar *name, const glm::vec3 &value, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform3f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z);
|
||||
}
|
||||
void Shader::SetVector4f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLboolean useShader) {
|
||||
void Shader::SetVector4f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w);
|
||||
}
|
||||
void Shader::SetVector4f(const GLchar *name, const glm::vec4 &value, GLboolean useShader) {
|
||||
void Shader::SetVector4f(const GLchar *name, const glm::vec4 &value, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniform4f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z, value.w);
|
||||
}
|
||||
void Shader::SetMatrix4(const GLchar *name, const glm::mat4 &matrix, GLboolean useShader) {
|
||||
void Shader::SetMatrix4(const GLchar *name, const glm::mat4 &matrix, GLboolean useShader)
|
||||
{
|
||||
if (useShader)
|
||||
this->Use();
|
||||
glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, GL_FALSE, glm::value_ptr(matrix));
|
||||
}
|
||||
|
||||
|
||||
void Shader::checkCompileErrors(GLuint object, std::string type) {
|
||||
void Shader::checkCompileErrors(GLuint object, std::string type)
|
||||
{
|
||||
GLint success;
|
||||
GLchar infoLog[1024];
|
||||
if (type != "PROGRAM")
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
|
||||
|
||||
// General purpsoe shader object. Compiles from file, generates
|
||||
// compile/link-time error messages and hosts several utility
|
||||
// functions for easy management.
|
||||
@@ -32,6 +31,7 @@ public:
|
||||
void SetVector4f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLboolean useShader = false);
|
||||
void SetVector4f(const GLchar *name, const glm::vec4 &value, GLboolean useShader = false);
|
||||
void SetMatrix4(const GLchar *name, const glm::mat4 &matrix, GLboolean useShader = false);
|
||||
|
||||
private:
|
||||
// Checks if compilation or linking failed and if so, print the error logs
|
||||
void checkCompileErrors(GLuint object, std::string type);
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
#include "Texture.h"
|
||||
|
||||
|
||||
Texture2D::Texture2D()
|
||||
: Width(0), Height(0), Internal_Format(GL_RGB), Image_Format(GL_RGB), Wrap_S(GL_REPEAT), Wrap_T(GL_REPEAT), Filter_Min(GL_LINEAR_MIPMAP_NEAREST), Filter_Max(GL_NEAREST)
|
||||
: Width(0), Height(0), Internal_Format(GL_RGB), Image_Format(GL_RGB), Wrap_S(GL_REPEAT), Wrap_T(GL_REPEAT), Filter_Min(GL_LINEAR_MIPMAP_NEAREST), Filter_Max(GL_LINEAR)
|
||||
{
|
||||
glGenTextures(1, &this->ID);
|
||||
}
|
||||
|
||||
void Texture2D::Generate(GLuint width, GLuint height, unsigned char* data) {
|
||||
void Texture2D::Generate(GLuint width, GLuint height, unsigned char *data)
|
||||
{
|
||||
this->Width = width;
|
||||
this->Height = height;
|
||||
// Create Texture
|
||||
@@ -31,6 +31,7 @@ void Texture2D::Generate(GLuint width, GLuint height, unsigned char* data) {
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
}
|
||||
|
||||
void Texture2D::Bind() const {
|
||||
void Texture2D::Bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||
}
|
||||
|
||||
@@ -2,18 +2,22 @@
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
namespace Utility{
|
||||
namespace Debug {
|
||||
namespace Utility
|
||||
{
|
||||
namespace Debug
|
||||
{
|
||||
ImGuiLogger openGLLogger;
|
||||
}
|
||||
}
|
||||
} // namespace Utility
|
||||
|
||||
void Utility::Debug::ImGuiLogger::Clear() {
|
||||
void Utility::Debug::ImGuiLogger::Clear()
|
||||
{
|
||||
Buf.clear();
|
||||
LineOffsets.clear();
|
||||
}
|
||||
|
||||
void Utility::Debug::ImGuiLogger::AddLog(const char* fmt, ...) IM_FMTARGS(2) {
|
||||
void Utility::Debug::ImGuiLogger::AddLog(const char *fmt, ...) IM_FMTARGS(2)
|
||||
{
|
||||
int old_size = Buf.size();
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
@@ -25,27 +29,37 @@
|
||||
ScrollToBottom = true;
|
||||
}
|
||||
|
||||
void Utility::Debug::ImGuiLogger::Draw(const char* title, bool* p_open) {
|
||||
void Utility::Debug::ImGuiLogger::Draw(const char *title, bool *p_open)
|
||||
{
|
||||
ImGui::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
||||
ImGui::Begin(title, p_open);
|
||||
if (ImGui::Button("Clear")) Clear();
|
||||
if (ImGui::Button("Clear"))
|
||||
Clear();
|
||||
ImGui::SameLine();
|
||||
bool copy = ImGui::Button("Copy");
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Errors", &ShowError); ImGui::SameLine();
|
||||
ImGui::Checkbox("Deprecated Behavior", &ShowDeprecatedBehavior); ImGui::SameLine();
|
||||
ImGui::Checkbox("Undefined Behavior", &ShowUndefinedBehavior); ImGui::SameLine();
|
||||
ImGui::Checkbox("Errors", &ShowError);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Deprecated Behavior", &ShowDeprecatedBehavior);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Undefined Behavior", &ShowUndefinedBehavior);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Portability", &ShowPortability);
|
||||
ImGui::Checkbox("Performance", &ShowPerformance); ImGui::SameLine();
|
||||
ImGui::Checkbox("Marker", &ShowMarker); ImGui::SameLine();
|
||||
ImGui::Checkbox("Push Group", &ShowPushGroup); ImGui::SameLine();
|
||||
ImGui::Checkbox("Pop Group", &ShowPopGroup); ImGui::SameLine();
|
||||
ImGui::Checkbox("Performance", &ShowPerformance);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Marker", &ShowMarker);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Push Group", &ShowPushGroup);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Pop Group", &ShowPopGroup);
|
||||
ImGui::SameLine();
|
||||
ImGui::Checkbox("Other", &ShowOther);
|
||||
|
||||
Filter.Draw("Filter", -100.0f);
|
||||
ImGui::Separator();
|
||||
ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||
if (copy) ImGui::LogToClipboard();
|
||||
if (copy)
|
||||
ImGui::LogToClipboard();
|
||||
|
||||
if (Filter.IsActive())
|
||||
{
|
||||
@@ -79,10 +93,12 @@ void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar *message,
|
||||
const void* userParam){
|
||||
const void *userParam)
|
||||
{
|
||||
|
||||
std::string _severity;
|
||||
switch (severity){
|
||||
switch (severity)
|
||||
{
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
_severity = "LOW";
|
||||
break;
|
||||
@@ -97,34 +113,41 @@ void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
||||
break;
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
switch (type)
|
||||
{
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
if(Utility::Debug::openGLLogger.ShowError) {
|
||||
if (Utility::Debug::openGLLogger.ShowError)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("ERROR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
if(Utility::Debug::openGLLogger.ShowDeprecatedBehavior) {
|
||||
if (Utility::Debug::openGLLogger.ShowDeprecatedBehavior)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("DEPRECATED_BEHAVIOR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
if(Utility::Debug::openGLLogger.ShowUndefinedBehavior) {
|
||||
if (Utility::Debug::openGLLogger.ShowUndefinedBehavior)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("UNDEFINED_BEHAVIOR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
if(Utility::Debug::openGLLogger.ShowPortability) {
|
||||
if (Utility::Debug::openGLLogger.ShowPortability)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("PORTATBILITY: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
if(Utility::Debug::openGLLogger.ShowPerformance) {
|
||||
if (Utility::Debug::openGLLogger.ShowPerformance)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("PERFORMANCE: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
case GL_DEBUG_TYPE_OTHER:
|
||||
if(Utility::Debug::openGLLogger.ShowOther) {
|
||||
if (Utility::Debug::openGLLogger.ShowOther)
|
||||
{
|
||||
Debug::openGLLogger.AddLog("OTHER: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||
}
|
||||
break;
|
||||
@@ -132,13 +155,16 @@ void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
||||
}
|
||||
|
||||
static const char *Errornames[] = {"OpenGL", "SDL", "GLEW", "Other"};
|
||||
void Utility::printWarning(ERROR_TYPE type, std::string msg) {
|
||||
void Utility::printWarning(ERROR_TYPE type, std::string msg)
|
||||
{
|
||||
std::cout << "Warning[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
|
||||
void Utility::printError(ERROR_TYPE type, std::string msg) {
|
||||
void Utility::printError(ERROR_TYPE type, std::string msg)
|
||||
{
|
||||
std::cout << "Error[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
void Utility::printInfo(ERROR_TYPE type, std::string msg) {
|
||||
void Utility::printInfo(ERROR_TYPE type, std::string msg)
|
||||
{
|
||||
std::cout << "Info[" << Errornames[type] << "]: " << msg << std::endl;
|
||||
}
|
||||
@@ -10,10 +10,12 @@
|
||||
#include "imgui.h"
|
||||
#endif
|
||||
|
||||
namespace Utility{
|
||||
namespace Utility
|
||||
{
|
||||
|
||||
#ifndef NDEBUG
|
||||
namespace Debug {
|
||||
namespace Debug
|
||||
{
|
||||
|
||||
// Usage:
|
||||
// static ExampleAppLog my_log;
|
||||
@@ -44,10 +46,16 @@ struct ImGuiLogger
|
||||
|
||||
extern ImGuiLogger openGLLogger;
|
||||
|
||||
}
|
||||
} // namespace Debug
|
||||
#endif //NDEBUG
|
||||
|
||||
enum ERROR_TYPE { OpenGL = 0, SDL, GLEW, Other};
|
||||
enum ERROR_TYPE
|
||||
{
|
||||
OpenGL = 0,
|
||||
SDL,
|
||||
GLEW,
|
||||
Other
|
||||
};
|
||||
|
||||
void APIENTRY openglCallbackFunction(GLenum source,
|
||||
GLenum type,
|
||||
@@ -57,13 +65,11 @@ void APIENTRY openglCallbackFunction(GLenum source,
|
||||
const GLchar *message,
|
||||
const void *userParam);
|
||||
|
||||
|
||||
|
||||
void printWarning(ERROR_TYPE type, std::string msg);
|
||||
|
||||
void printError(ERROR_TYPE type, std::string msg);
|
||||
|
||||
void printInfo(ERROR_TYPE type, std::string msg);
|
||||
|
||||
}
|
||||
} // namespace Utility
|
||||
#endif // UTILITY_H
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef POSITION_H
|
||||
#define POSITION_H
|
||||
|
||||
struct Position {
|
||||
struct Position
|
||||
{
|
||||
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
|
||||
|
||||
float x, y;
|
||||
|
||||
@@ -2,22 +2,27 @@
|
||||
|
||||
#include "../DesktopLauncher.h"
|
||||
|
||||
void QuitCommand::execute(OrtographicCamera& camera) {
|
||||
void QuitCommand::execute(OrtographicCamera &camera)
|
||||
{
|
||||
Game::exit();
|
||||
}
|
||||
|
||||
void WCommand::execute(OrtographicCamera& camera) {
|
||||
void WCommand::execute(OrtographicCamera &camera)
|
||||
{
|
||||
camera.zoomIn(0.01f);
|
||||
}
|
||||
|
||||
void ACommand::execute(OrtographicCamera& camera) {
|
||||
void ACommand::execute(OrtographicCamera &camera)
|
||||
{
|
||||
camera.translate(glm::vec2(-0.1f, 0.0f));
|
||||
}
|
||||
|
||||
void SCommand::execute(OrtographicCamera& camera) {
|
||||
void SCommand::execute(OrtographicCamera &camera)
|
||||
{
|
||||
camera.zoomIn(-0.01f);
|
||||
}
|
||||
|
||||
void DCommand::execute(OrtographicCamera& camera) {
|
||||
void DCommand::execute(OrtographicCamera &camera)
|
||||
{
|
||||
camera.translate(glm::vec2(0.1f, 0.0f));
|
||||
}
|
||||
@@ -3,33 +3,38 @@
|
||||
|
||||
#include "../Camera.h"
|
||||
|
||||
class Command {
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
virtual ~Command() {}
|
||||
virtual void execute(OrtographicCamera &camera) = 0;
|
||||
};
|
||||
|
||||
class QuitCommand : public Command {
|
||||
class QuitCommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(OrtographicCamera &camera) override;
|
||||
};
|
||||
|
||||
class WCommand : public Command {
|
||||
class WCommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(OrtographicCamera &camera) override;
|
||||
};
|
||||
class ACommand : public Command {
|
||||
class ACommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(OrtographicCamera &camera) override;
|
||||
};
|
||||
class SCommand : public Command {
|
||||
class SCommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(OrtographicCamera &camera) override;
|
||||
};
|
||||
class DCommand : public Command {
|
||||
class DCommand : public Command
|
||||
{
|
||||
public:
|
||||
virtual void execute(OrtographicCamera &camera) override;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
InputHandler::InputHandler() {
|
||||
InputHandler::InputHandler()
|
||||
{
|
||||
W = new WCommand();
|
||||
A = new ACommand();
|
||||
S = new SCommand();
|
||||
@@ -10,7 +11,8 @@ InputHandler::InputHandler() {
|
||||
quit = new QuitCommand();
|
||||
}
|
||||
|
||||
InputHandler::~InputHandler() {
|
||||
InputHandler::~InputHandler()
|
||||
{
|
||||
//Free all Commands
|
||||
delete W;
|
||||
delete A;
|
||||
@@ -19,11 +21,14 @@ InputHandler::~InputHandler() {
|
||||
delete quit;
|
||||
}
|
||||
|
||||
Command* InputHandler::handleInput(SDL_Event *event) {
|
||||
if(event == NULL) {
|
||||
Command *InputHandler::handleInput(SDL_Event *event)
|
||||
{
|
||||
if (event == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
switch (event->type) {
|
||||
switch (event->type)
|
||||
{
|
||||
case SDL_QUIT:
|
||||
return quit;
|
||||
break;
|
||||
@@ -33,7 +38,8 @@ Command* InputHandler::handleInput(SDL_Event *event) {
|
||||
break;
|
||||
case SDL_KEYUP:
|
||||
std::cout << "The Key " << SDL_GetKeyName(event->key.keysym.sym) << " has been released!" << std::endl;
|
||||
switch(event->key.keysym.sym) {
|
||||
switch (event->key.keysym.sym)
|
||||
{
|
||||
case SDLK_w:
|
||||
return W;
|
||||
break;
|
||||
@@ -46,7 +52,8 @@ Command* InputHandler::handleInput(SDL_Event *event) {
|
||||
case SDLK_d:
|
||||
return D;
|
||||
break;
|
||||
default: break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
break;
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
|
||||
#include "Command.h"
|
||||
|
||||
class InputHandler {
|
||||
class InputHandler
|
||||
{
|
||||
public:
|
||||
~InputHandler();
|
||||
InputHandler();
|
||||
|
||||
@@ -4,24 +4,21 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
GameScreen::GameScreen(Renderer* renderer, Assets* assets) {
|
||||
GameScreen::GameScreen(Renderer *renderer, Assets *assets)
|
||||
{
|
||||
std::cout << "GameScreen got created!" << std::endl;
|
||||
this->renderer = renderer;
|
||||
this->assets = assets;
|
||||
|
||||
//Vertex2D can be defined like this, because it an aggregate class.
|
||||
// see https://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how-why-are-they-special
|
||||
std::vector<Vertex2D> vertices({
|
||||
Vertex2D{glm::vec2(-0.5f,-0.5f), glm::vec2(0.0f,1.0f)},
|
||||
std::vector<Vertex2D> vertices({Vertex2D{glm::vec2(-0.5f, -0.5f), glm::vec2(0.0f, 1.0f)},
|
||||
Vertex2D{glm::vec2(0.5f, -0.5f), glm::vec2(1.0f, 1.0f)},
|
||||
Vertex2D{glm::vec2(0.5f, 0.5f), glm::vec2(1.0f, 0.0f)},
|
||||
Vertex2D{glm::vec2(-0.5f,0.5f), glm::vec2(0.0f,0.0f)}
|
||||
});
|
||||
Vertex2D{glm::vec2(-0.5f, 0.5f), glm::vec2(0.0f, 0.0f)}});
|
||||
|
||||
std::vector<unsigned int> indices({
|
||||
0,1,3,
|
||||
1,2,3
|
||||
});
|
||||
std::vector<unsigned int> indices({0, 1, 3,
|
||||
1, 2, 3});
|
||||
|
||||
obj = new Mesh(vertices, indices, assets->getTexture("police_officer"));
|
||||
|
||||
@@ -34,21 +31,23 @@ GameScreen::GameScreen(Renderer* renderer, Assets* assets) {
|
||||
//charakter.assign<Position>();
|
||||
}
|
||||
|
||||
GameScreen::~GameScreen() {
|
||||
GameScreen::~GameScreen()
|
||||
{
|
||||
delete camera;
|
||||
delete obj;
|
||||
delete inputHandler;
|
||||
}
|
||||
|
||||
void GameScreen::hide() {
|
||||
|
||||
void GameScreen::hide()
|
||||
{
|
||||
}
|
||||
|
||||
void GameScreen::pause() {
|
||||
|
||||
void GameScreen::pause()
|
||||
{
|
||||
}
|
||||
|
||||
void GameScreen::render() {
|
||||
void GameScreen::render()
|
||||
{
|
||||
//Drawing
|
||||
Shader defaultShader = assets->getShader("defaultShader");
|
||||
defaultShader.SetMatrix4("MVP", camera->getCombinedMatrix(), true);
|
||||
@@ -56,24 +55,27 @@ void GameScreen::render() {
|
||||
renderer->draw(*obj, defaultShader);
|
||||
}
|
||||
|
||||
void GameScreen::update() {
|
||||
void GameScreen::update()
|
||||
{
|
||||
SDL_Event event;
|
||||
while(SDL_PollEvent(&event) != 0) {
|
||||
while (SDL_PollEvent(&event) != 0)
|
||||
{
|
||||
Command *command = inputHandler->handleInput(&event);
|
||||
if (command) {
|
||||
if (command)
|
||||
{
|
||||
command->execute(*camera);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GameScreen::resize() {
|
||||
|
||||
void GameScreen::resize()
|
||||
{
|
||||
}
|
||||
|
||||
void GameScreen::resume() {
|
||||
|
||||
void GameScreen::resume()
|
||||
{
|
||||
}
|
||||
|
||||
void GameScreen::show() {
|
||||
|
||||
void GameScreen::show()
|
||||
{
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
#include "../Camera.h"
|
||||
#include "../input/InputHandler.h"
|
||||
|
||||
class GameScreen : public Screen {
|
||||
class GameScreen : public Screen
|
||||
{
|
||||
public:
|
||||
GameScreen(Renderer *renderer, Assets *assets);
|
||||
~GameScreen();
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
#ifndef SCREEN_H
|
||||
#define SCREEN_H
|
||||
|
||||
class Screen {
|
||||
class Screen
|
||||
{
|
||||
protected:
|
||||
Screen() {}
|
||||
|
||||
@@ -16,7 +17,6 @@ class Screen {
|
||||
virtual void resize() = 0;
|
||||
virtual void resume() = 0;
|
||||
virtual void show() = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user