Formatted classes
This commit is contained in:
@@ -9,13 +9,14 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
class Assets {
|
class Assets
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
std::map<std::string, Texture2D> textures;
|
std::map<std::string, Texture2D> textures;
|
||||||
std::map<std::string, Shader> shaders;
|
std::map<std::string, Shader> shaders;
|
||||||
|
|
||||||
Texture2D loadTextureFromFile(const GLchar *file, GLboolean alpha);
|
Texture2D loadTextureFromFile(const GLchar *file, GLboolean alpha);
|
||||||
Shader loadShaderFromFile(const GLchar *vShaderFile,const GLchar *fShaderFile, const GLchar *gShaderFile=nullptr);
|
Shader loadShaderFromFile(const GLchar *vShaderFile, const GLchar *fShaderFile, const GLchar *gShaderFile = nullptr);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Assets() {}
|
Assets() {}
|
||||||
@@ -25,8 +26,6 @@ class Assets {
|
|||||||
Shader getShader(std::string name);
|
Shader getShader(std::string name);
|
||||||
Texture2D loadTexture(const GLchar *file, GLboolean alpha, std::string name);
|
Texture2D loadTexture(const GLchar *file, GLboolean alpha, std::string name);
|
||||||
Texture2D getTexture(std::string name);
|
Texture2D getTexture(std::string name);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,20 +6,25 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
BitmapFont::BitmapFont(std::string fontLocation) {
|
BitmapFont::BitmapFont(std::string fontLocation)
|
||||||
|
{
|
||||||
FT_Library ft;
|
FT_Library ft;
|
||||||
if(FT_Init_FreeType(&ft)) {
|
if (FT_Init_FreeType(&ft))
|
||||||
|
{
|
||||||
std::cout << "ERROR::FreeType: Could not init FreeType Library" << std::endl;
|
std::cout << "ERROR::FreeType: Could not init FreeType Library" << std::endl;
|
||||||
}
|
}
|
||||||
FT_Face face;
|
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;
|
std::cout << "ERROR::FreeType: Failed to load font" << std::endl;
|
||||||
}
|
}
|
||||||
FT_Set_Pixel_Sizes(face, 0, 48);
|
FT_Set_Pixel_Sizes(face, 0, 48);
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1); //Disable byte-alignment restriction
|
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
|
//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;
|
std::cout << "ERROR::FreeType: Could not load Glyph: " << c << std::endl;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -35,8 +40,7 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
|||||||
0,
|
0,
|
||||||
GL_RED,
|
GL_RED,
|
||||||
GL_UNSIGNED_BYTE,
|
GL_UNSIGNED_BYTE,
|
||||||
face->glyph->bitmap.buffer
|
face->glyph->bitmap.buffer);
|
||||||
);
|
|
||||||
// Set texture options
|
// Set texture options
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, 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,
|
texture,
|
||||||
glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
|
glm::ivec2(face->glyph->bitmap.width, face->glyph->bitmap.rows),
|
||||||
glm::ivec2(face->glyph->bitmap_left, face->glyph->bitmap_top),
|
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));
|
characters.insert(std::pair<GLchar, Character>(c, character));
|
||||||
}
|
}
|
||||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //Reset byte-alignment restriction
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); //Reset byte-alignment restriction
|
||||||
@@ -57,7 +60,7 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
|||||||
glEnable(GL_BLEND);
|
glEnable(GL_BLEND);
|
||||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
projection = glm::ortho(0.0f,800.0f,0.0f,600.0f);
|
projection = glm::ortho(0.0f, 800.0f, 0.0f, 600.0f);
|
||||||
|
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
@@ -70,10 +73,11 @@ BitmapFont::BitmapFont(std::string fontLocation) {
|
|||||||
glBindVertexArray(0);
|
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.Use();
|
||||||
s.SetVector3f("textColor", color, true);
|
s.SetVector3f("textColor", color, true);
|
||||||
s.SetMatrix4("projection",projection,true);
|
s.SetMatrix4("projection", projection, true);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
@@ -91,14 +95,13 @@ void BitmapFont::drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLf
|
|||||||
GLfloat h = ch.size.y * scale;
|
GLfloat h = ch.size.y * scale;
|
||||||
// Update VBO for each character
|
// Update VBO for each character
|
||||||
GLfloat vertices[6][4] = {
|
GLfloat vertices[6][4] = {
|
||||||
{ xpos, ypos + h, 0.0, 0.0 },
|
{xpos, ypos + h, 0.0, 0.0},
|
||||||
{ xpos, ypos, 0.0, 1.0 },
|
{xpos, ypos, 0.0, 1.0},
|
||||||
{ xpos + w, ypos, 1.0, 1.0 },
|
{xpos + w, ypos, 1.0, 1.0},
|
||||||
|
|
||||||
{ xpos, ypos + h, 0.0, 0.0 },
|
{xpos, ypos + h, 0.0, 0.0},
|
||||||
{ xpos + w, ypos, 1.0, 1.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
|
// Render glyph texture over quad
|
||||||
glBindTexture(GL_TEXTURE_2D, ch.texID);
|
glBindTexture(GL_TEXTURE_2D, ch.texID);
|
||||||
// Update content of VBO memory
|
// Update content of VBO memory
|
||||||
|
|||||||
@@ -8,14 +8,16 @@
|
|||||||
|
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
struct Character {
|
struct Character
|
||||||
|
{
|
||||||
GLuint texID;
|
GLuint texID;
|
||||||
glm::ivec2 size;
|
glm::ivec2 size;
|
||||||
glm::ivec2 bearing;
|
glm::ivec2 bearing;
|
||||||
GLuint advance;
|
GLuint advance;
|
||||||
};
|
};
|
||||||
|
|
||||||
class BitmapFont {
|
class BitmapFont
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
BitmapFont(std::string fontLocation);
|
BitmapFont(std::string fontLocation);
|
||||||
void drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color);
|
void drawText(Shader &s, std::string text, GLfloat x, GLfloat y, GLfloat scale, glm::vec3 color);
|
||||||
|
|||||||
@@ -2,52 +2,60 @@
|
|||||||
|
|
||||||
#include <glm/gtc/matrix_transform.hpp>
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
void OrtographicCamera::setPosition(glm::vec2 position) {
|
void OrtographicCamera::setPosition(glm::vec2 position)
|
||||||
|
{
|
||||||
this->cameraPos = position;
|
this->cameraPos = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::vec2 OrtographicCamera::getPosition() {
|
glm::vec2 OrtographicCamera::getPosition()
|
||||||
|
{
|
||||||
return this->cameraPos;
|
return this->cameraPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrtographicCamera::setZoomLevel(float newZoom) {
|
void OrtographicCamera::setZoomLevel(float newZoom)
|
||||||
|
{
|
||||||
this->zoom = newZoom;
|
this->zoom = newZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrtographicCamera::zoomIn(float targetZoom) {
|
void OrtographicCamera::zoomIn(float targetZoom)
|
||||||
|
{
|
||||||
zoom -= targetZoom;
|
zoom -= targetZoom;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrtographicCamera::translate(glm::vec2 target) {
|
void OrtographicCamera::translate(glm::vec2 target)
|
||||||
|
{
|
||||||
cameraPos = cameraPos - 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);
|
glm::mat4 view(1);
|
||||||
view = glm::translate(view, glm::vec3(-cameraPos,0.f));
|
view = glm::translate(view, glm::vec3(-cameraPos, 0.f));
|
||||||
return view;
|
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)
|
//Dies gibt die Größe des kamera auschnittes an die in die welt zeigt (Frustum)
|
||||||
int width = 800;
|
int width = 800;
|
||||||
int height = 600;
|
int height = 600;
|
||||||
int DPI = 2; // 200% windows settings
|
int DPI = 2; // 200% windows settings
|
||||||
glm::mat4 projection;
|
glm::mat4 projection;
|
||||||
projection = glm::ortho(0.0f, (width/DPI)*this->zoom, 0.0f, (height/DPI)*this->zoom);
|
projection = glm::ortho(0.0f, (width / DPI) * this->zoom, 0.0f, (height / DPI) * this->zoom);
|
||||||
return projection;
|
return projection;
|
||||||
}
|
}
|
||||||
|
|
||||||
glm::mat4 OrtographicCamera::getCombinedMatrix() {
|
glm::mat4 OrtographicCamera::getCombinedMatrix()
|
||||||
|
{
|
||||||
glm::mat4 combined;
|
glm::mat4 combined;
|
||||||
combined = getProjectionMatrix() * getViewMatrix();
|
combined = getProjectionMatrix() * getViewMatrix();
|
||||||
return combined;
|
return combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OrtographicCamera::update() {
|
void OrtographicCamera::update()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
@@ -3,13 +3,14 @@
|
|||||||
|
|
||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
class OrtographicCamera {
|
class OrtographicCamera
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
glm::vec2 cameraPos;
|
glm::vec2 cameraPos;
|
||||||
float zoom;
|
float zoom;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
OrtographicCamera() : cameraPos(glm::vec2(-5.0f,-5.0f)), zoom(0.05f) {}
|
OrtographicCamera() : cameraPos(glm::vec2(-5.0f, -5.0f)), zoom(0.05f) {}
|
||||||
|
|
||||||
void setPosition(glm::vec2);
|
void setPosition(glm::vec2);
|
||||||
glm::vec2 getPosition();
|
glm::vec2 getPosition();
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
#include "DarkRP2D.h"
|
#include "DarkRP2D.h"
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#include "imgui_impl_sdl_gl3.h"
|
#include "imgui_impl_sdl_gl3.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
@@ -10,51 +10,56 @@
|
|||||||
#include "screens/GameScreen.h"
|
#include "screens/GameScreen.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
|
||||||
DarkRP2D::~DarkRP2D() {
|
DarkRP2D::~DarkRP2D()
|
||||||
|
{
|
||||||
std::cout << "Game got destroyed!" << std::endl;
|
std::cout << "Game got destroyed!" << std::endl;
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
ImGui_ImplSdlGL3_Shutdown();
|
ImGui_ImplSdlGL3_Shutdown();
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
#endif
|
#endif
|
||||||
delete gameScreen;
|
delete gameScreen;
|
||||||
delete assets;
|
delete assets;
|
||||||
delete renderer;
|
delete renderer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarkRP2D::create () {
|
void DarkRP2D::create()
|
||||||
|
{
|
||||||
std::cout << "Game got created!" << std::endl;
|
std::cout << "Game got created!" << std::endl;
|
||||||
assets = new Assets();
|
assets = new Assets();
|
||||||
assets->loadTexture("police_officer.png",true,"police_officer");
|
assets->loadTexture("police_officer.png", true, "police_officer");
|
||||||
assets->loadShader("vert.shader","frag.shader",nullptr,"defaultShader");
|
assets->loadShader("vert.shader", "frag.shader", nullptr, "defaultShader");
|
||||||
assets->loadShader("bitmapvert.shader","bitmapfrag.shader",nullptr,"bitmapShader");
|
assets->loadShader("bitmapvert.shader", "bitmapfrag.shader", nullptr, "bitmapShader");
|
||||||
|
|
||||||
renderer = new Renderer();
|
renderer = new Renderer();
|
||||||
|
|
||||||
font = new BitmapFont("arial.ttf");
|
font = new BitmapFont("arial.ttf");
|
||||||
|
|
||||||
gameScreen = new GameScreen(renderer,assets);
|
gameScreen = new GameScreen(renderer, assets);
|
||||||
gameScreen->show();
|
gameScreen->show();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
//Setup IMGUI debugging
|
//Setup IMGUI debugging
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui_ImplSdlGL3_Init(this->gWindow);
|
ImGui_ImplSdlGL3_Init(this->gWindow);
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarkRP2D::loop(unsigned int delta) {
|
void DarkRP2D::loop(unsigned int delta)
|
||||||
|
{
|
||||||
static unsigned int accumulator = 0, ups = 0, fps = 0, acc = 0;
|
static unsigned int accumulator = 0, ups = 0, fps = 0, acc = 0;
|
||||||
accumulator += delta;
|
accumulator += delta;
|
||||||
acc += delta;
|
acc += delta;
|
||||||
|
|
||||||
while(accumulator >= 17) {
|
while (accumulator >= 17)
|
||||||
|
{
|
||||||
accumulator -= 17;
|
accumulator -= 17;
|
||||||
update(delta);
|
update(delta);
|
||||||
ups++;
|
ups++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(acc >= 1000) {
|
if (acc >= 1000)
|
||||||
|
{
|
||||||
std::cout << "Updates per second: " << ups << " Frames per Second: " << fps << std::endl;
|
std::cout << "Updates per second: " << ups << " Frames per Second: " << fps << std::endl;
|
||||||
acc -= 1000;
|
acc -= 1000;
|
||||||
ups = 0;
|
ups = 0;
|
||||||
@@ -64,23 +69,25 @@ void DarkRP2D::loop(unsigned int delta) {
|
|||||||
fps++;
|
fps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarkRP2D::update(unsigned int delta) {
|
void DarkRP2D::update(unsigned int delta)
|
||||||
|
{
|
||||||
gameScreen->update();
|
gameScreen->update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarkRP2D::render(unsigned int delta) {
|
void DarkRP2D::render(unsigned int delta)
|
||||||
|
{
|
||||||
renderer->clear();
|
renderer->clear();
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
ImGui_ImplSdlGL3_NewFrame(gWindow);
|
ImGui_ImplSdlGL3_NewFrame(gWindow);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//texttest
|
//texttest
|
||||||
Shader bitmapShader = assets->getShader("bitmapShader");
|
Shader bitmapShader = assets->getShader("bitmapShader");
|
||||||
font->drawText(bitmapShader, "Hallo du noob", 25.0f, 25.0f, 1.f, glm::vec3(0.5f,0.8f,0.2f));
|
font->drawText(bitmapShader, "Hallo du noob", 25.0f, 25.0f, 1.f, glm::vec3(0.5f, 0.8f, 0.2f));
|
||||||
|
|
||||||
gameScreen->render();
|
gameScreen->render();
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// 1. Show a simple window.
|
// 1. Show a simple window.
|
||||||
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
|
// Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
|
||||||
static bool ShowOpenGLLogger = false;
|
static bool ShowOpenGLLogger = false;
|
||||||
@@ -96,15 +103,16 @@ void DarkRP2D::render(unsigned int delta) {
|
|||||||
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
|
||||||
ImGui::Checkbox("Show OpenGL Logger", &ShowOpenGLLogger);
|
ImGui::Checkbox("Show OpenGL Logger", &ShowOpenGLLogger);
|
||||||
}
|
}
|
||||||
if(ShowOpenGLLogger)
|
if (ShowOpenGLLogger)
|
||||||
Utility::Debug::openGLLogger.Draw("OpenGL Logger");
|
Utility::Debug::openGLLogger.Draw("OpenGL Logger");
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplSdlGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_GL_SwapWindow(gWindow);
|
SDL_GL_SwapWindow(gWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DarkRP2D::resize(int width, int height){
|
void DarkRP2D::resize(int width, int height)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
@@ -5,31 +5,29 @@ class DarkRP2D;
|
|||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#include "Assets.h"
|
#include "Assets.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "input/InputHandler.h"
|
#include "input/InputHandler.h"
|
||||||
#include "BitmapFont.h"
|
#include "BitmapFont.h"
|
||||||
#include "screens/Screen.h"
|
#include "screens/Screen.h"
|
||||||
|
|
||||||
class DarkRP2D {
|
class DarkRP2D
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
SDL_Window* gWindow;
|
SDL_Window *gWindow;
|
||||||
Assets *assets;
|
Assets *assets;
|
||||||
Renderer* renderer;
|
Renderer *renderer;
|
||||||
BitmapFont *font;
|
BitmapFont *font;
|
||||||
Screen *gameScreen;
|
Screen *gameScreen;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
DarkRP2D(SDL_Window *gWindow) : gWindow(gWindow) {}
|
DarkRP2D(SDL_Window *gWindow) : gWindow(gWindow) {}
|
||||||
~DarkRP2D();
|
~DarkRP2D();
|
||||||
void create ();
|
void create();
|
||||||
void loop(unsigned int delta);
|
void loop(unsigned int delta);
|
||||||
void update(unsigned int delta);
|
void update(unsigned int delta);
|
||||||
void render(unsigned int delta);
|
void render(unsigned int delta);
|
||||||
void resize(int width, int height);
|
void resize(int width, int height);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,23 +4,24 @@
|
|||||||
#include <SDL_image.h>
|
#include <SDL_image.h>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
|
|
||||||
#include "Desktoplauncher.h"
|
#include "Desktoplauncher.h"
|
||||||
#include "DarkRP2D.h"
|
#include "DarkRP2D.h"
|
||||||
#include "Utility.h"
|
#include "Utility.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
static SDL_Window* gWindow = NULL;
|
static SDL_Window *gWindow = NULL;
|
||||||
static SDL_GLContext glcontext;
|
static SDL_GLContext glcontext;
|
||||||
static bool gameQuit = false;
|
static bool gameQuit = false;
|
||||||
|
|
||||||
void dispose();
|
void dispose();
|
||||||
bool initSDL();
|
bool initSDL();
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
//Init SDL_Window, SDL_Surface, SDL_Renderer
|
//Init SDL_Window, SDL_Surface, SDL_Renderer
|
||||||
if(!initSDL()) {
|
if (!initSDL())
|
||||||
|
{
|
||||||
dispose();
|
dispose();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -29,7 +30,8 @@ int main(int argc, char *argv[]) {
|
|||||||
DarkRP2D resA(gWindow);
|
DarkRP2D resA(gWindow);
|
||||||
resA.create();
|
resA.create();
|
||||||
unsigned int lastTime = SDL_GetTicks(), currentTime, elapsedTime;
|
unsigned int lastTime = SDL_GetTicks(), currentTime, elapsedTime;
|
||||||
while( !gameQuit ) {
|
while (!gameQuit)
|
||||||
|
{
|
||||||
currentTime = SDL_GetTicks();
|
currentTime = SDL_GetTicks();
|
||||||
elapsedTime = currentTime - lastTime;
|
elapsedTime = currentTime - lastTime;
|
||||||
lastTime = currentTime;
|
lastTime = currentTime;
|
||||||
@@ -40,67 +42,79 @@ int main(int argc, char *argv[]) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::exit() {
|
void Game::exit()
|
||||||
|
{
|
||||||
gameQuit = true;
|
gameQuit = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace Game {
|
namespace Game
|
||||||
float DDPI, HDPI,VDPI;
|
{
|
||||||
|
float DDPI, HDPI, VDPI;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool initSDL() {
|
bool initSDL()
|
||||||
|
{
|
||||||
int result = SetProcessDPIAware(); // NEEDED or SDL_GetDisplayDPI returns wrong numbers
|
int result = SetProcessDPIAware(); // NEEDED or SDL_GetDisplayDPI returns wrong numbers
|
||||||
cout << "Result: " << result << endl;
|
cout << "Result: " << result << endl;
|
||||||
//Init SDL
|
//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;
|
cout << "SDL could not initialize! SDL_Error: " << SDL_GetError() << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Init Window
|
//Init Window
|
||||||
uint32_t WindowFlags = SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_OPENGL;
|
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);
|
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;
|
cout << "Window could not be created! SDL_Error: " << SDL_GetError() << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Read in Display DPI
|
//Read in Display DPI
|
||||||
int returnDisplayDPI = SDL_GetDisplayDPI(SDL_GetWindowDisplayIndex(gWindow),&Game::DDPI,&Game::HDPI,&Game::VDPI);
|
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 << "DisplayDPI cannot be loaded! SDL_ERROR: " << SDL_GetError() << endl;
|
||||||
}
|
}
|
||||||
cout << "DPI: DDPI: " << Game::DDPI << " HDPI: " << Game::HDPI << " VPDI: " << Game::VDPI << endl;
|
cout << "DPI: DDPI: " << Game::DDPI << " HDPI: " << Game::HDPI << " VPDI: " << Game::VDPI << endl;
|
||||||
//Mask deprectated functions
|
//Mask deprectated functions
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
|
||||||
#endif
|
#endif
|
||||||
//Init OpenGL Renderer
|
//Init OpenGL Renderer
|
||||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||||
glcontext = SDL_GL_CreateContext(gWindow);
|
glcontext = SDL_GL_CreateContext(gWindow);
|
||||||
if(glcontext == NULL) {
|
if (glcontext == NULL)
|
||||||
|
{
|
||||||
cout << "Could not create OpenGL Context: " << SDL_GetError() << endl;
|
cout << "Could not create OpenGL Context: " << SDL_GetError() << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Init GLEW
|
//Init GLEW
|
||||||
glewExperimental = GL_TRUE;
|
glewExperimental = GL_TRUE;
|
||||||
GLenum err = glewInit();
|
GLenum err = glewInit();
|
||||||
if(GLEW_OK != err) {
|
if (GLEW_OK != err)
|
||||||
|
{
|
||||||
cout << "Init of Glew failed: " << glewGetErrorString(err) << endl;
|
cout << "Init of Glew failed: " << glewGetErrorString(err) << endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//Init debug callback function
|
//Init debug callback function
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
if (GLEW_ARB_debug_output) {
|
if (GLEW_ARB_debug_output)
|
||||||
|
{
|
||||||
Utility::printInfo(Utility::GLEW, "Supporting 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!");
|
Utility::printInfo(Utility::GLEW, "Supporting AMD debug output!");
|
||||||
}
|
}
|
||||||
if (GLEW_KHR_debug) {
|
if (GLEW_KHR_debug)
|
||||||
|
{
|
||||||
Utility::printInfo(Utility::GLEW, "Supporting KHR debug output!");
|
Utility::printInfo(Utility::GLEW, "Supporting KHR debug output!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(glDebugMessageCallback) {
|
if (glDebugMessageCallback)
|
||||||
|
{
|
||||||
glEnable(GL_DEBUG_OUTPUT);
|
glEnable(GL_DEBUG_OUTPUT);
|
||||||
Utility::printInfo(Utility::OpenGL, "Register OpenGL debug callback");
|
Utility::printInfo(Utility::OpenGL, "Register OpenGL debug callback");
|
||||||
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
||||||
@@ -112,15 +126,18 @@ bool initSDL() {
|
|||||||
0,
|
0,
|
||||||
&unusedIds,
|
&unusedIds,
|
||||||
true);
|
true);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
Utility::printWarning(Utility::OpenGL, "glDebugMessageCallback not available");
|
Utility::printWarning(Utility::OpenGL, "glDebugMessageCallback not available");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dispose() {
|
void dispose()
|
||||||
|
{
|
||||||
SDL_GL_DeleteContext(glcontext);
|
SDL_GL_DeleteContext(glcontext);
|
||||||
SDL_DestroyWindow( gWindow );
|
SDL_DestroyWindow(gWindow);
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace Game {
|
namespace Game
|
||||||
|
{
|
||||||
|
|
||||||
const int SCREEN_WIDTH = 800;
|
const int SCREEN_WIDTH = 800;
|
||||||
const int SCREEN_HEIGHT = 600;
|
const int SCREEN_HEIGHT = 600;
|
||||||
@@ -15,8 +16,7 @@ extern float HDPI;
|
|||||||
//vertical DPI of the display used while starting
|
//vertical DPI of the display used while starting
|
||||||
extern float VDPI;
|
extern float VDPI;
|
||||||
|
|
||||||
|
|
||||||
void exit();
|
void exit();
|
||||||
|
|
||||||
}
|
} // namespace Game
|
||||||
#endif
|
#endif
|
||||||
29
src/Mesh.cpp
29
src/Mesh.cpp
@@ -3,8 +3,8 @@
|
|||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include <iostream>
|
#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->texture = texture;
|
||||||
this->vertices = vertices;
|
this->vertices = vertices;
|
||||||
this->indices = indices;
|
this->indices = indices;
|
||||||
@@ -12,13 +12,14 @@ Mesh::Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices, Te
|
|||||||
setupMesh();
|
setupMesh();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::setupMesh() {
|
void Mesh::setupMesh()
|
||||||
|
{
|
||||||
//Create VAO & Bind
|
//Create VAO & Bind
|
||||||
glGenVertexArrays(1, &VAO);
|
glGenVertexArrays(1, &VAO);
|
||||||
glBindVertexArray(VAO);
|
glBindVertexArray(VAO);
|
||||||
//Create VBO
|
//Create VBO
|
||||||
glGenBuffers(1, &VBO);
|
glGenBuffers(1, &VBO);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER,VBO);
|
glBindBuffer(GL_ARRAY_BUFFER, VBO);
|
||||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex2D), &vertices[0], GL_STATIC_DRAW);
|
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(Vertex2D), &vertices[0], GL_STATIC_DRAW);
|
||||||
//Create EBO
|
//Create EBO
|
||||||
glGenBuffers(1, &EBO);
|
glGenBuffers(1, &EBO);
|
||||||
@@ -27,7 +28,7 @@ void Mesh::setupMesh() {
|
|||||||
|
|
||||||
//Set attriPointer and enable
|
//Set attriPointer and enable
|
||||||
glEnableVertexAttribArray(0);
|
glEnableVertexAttribArray(0);
|
||||||
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *) 0);
|
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *)0);
|
||||||
|
|
||||||
glEnableVertexAttribArray(1);
|
glEnableVertexAttribArray(1);
|
||||||
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *)offsetof(Vertex2D, texCoord));
|
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex2D), (void *)offsetof(Vertex2D, texCoord));
|
||||||
@@ -36,21 +37,25 @@ void Mesh::setupMesh() {
|
|||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh::~Mesh() {
|
Mesh::~Mesh()
|
||||||
|
{
|
||||||
std::cout << "Deleting Mesh" << std::endl;
|
std::cout << "Deleting Mesh" << std::endl;
|
||||||
glDeleteBuffers(1,&VBO);
|
glDeleteBuffers(1, &VBO);
|
||||||
glDeleteBuffers(1,&EBO);
|
glDeleteBuffers(1, &EBO);
|
||||||
glDeleteBuffers(1,&VAO);
|
glDeleteBuffers(1, &VAO);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int Mesh::getIndicesCount() const {
|
unsigned int Mesh::getIndicesCount() const
|
||||||
|
{
|
||||||
return indices.size();
|
return indices.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::bindVAO() const {
|
void Mesh::bindVAO() const
|
||||||
|
{
|
||||||
glBindVertexArray(this->VAO);
|
glBindVertexArray(this->VAO);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mesh::bindTexture() const {
|
void Mesh::bindTexture() const
|
||||||
|
{
|
||||||
texture.Bind();
|
texture.Bind();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,12 +7,14 @@
|
|||||||
|
|
||||||
//Aggregate class -> so following construction is available
|
//Aggregate class -> so following construction is available
|
||||||
//Vertex2D{glm::vec2(-0.5f,-0.5f), glm::vec2(0.0f,1.0f)}
|
//Vertex2D{glm::vec2(-0.5f,-0.5f), glm::vec2(0.0f,1.0f)}
|
||||||
struct Vertex2D {
|
struct Vertex2D
|
||||||
|
{
|
||||||
glm::vec2 position;
|
glm::vec2 position;
|
||||||
glm::vec2 texCoord;
|
glm::vec2 texCoord;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Mesh {
|
class Mesh
|
||||||
|
{
|
||||||
private:
|
private:
|
||||||
unsigned int VBO, VAO, EBO;
|
unsigned int VBO, VAO, EBO;
|
||||||
|
|
||||||
@@ -24,7 +26,7 @@ class Mesh {
|
|||||||
std::vector<unsigned int> indices;
|
std::vector<unsigned int> indices;
|
||||||
Texture2D texture;
|
Texture2D texture;
|
||||||
|
|
||||||
Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices,Texture2D textures);
|
Mesh(std::vector<Vertex2D> vertices, std::vector<unsigned int> indices, Texture2D textures);
|
||||||
~Mesh();
|
~Mesh();
|
||||||
|
|
||||||
unsigned int getIndicesCount() const;
|
unsigned int getIndicesCount() const;
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
|
|
||||||
Renderer::Renderer() {
|
Renderer::Renderer()
|
||||||
glClearColor(1.f,1.f,1.f,1.f);
|
{
|
||||||
|
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
|
//Bind texture of mesh
|
||||||
mesh.bindTexture();
|
mesh.bindTexture();
|
||||||
mesh.bindVAO();
|
mesh.bindVAO();
|
||||||
@@ -13,6 +15,7 @@ void Renderer::draw(const Mesh& mesh, Shader& shader) {
|
|||||||
glDrawElements(GL_TRIANGLES, mesh.getIndicesCount(), GL_UNSIGNED_INT, 0);
|
glDrawElements(GL_TRIANGLES, mesh.getIndicesCount(), GL_UNSIGNED_INT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::clear() const {
|
void Renderer::clear() const
|
||||||
|
{
|
||||||
glClear(GL_COLOR_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT);
|
||||||
}
|
}
|
||||||
@@ -4,10 +4,11 @@
|
|||||||
#include "Mesh.h"
|
#include "Mesh.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
|
|
||||||
class Renderer {
|
class Renderer
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Renderer();
|
Renderer();
|
||||||
void draw(const Mesh& mesh, Shader& shader);
|
void draw(const Mesh &mesh, Shader &shader);
|
||||||
void clear() const;
|
void clear() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,14 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
Shader &Shader::Use() {
|
Shader &Shader::Use()
|
||||||
|
{
|
||||||
glUseProgram(this->ID);
|
glUseProgram(this->ID);
|
||||||
return *this;
|
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;
|
GLuint sVertex, sFragment, gShader;
|
||||||
// Vertex Shader
|
// Vertex Shader
|
||||||
sVertex = glCreateShader(GL_VERTEX_SHADER);
|
sVertex = glCreateShader(GL_VERTEX_SHADER);
|
||||||
@@ -42,54 +44,63 @@ void Shader::Compile(const GLchar* vertexSource, const GLchar* fragmentSource, c
|
|||||||
glDeleteShader(gShader);
|
glDeleteShader(gShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shader::SetFloat(const GLchar *name, GLfloat value, GLboolean useShader) {
|
void Shader::SetFloat(const GLchar *name, GLfloat value, GLboolean useShader)
|
||||||
|
{
|
||||||
if (useShader)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform1f(glGetUniformLocation(this->ID, name), value);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform1i(glGetUniformLocation(this->ID, name), value);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform2f(glGetUniformLocation(this->ID, name), x, y);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform2f(glGetUniformLocation(this->ID, name), value.x, value.y);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform3f(glGetUniformLocation(this->ID, name), x, y, z);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform3f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform4f(glGetUniformLocation(this->ID, name), x, y, z, w);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniform4f(glGetUniformLocation(this->ID, name), value.x, value.y, value.z, value.w);
|
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)
|
if (useShader)
|
||||||
this->Use();
|
this->Use();
|
||||||
glUniformMatrix4fv(glGetUniformLocation(this->ID, name), 1, GL_FALSE, glm::value_ptr(matrix));
|
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;
|
GLint success;
|
||||||
GLchar infoLog[1024];
|
GLchar infoLog[1024];
|
||||||
if (type != "PROGRAM")
|
if (type != "PROGRAM")
|
||||||
|
|||||||
26
src/Shader.h
26
src/Shader.h
@@ -7,32 +7,32 @@
|
|||||||
#include <glm/glm.hpp>
|
#include <glm/glm.hpp>
|
||||||
#include <glm/gtc/type_ptr.hpp>
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
|
||||||
|
|
||||||
// General purpsoe shader object. Compiles from file, generates
|
// General purpsoe shader object. Compiles from file, generates
|
||||||
// compile/link-time error messages and hosts several utility
|
// compile/link-time error messages and hosts several utility
|
||||||
// functions for easy management.
|
// functions for easy management.
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// State
|
// State
|
||||||
GLuint ID;
|
GLuint ID;
|
||||||
// Constructor
|
// Constructor
|
||||||
Shader() { }
|
Shader() {}
|
||||||
// Sets the current shader as active
|
// Sets the current shader as active
|
||||||
Shader &Use();
|
Shader &Use();
|
||||||
// Compiles the shader from given source code
|
// Compiles the shader from given source code
|
||||||
void Compile(const GLchar *vertexSource, const GLchar *fragmentSource, const GLchar *geometrySource = nullptr); // Note: geometry source code is optional
|
void Compile(const GLchar *vertexSource, const GLchar *fragmentSource, const GLchar *geometrySource = nullptr); // Note: geometry source code is optional
|
||||||
// Utility functions
|
// Utility functions
|
||||||
void SetFloat (const GLchar *name, GLfloat value, GLboolean useShader = false);
|
void SetFloat(const GLchar *name, GLfloat value, GLboolean useShader = false);
|
||||||
void SetInteger (const GLchar *name, GLint value, GLboolean useShader = false);
|
void SetInteger(const GLchar *name, GLint value, GLboolean useShader = false);
|
||||||
void SetVector2f (const GLchar *name, GLfloat x, GLfloat y, GLboolean useShader = false);
|
void SetVector2f(const GLchar *name, GLfloat x, GLfloat y, GLboolean useShader = false);
|
||||||
void SetVector2f (const GLchar *name, const glm::vec2 &value, GLboolean useShader = false);
|
void SetVector2f(const GLchar *name, const glm::vec2 &value, GLboolean useShader = false);
|
||||||
void SetVector3f (const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLboolean useShader = false);
|
void SetVector3f(const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLboolean useShader = false);
|
||||||
void SetVector3f (const GLchar *name, const glm::vec3 &value, GLboolean useShader = false);
|
void SetVector3f(const GLchar *name, const glm::vec3 &value, GLboolean useShader = false);
|
||||||
void SetVector4f (const GLchar *name, GLfloat x, GLfloat y, GLfloat z, GLfloat w, GLboolean useShader = false);
|
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 SetVector4f(const GLchar *name, const glm::vec4 &value, GLboolean useShader = false);
|
||||||
void SetMatrix4 (const GLchar *name, const glm::mat4 &matrix, GLboolean useShader = false);
|
void SetMatrix4(const GLchar *name, const glm::mat4 &matrix, GLboolean useShader = false);
|
||||||
private:
|
|
||||||
|
private:
|
||||||
// Checks if compilation or linking failed and if so, print the error logs
|
// Checks if compilation or linking failed and if so, print the error logs
|
||||||
void checkCompileErrors(GLuint object, std::string type);
|
void checkCompileErrors(GLuint object, std::string type);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
|
|
||||||
Texture2D::Texture2D()
|
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);
|
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->Width = width;
|
||||||
this->Height = height;
|
this->Height = height;
|
||||||
// Create Texture
|
// Create Texture
|
||||||
@@ -31,6 +31,7 @@ void Texture2D::Generate(GLuint width, GLuint height, unsigned char* data) {
|
|||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Texture2D::Bind() const {
|
void Texture2D::Bind() const
|
||||||
|
{
|
||||||
glBindTexture(GL_TEXTURE_2D, this->ID);
|
glBindTexture(GL_TEXTURE_2D, this->ID);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
// It also hosts utility functions for easy management.
|
// It also hosts utility functions for easy management.
|
||||||
class Texture2D
|
class Texture2D
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Holds the ID of the texture object, used for all texture operations to reference to this particlar texture
|
// Holds the ID of the texture object, used for all texture operations to reference to this particlar texture
|
||||||
GLuint ID;
|
GLuint ID;
|
||||||
// Texture image dimensions
|
// Texture image dimensions
|
||||||
@@ -23,7 +23,7 @@ public:
|
|||||||
// Constructor (sets default texture modes)
|
// Constructor (sets default texture modes)
|
||||||
Texture2D();
|
Texture2D();
|
||||||
// Generates texture from image data
|
// Generates texture from image data
|
||||||
void Generate(GLuint width, GLuint height, unsigned char* data);
|
void Generate(GLuint width, GLuint height, unsigned char *data);
|
||||||
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
// Binds the texture as the current active GL_TEXTURE_2D texture object
|
||||||
void Bind() const;
|
void Bind() const;
|
||||||
};
|
};
|
||||||
|
|||||||
104
src/Utility.cpp
104
src/Utility.cpp
@@ -2,18 +2,22 @@
|
|||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
|
|
||||||
namespace Utility{
|
namespace Utility
|
||||||
namespace Debug {
|
{
|
||||||
ImGuiLogger openGLLogger;
|
namespace Debug
|
||||||
}
|
{
|
||||||
}
|
ImGuiLogger openGLLogger;
|
||||||
|
}
|
||||||
|
} // namespace Utility
|
||||||
|
|
||||||
void Utility::Debug::ImGuiLogger::Clear() {
|
void Utility::Debug::ImGuiLogger::Clear()
|
||||||
|
{
|
||||||
Buf.clear();
|
Buf.clear();
|
||||||
LineOffsets.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();
|
int old_size = Buf.size();
|
||||||
va_list args;
|
va_list args;
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
@@ -23,37 +27,47 @@
|
|||||||
if (Buf[old_size] == '\n')
|
if (Buf[old_size] == '\n')
|
||||||
LineOffsets.push_back(old_size);
|
LineOffsets.push_back(old_size);
|
||||||
ScrollToBottom = true;
|
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::SetNextWindowSize(ImVec2(500, 400), ImGuiCond_FirstUseEver);
|
||||||
ImGui::Begin(title, p_open);
|
ImGui::Begin(title, p_open);
|
||||||
if (ImGui::Button("Clear")) Clear();
|
if (ImGui::Button("Clear"))
|
||||||
|
Clear();
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
bool copy = ImGui::Button("Copy");
|
bool copy = ImGui::Button("Copy");
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Errors", &ShowError); ImGui::SameLine();
|
ImGui::Checkbox("Errors", &ShowError);
|
||||||
ImGui::Checkbox("Deprecated Behavior", &ShowDeprecatedBehavior); ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Undefined Behavior", &ShowUndefinedBehavior); ImGui::SameLine();
|
ImGui::Checkbox("Deprecated Behavior", &ShowDeprecatedBehavior);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Checkbox("Undefined Behavior", &ShowUndefinedBehavior);
|
||||||
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Portability", &ShowPortability);
|
ImGui::Checkbox("Portability", &ShowPortability);
|
||||||
ImGui::Checkbox("Performance", &ShowPerformance); ImGui::SameLine();
|
ImGui::Checkbox("Performance", &ShowPerformance);
|
||||||
ImGui::Checkbox("Marker", &ShowMarker); ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Push Group", &ShowPushGroup); ImGui::SameLine();
|
ImGui::Checkbox("Marker", &ShowMarker);
|
||||||
ImGui::Checkbox("Pop Group", &ShowPopGroup); ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
ImGui::Checkbox("Push Group", &ShowPushGroup);
|
||||||
|
ImGui::SameLine();
|
||||||
|
ImGui::Checkbox("Pop Group", &ShowPopGroup);
|
||||||
|
ImGui::SameLine();
|
||||||
ImGui::Checkbox("Other", &ShowOther);
|
ImGui::Checkbox("Other", &ShowOther);
|
||||||
|
|
||||||
Filter.Draw("Filter", -100.0f);
|
Filter.Draw("Filter", -100.0f);
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
ImGui::BeginChild("scrolling", ImVec2(0,0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
ImGui::BeginChild("scrolling", ImVec2(0, 0), false, ImGuiWindowFlags_HorizontalScrollbar);
|
||||||
if (copy) ImGui::LogToClipboard();
|
if (copy)
|
||||||
|
ImGui::LogToClipboard();
|
||||||
|
|
||||||
if (Filter.IsActive())
|
if (Filter.IsActive())
|
||||||
{
|
{
|
||||||
const char* buf_begin = Buf.begin();
|
const char *buf_begin = Buf.begin();
|
||||||
const char* line = buf_begin;
|
const char *line = buf_begin;
|
||||||
for (int line_no = 0; line != NULL; line_no++)
|
for (int line_no = 0; line != NULL; line_no++)
|
||||||
{
|
{
|
||||||
const char* line_end = (line_no < LineOffsets.Size) ? buf_begin + LineOffsets[line_no] : NULL;
|
const char *line_end = (line_no < LineOffsets.Size) ? buf_begin + LineOffsets[line_no] : NULL;
|
||||||
if (Filter.PassFilter(line, line_end))
|
if (Filter.PassFilter(line, line_end))
|
||||||
ImGui::TextUnformatted(line, line_end);
|
ImGui::TextUnformatted(line, line_end);
|
||||||
line = line_end && line_end[1] ? line_end + 1 : NULL;
|
line = line_end && line_end[1] ? line_end + 1 : NULL;
|
||||||
@@ -69,7 +83,7 @@
|
|||||||
ScrollToBottom = false;
|
ScrollToBottom = false;
|
||||||
ImGui::EndChild();
|
ImGui::EndChild();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif //NDEBUG
|
#endif //NDEBUG
|
||||||
|
|
||||||
@@ -78,11 +92,13 @@ void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
|||||||
GLuint id,
|
GLuint id,
|
||||||
GLenum severity,
|
GLenum severity,
|
||||||
GLsizei length,
|
GLsizei length,
|
||||||
const GLchar* message,
|
const GLchar *message,
|
||||||
const void* userParam){
|
const void *userParam)
|
||||||
|
{
|
||||||
|
|
||||||
std::string _severity;
|
std::string _severity;
|
||||||
switch (severity){
|
switch (severity)
|
||||||
|
{
|
||||||
case GL_DEBUG_SEVERITY_LOW:
|
case GL_DEBUG_SEVERITY_LOW:
|
||||||
_severity = "LOW";
|
_severity = "LOW";
|
||||||
break;
|
break;
|
||||||
@@ -97,48 +113,58 @@ void APIENTRY Utility::openglCallbackFunction(GLenum source,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type)
|
||||||
|
{
|
||||||
case GL_DEBUG_TYPE_ERROR:
|
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());
|
Debug::openGLLogger.AddLog("ERROR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
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());
|
Debug::openGLLogger.AddLog("DEPRECATED_BEHAVIOR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
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());
|
Debug::openGLLogger.AddLog("UNDEFINED_BEHAVIOR: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEBUG_TYPE_PORTABILITY:
|
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());
|
Debug::openGLLogger.AddLog("PORTATBILITY: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
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());
|
Debug::openGLLogger.AddLog("PERFORMANCE: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case GL_DEBUG_TYPE_OTHER:
|
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());
|
Debug::openGLLogger.AddLog("OTHER: %s ID: %d SEVERITY: %s\n", message, id, _severity.c_str());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* Errornames[] = { "OpenGL", "SDL","GLEW", "Other" };
|
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;
|
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;
|
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;
|
std::cout << "Info[" << Errornames[type] << "]: " << msg << std::endl;
|
||||||
}
|
}
|
||||||
@@ -7,13 +7,15 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Utility{
|
namespace Utility
|
||||||
|
{
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
namespace Debug {
|
namespace Debug
|
||||||
|
{
|
||||||
|
|
||||||
// Usage:
|
// Usage:
|
||||||
// static ExampleAppLog my_log;
|
// static ExampleAppLog my_log;
|
||||||
@@ -38,26 +40,30 @@ struct ImGuiLogger
|
|||||||
ImGuiLogger() : ShowError(true) {}
|
ImGuiLogger() : ShowError(true) {}
|
||||||
|
|
||||||
void Clear();
|
void Clear();
|
||||||
void AddLog(const char* fmt, ...) IM_FMTARGS(2);
|
void AddLog(const char *fmt, ...) IM_FMTARGS(2);
|
||||||
void Draw(const char* title, bool* p_open = NULL);
|
void Draw(const char *title, bool *p_open = NULL);
|
||||||
};
|
};
|
||||||
|
|
||||||
extern ImGuiLogger openGLLogger;
|
extern ImGuiLogger openGLLogger;
|
||||||
|
|
||||||
}
|
} // namespace Debug
|
||||||
#endif //NDEBUG
|
#endif //NDEBUG
|
||||||
|
|
||||||
enum ERROR_TYPE { OpenGL = 0, SDL, GLEW, Other};
|
enum ERROR_TYPE
|
||||||
|
{
|
||||||
|
OpenGL = 0,
|
||||||
|
SDL,
|
||||||
|
GLEW,
|
||||||
|
Other
|
||||||
|
};
|
||||||
|
|
||||||
void APIENTRY openglCallbackFunction(GLenum source,
|
void APIENTRY openglCallbackFunction(GLenum source,
|
||||||
GLenum type,
|
GLenum type,
|
||||||
GLuint id,
|
GLuint id,
|
||||||
GLenum severity,
|
GLenum severity,
|
||||||
GLsizei length,
|
GLsizei length,
|
||||||
const GLchar* message,
|
const GLchar *message,
|
||||||
const void* userParam);
|
const void *userParam);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void printWarning(ERROR_TYPE type, std::string msg);
|
void printWarning(ERROR_TYPE type, std::string msg);
|
||||||
|
|
||||||
@@ -65,5 +71,5 @@ void printError(ERROR_TYPE type, std::string msg);
|
|||||||
|
|
||||||
void printInfo(ERROR_TYPE type, std::string msg);
|
void printInfo(ERROR_TYPE type, std::string msg);
|
||||||
|
|
||||||
}
|
} // namespace Utility
|
||||||
#endif // UTILITY_H
|
#endif // UTILITY_H
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#ifndef POSITION_H
|
#ifndef POSITION_H
|
||||||
#define POSITION_H
|
#define POSITION_H
|
||||||
|
|
||||||
struct Position {
|
struct Position
|
||||||
|
{
|
||||||
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
|
Position(float x = 0.0f, float y = 0.0f) : x(x), y(y) {}
|
||||||
|
|
||||||
float x, y;
|
float x, y;
|
||||||
|
|||||||
@@ -2,22 +2,27 @@
|
|||||||
|
|
||||||
#include "../DesktopLauncher.h"
|
#include "../DesktopLauncher.h"
|
||||||
|
|
||||||
void QuitCommand::execute(OrtographicCamera& camera) {
|
void QuitCommand::execute(OrtographicCamera &camera)
|
||||||
|
{
|
||||||
Game::exit();
|
Game::exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WCommand::execute(OrtographicCamera& camera) {
|
void WCommand::execute(OrtographicCamera &camera)
|
||||||
|
{
|
||||||
camera.zoomIn(0.01f);
|
camera.zoomIn(0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ACommand::execute(OrtographicCamera& camera) {
|
void ACommand::execute(OrtographicCamera &camera)
|
||||||
|
{
|
||||||
camera.translate(glm::vec2(-0.1f, 0.0f));
|
camera.translate(glm::vec2(-0.1f, 0.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
void SCommand::execute(OrtographicCamera& camera) {
|
void SCommand::execute(OrtographicCamera &camera)
|
||||||
|
{
|
||||||
camera.zoomIn(-0.01f);
|
camera.zoomIn(-0.01f);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DCommand::execute(OrtographicCamera& camera) {
|
void DCommand::execute(OrtographicCamera &camera)
|
||||||
|
{
|
||||||
camera.translate(glm::vec2(0.1f, 0.0f));
|
camera.translate(glm::vec2(0.1f, 0.0f));
|
||||||
}
|
}
|
||||||
@@ -3,33 +3,38 @@
|
|||||||
|
|
||||||
#include "../Camera.h"
|
#include "../Camera.h"
|
||||||
|
|
||||||
class Command {
|
class Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Command() {}
|
virtual ~Command() {}
|
||||||
virtual void execute(OrtographicCamera& camera) = 0;
|
virtual void execute(OrtographicCamera &camera) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QuitCommand : public Command {
|
class QuitCommand : public Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void execute(OrtographicCamera& camera) override;
|
virtual void execute(OrtographicCamera &camera) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WCommand : public Command {
|
class WCommand : public Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void execute(OrtographicCamera& camera) override;
|
virtual void execute(OrtographicCamera &camera) override;
|
||||||
};
|
};
|
||||||
class ACommand : public Command {
|
class ACommand : public Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void execute(OrtographicCamera& camera) override;
|
virtual void execute(OrtographicCamera &camera) override;
|
||||||
};
|
};
|
||||||
class SCommand : public Command {
|
class SCommand : public Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void execute(OrtographicCamera& camera) override;
|
virtual void execute(OrtographicCamera &camera) override;
|
||||||
};
|
};
|
||||||
class DCommand : public Command {
|
class DCommand : public Command
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual void execute(OrtographicCamera& camera) override;
|
virtual void execute(OrtographicCamera &camera) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
InputHandler::InputHandler() {
|
InputHandler::InputHandler()
|
||||||
|
{
|
||||||
W = new WCommand();
|
W = new WCommand();
|
||||||
A = new ACommand();
|
A = new ACommand();
|
||||||
S = new SCommand();
|
S = new SCommand();
|
||||||
@@ -10,7 +11,8 @@ InputHandler::InputHandler() {
|
|||||||
quit = new QuitCommand();
|
quit = new QuitCommand();
|
||||||
}
|
}
|
||||||
|
|
||||||
InputHandler::~InputHandler() {
|
InputHandler::~InputHandler()
|
||||||
|
{
|
||||||
//Free all Commands
|
//Free all Commands
|
||||||
delete W;
|
delete W;
|
||||||
delete A;
|
delete A;
|
||||||
@@ -19,11 +21,14 @@ InputHandler::~InputHandler() {
|
|||||||
delete quit;
|
delete quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
Command* InputHandler::handleInput(SDL_Event *event) {
|
Command *InputHandler::handleInput(SDL_Event *event)
|
||||||
if(event == NULL) {
|
{
|
||||||
|
if (event == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
switch (event->type) {
|
switch (event->type)
|
||||||
|
{
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
return quit;
|
return quit;
|
||||||
break;
|
break;
|
||||||
@@ -33,7 +38,8 @@ Command* InputHandler::handleInput(SDL_Event *event) {
|
|||||||
break;
|
break;
|
||||||
case SDL_KEYUP:
|
case SDL_KEYUP:
|
||||||
std::cout << "The Key " << SDL_GetKeyName(event->key.keysym.sym) << " has been released!" << std::endl;
|
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:
|
case SDLK_w:
|
||||||
return W;
|
return W;
|
||||||
break;
|
break;
|
||||||
@@ -46,7 +52,8 @@ Command* InputHandler::handleInput(SDL_Event *event) {
|
|||||||
case SDLK_d:
|
case SDLK_d:
|
||||||
return D;
|
return D;
|
||||||
break;
|
break;
|
||||||
default: break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -4,17 +4,18 @@
|
|||||||
|
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
|
|
||||||
class InputHandler {
|
class InputHandler
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
~InputHandler();
|
~InputHandler();
|
||||||
InputHandler();
|
InputHandler();
|
||||||
Command* handleInput(SDL_Event *event);
|
Command *handleInput(SDL_Event *event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Command* W;
|
Command *W;
|
||||||
Command* A;
|
Command *A;
|
||||||
Command* S;
|
Command *S;
|
||||||
Command* D;
|
Command *D;
|
||||||
Command* quit;
|
Command *quit;
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -4,26 +4,23 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
GameScreen::GameScreen(Renderer* renderer, Assets* assets) {
|
GameScreen::GameScreen(Renderer *renderer, Assets *assets)
|
||||||
|
{
|
||||||
std::cout << "GameScreen got created!" << std::endl;
|
std::cout << "GameScreen got created!" << std::endl;
|
||||||
this->renderer = renderer;
|
this->renderer = renderer;
|
||||||
this->assets = assets;
|
this->assets = assets;
|
||||||
|
|
||||||
//Vertex2D can be defined like this, because it an aggregate class.
|
//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
|
// see https://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how-why-are-they-special
|
||||||
std::vector<Vertex2D> vertices({
|
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(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,1.0f)},
|
Vertex2D{glm::vec2(0.5f, 0.5f), glm::vec2(1.0f, 0.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({
|
std::vector<unsigned int> indices({0, 1, 3,
|
||||||
0,1,3,
|
1, 2, 3});
|
||||||
1,2,3
|
|
||||||
});
|
|
||||||
|
|
||||||
obj = new Mesh(vertices,indices,assets->getTexture("police_officer"));
|
obj = new Mesh(vertices, indices, assets->getTexture("police_officer"));
|
||||||
|
|
||||||
inputHandler = new InputHandler();
|
inputHandler = new InputHandler();
|
||||||
camera = new OrtographicCamera();
|
camera = new OrtographicCamera();
|
||||||
@@ -34,46 +31,51 @@ GameScreen::GameScreen(Renderer* renderer, Assets* assets) {
|
|||||||
//charakter.assign<Position>();
|
//charakter.assign<Position>();
|
||||||
}
|
}
|
||||||
|
|
||||||
GameScreen::~GameScreen() {
|
GameScreen::~GameScreen()
|
||||||
|
{
|
||||||
delete camera;
|
delete camera;
|
||||||
delete obj;
|
delete obj;
|
||||||
delete inputHandler;
|
delete inputHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::hide() {
|
void GameScreen::hide()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::pause() {
|
void GameScreen::pause()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::render() {
|
void GameScreen::render()
|
||||||
|
{
|
||||||
//Drawing
|
//Drawing
|
||||||
Shader defaultShader = assets->getShader("defaultShader");
|
Shader defaultShader = assets->getShader("defaultShader");
|
||||||
defaultShader.SetMatrix4("MVP",camera->getCombinedMatrix(),true);
|
defaultShader.SetMatrix4("MVP", camera->getCombinedMatrix(), true);
|
||||||
//Draw Mesh
|
//Draw Mesh
|
||||||
renderer->draw(*obj,defaultShader);
|
renderer->draw(*obj, defaultShader);
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::update() {
|
void GameScreen::update()
|
||||||
|
{
|
||||||
SDL_Event event;
|
SDL_Event event;
|
||||||
while(SDL_PollEvent(&event) != 0) {
|
while (SDL_PollEvent(&event) != 0)
|
||||||
Command* command = inputHandler->handleInput(&event);
|
{
|
||||||
if (command) {
|
Command *command = inputHandler->handleInput(&event);
|
||||||
|
if (command)
|
||||||
|
{
|
||||||
command->execute(*camera);
|
command->execute(*camera);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::resize() {
|
void GameScreen::resize()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::resume() {
|
void GameScreen::resume()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameScreen::show() {
|
void GameScreen::show()
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,9 +8,10 @@
|
|||||||
#include "../Camera.h"
|
#include "../Camera.h"
|
||||||
#include "../input/InputHandler.h"
|
#include "../input/InputHandler.h"
|
||||||
|
|
||||||
class GameScreen : public Screen {
|
class GameScreen : public Screen
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
GameScreen(Renderer* renderer, Assets* assets);
|
GameScreen(Renderer *renderer, Assets *assets);
|
||||||
~GameScreen();
|
~GameScreen();
|
||||||
|
|
||||||
virtual void hide() override;
|
virtual void hide() override;
|
||||||
@@ -22,9 +23,9 @@ class GameScreen : public Screen {
|
|||||||
virtual void show() override;
|
virtual void show() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Renderer* renderer;
|
Renderer *renderer;
|
||||||
Assets* assets;
|
Assets *assets;
|
||||||
InputHandler* inputHandler;
|
InputHandler *inputHandler;
|
||||||
|
|
||||||
OrtographicCamera *camera;
|
OrtographicCamera *camera;
|
||||||
Mesh *obj;
|
Mesh *obj;
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
#ifndef SCREEN_H
|
#ifndef SCREEN_H
|
||||||
#define SCREEN_H
|
#define SCREEN_H
|
||||||
|
|
||||||
class Screen {
|
class Screen
|
||||||
|
{
|
||||||
protected:
|
protected:
|
||||||
Screen() {}
|
Screen() {}
|
||||||
|
|
||||||
@@ -16,7 +17,6 @@ class Screen {
|
|||||||
virtual void resize() = 0;
|
virtual void resize() = 0;
|
||||||
virtual void resume() = 0;
|
virtual void resume() = 0;
|
||||||
virtual void show() = 0;
|
virtual void show() = 0;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user