1er commit

This commit is contained in:
2021-08-21 10:14:47 +02:00
commit a99ecf7c2d
99 changed files with 66605 additions and 0 deletions

44
include/render/Renderer.h Normal file
View File

@@ -0,0 +1,44 @@
/*
* Renderer.h
*
* Created on: 4 nov. 2020
* Author: simon
*/
#ifndef RENDER_RENDERER_H_
#define RENDER_RENDERER_H_
#include <glm/glm.hpp>
#include "loader/GLLoader.h"
namespace td {
namespace render{
namespace Renderer{
struct Model{
GL::VAO* vao;
glm::vec2 positon;
};
bool init();
void destroy();
void prepare();
void resize(const int width, const int height);
void renderVAO(const GL::VAO& vao);
void renderModel(const Model& model);
void setZoom(float zoom);
void setCamMovement(const glm::vec2& mov);
void setCamPos(const glm::vec2& newPos);
void setIsometricView(bool isometric); // false = 2D true = Isometric
}
} // namespace render
} // namespace td
#endif /* RENDER_RENDERER_H_ */

View File

@@ -0,0 +1,23 @@
#pragma once
#include "game/World.h"
namespace td {
namespace render {
namespace WorldRenderer{
void init(const game::World* world);
void update();
void render();
void destroy();
void moveCam(float relativeX, float relativeY, float aspectRatio);
void changeZoom(float zoom);
void click(int mouseX, int mouseY);
} // namespace WorldRenderer
} // namespace render
} // namespace td

View File

@@ -0,0 +1,23 @@
/*
* TowerGUI.h
*
* Created on: 5 nov. 2020
* Author: simon
*/
#ifndef RENDER_GUI_TOWERGUI_H_
#define RENDER_GUI_TOWERGUI_H_
struct GLFWwindow;
namespace TowerGui{
void init(GLFWwindow* window);
void render();
void destroy();
}
#endif /* RENDER_GUI_TOWERGUI_H_ */

View File

@@ -0,0 +1,67 @@
/*
* GLLoader.h
*
* Created on: 4 nov. 2020
* Author: simon
*/
#pragma once
#include <vector>
#define REMOVE_COPY(className) \
className(const className &) = delete;\
className& operator=(const className &) = delete
namespace GL{
struct VertexAttribPointer{
unsigned int m_Index, m_Size;
int m_Offset;
};
class VBO{
private:
unsigned int m_ID, m_DataStride;
std::vector<VertexAttribPointer> m_VertexAttribs;
public:
REMOVE_COPY(VBO);
VBO(VBO&& other){
m_VertexAttribs = std::move(other.m_VertexAttribs);
m_ID = other.m_ID;
m_DataStride = other.m_DataStride;
other.m_ID = 0;
other.m_DataStride = 0;
}
VBO(const std::vector<float>& data, unsigned int stride);
~VBO();
void bind() const;
void unbind() const;
void addVertexAttribPointer(unsigned int index, unsigned int coordinateSize, unsigned int offset);
void bindVertexAttribs() const;
};
class VAO{
private:
unsigned int m_ID, m_VertexCount;
std::vector<VBO> m_Vbos; //use to destroy vbos when become unused
public:
REMOVE_COPY(VAO);
VAO(VAO&& other){
m_ID = other.m_ID;
m_VertexCount = other.m_VertexCount;
m_Vbos = std::move(other.m_Vbos);
other.m_VertexCount = 0;
other.m_ID = 0;
}
VAO(unsigned int vertexCount);
~VAO();
unsigned int getVertexCount() const {return m_VertexCount;}
void bindVBO(VBO& vbo);
void bind() const;
void unbind() const;
};
}

View File

@@ -0,0 +1,16 @@
/*
* TextureLoader.h
*
* Created on: 15 nov. 2020
* Author: simon
*/
#ifndef RENDER_LOADER_TEXTURELOADER_H_
#define RENDER_LOADER_TEXTURELOADER_H_
namespace TextureLoader{
const unsigned int loadGLTexture(const char* fileName);
}
#endif /* RENDER_LOADER_TEXTURELOADER_H_ */

View File

@@ -0,0 +1,18 @@
#pragma once
#include "game/World.h"
#include "GLLoader.h"
namespace td {
namespace render {
namespace WorldLoader {
GL::VAO loadMobModel();
GL::VAO loadWorldModel(const td::game::World* world);
} // namespace WorldLoader
} // namespace render
} // namespace td

7559
include/render/loader/stb_image.h Executable file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
#pragma once
#include "ShaderProgram.h"
class EntityShader : public ShaderProgram{
private:
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_translation = 0, location_viewtype = 0;
protected:
void getAllUniformLocation();
public:
EntityShader();
void loadShader();
void setCamPos(const glm::vec2& camPos);
void setZoom(float zoom);
void setAspectRatio(float aspectRatio);
void setModelPos(const glm::vec2& modelPos);
void setIsometricView(float isometric);
};

View File

@@ -0,0 +1,47 @@
/*
* ShaderProgram.h
*
* Created on: 31 janv. 2020
* Author: simon
*/
#ifndef RENDER_SHADERS_SHADERPROGRAM_H_
#define RENDER_SHADERS_SHADERPROGRAM_H_
#include <string>
#include <glm/glm.hpp>
namespace gl{
enum class GLenum : unsigned int;
}
class ShaderProgram {
public:
ShaderProgram();
virtual ~ShaderProgram();
void start() const;
void stop() const;
void loadProgramFile(const std::string& vertexFile, const std::string& fragmentFile);
void loadProgram(const std::string& vertexSource, const std::string& fragmentSource);
protected:
virtual void getAllUniformLocation() = 0;
int getUniformLocation(const std::string& uniformName)const;
void loadFloat(const int location, const float value)const;
void loadInt(const int& location, const int& value)const;
void loadVector(const int& location, const glm::vec2& vector)const;
void loadVector(const int& location, const glm::vec3& vector)const;
void loadVector(const int& location, const glm::vec4& vector)const;
void loadBoolean(const int& location, const bool& value)const;
void loadMatrix(const int& location, const glm::mat4& matrix);
void cleanUp() const;
private:
unsigned int programID;
unsigned int vertexShaderID;
unsigned int fragmentShaderID;
int loadShaderFromFile(const std::string& file, gl::GLenum type);
int loadShader(const std::string& source, gl::GLenum type);
};
#endif /* RENDER_SHADERS_SHADERPROGRAM_H_ */

View File

@@ -0,0 +1,27 @@
/*
* GameShader.h
*
* Created on: 4 nov. 2020
* Author: simon
*/
#ifndef RENDER_SHADERS_GAMESHADER_H_
#define RENDER_SHADERS_GAMESHADER_H_
#include "ShaderProgram.h"
class WorldShader : public ShaderProgram{
private:
unsigned int location_cam = 0, location_zoom = 0, location_aspect_ratio = 0, location_viewtype = 0;
protected:
void getAllUniformLocation();
public:
WorldShader();
void loadShader();
void setCamPos(const glm::vec2& camPos);
void setZoom(float zoom);
void setAspectRatio(float aspectRatio);
void setIsometricView(float isometric);
};
#endif /* RENDER_SHADERS_GAMESHADER_H_ */