14 #include <GLFW/glfw3.h> 21 #include <unordered_map> 24 #define GLM_FORCE_RADIANS 25 #include <glm/glm.hpp> 27 #include FT_FREETYPE_H 43 static int realScreenWidth, realScreenHeight;
45 uint32_t perspectiveProgram = 0;
46 uint32_t orthographicProgram = 0;
49 uint32_t renderOrientation = 0;
50 uint32_t cameraOrientation = 0;
51 uint32_t worldDetails = 0;
52 uint32_t lightUboId = 0;
53 uint32_t perspColourUboId = 0;
54 uint32_t orthoColourUboId = 0;
58 float frustumScale = 0.0f;
61 float zOffsetFromCamera = 0.0f;
63 std::unordered_map<std::string, uint32_t> textures;
65 FT_Library library = 0;
66 std::vector<float> textMemory;
67 std::unordered_map<std::string, FT_Face> fontFaces;
69 static void framebufferSizeCallback(GLFWwindow* window,
int width,
72 std::string loadShaderFromFile(
const std::string& fileLocation)
const;
73 uint32_t compileShader(
const std::string& shaderSourceFile,
74 const uint32_t shaderType)
const;
75 std::string getProgramInfoLog(
const uint32_t linkedProgram)
const;
76 std::string getShaderInfoLog(
const uint32_t shader)
const;
78 void checkForOpenGLErrors(
const std::string& when,
const bool abort)
const;
80 void positionNextObject(
const glm::vec3& offset,
81 const glm::vec3& rotation)
const;
82 void positionCamera()
const;
83 uint32_t getTextureHandle(
const std::string& name)
const;
84 uint32_t generateTexture(
const std::string& name,
const float* data,
85 const unsigned long width,
86 const unsigned long height,
89 void init(
const int width,
const int height,
const std::string& windowTitle,
90 const std::string& shadersPath);
91 void initWindow(
int& width,
int& height,
92 const std::string& windowTitle =
"");
94 void setPerspectiveAndLight();
96 void bindTexture(
const std::string& name,
bool perspective);
98 Renderer(
const std::string& windowTitle,
const int width,
const int height,
99 const float frustumScale,
const float zNear,
const float zFar,
100 const float zOffsetFromCamera,
const std::string& shadersPath,
101 const uint32_t maxObjectsPerPass);
162 const int height = 0,
163 const float frustumScale = 1.0f,
164 const float zNear = 1.0f,
165 const float zFar = 24.0f,
166 const float zOffsetFromCamera = -1.0f,
167 const std::string& shadersPath =
168 "resources/shaders/",
169 const uint32_t maxObjectsPerPass = 20);
186 void generateTexture(
const std::string& name,
const Image& image);
199 void generateTexture(
const std::string& name,
const std::string& text,
200 const glm::vec3& colour,
201 const int fontSize = 48,
202 const std::string& fontPath =
203 "resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
204 const bool replace =
true);
221 const glm::vec3& topLeft,
222 const glm::vec3& bottomRight);
239 void render(
Model& model,
const glm::vec3& offset,
const glm::vec3& rotation,
240 const glm::vec4& colour,
const std::string& textureName =
"",
241 const bool perspective =
true);
251 void render(
Model& model,
const glm::vec3& offset,
const glm::vec3& rotation,
252 const std::string& textureName);
261 void render(
Model& model,
const std::string& textureName,
262 const bool perspective =
true);
271 const bool perspective =
true);
320 void operator=(
Renderer const&) =
delete;
322 void operator=(
Renderer&&) =
delete;
void deleteTexture(const std::string &name)
Deletes the texture indicated by the given name.
Definition: Renderer.cpp:662
A 3D model, loaded from a Wavefront file.
Definition: Model.hpp:21
void clearScreen() const
Clears the screen.
Definition: Renderer.cpp:877
Header of the Image class.
void clearBuffers(Model &model) const
Clear a Model from the GPU buffers (the Model itself remains intact).
Definition: Renderer.cpp:850
Header of the SceneObject class.
An image, loaded from a png file, which can be used for generating textures.
Definition: Image.hpp:29
glm::vec3 cameraPosition
The camera position in world space.
Definition: Renderer.hpp:114
glm::vec3 lightDirection
Vector, indicating the direction of the light in the scene.
Definition: Renderer.hpp:109
An object that appears on the 3D scene. It is made up of one or more models (the latter for animation...
Definition: SceneObject.hpp:35
void render(Model &model, const glm::vec3 &offset, const glm::vec3 &rotation, const glm::vec4 &colour, const std::string &textureName="", const bool perspective=true)
Render a Model.
Definition: Renderer.cpp:703
~Renderer()
Destructor.
Definition: Renderer.cpp:528
Renderer class (OpenGL 3.3)
Definition: Renderer.hpp:36
void swapBuffers() const
This is a double buffered system and this command swaps the buffers.
Definition: Renderer.cpp:892
void createRectangle(Model &rect, const glm::vec3 &topLeft, const glm::vec3 &bottomRight)
Populates a Model object with a rectangle stretching between the given coordinates.
Definition: Renderer.cpp:671
glm::vec3 cameraRotation
The camera rotation (around the x, y and z axes)
Definition: Renderer.hpp:119
Header of the Model class.
Header of the Logger class.
static Renderer & getInstance(const std::string &windowTitle="", const int width=0, const int height=0, const float frustumScale=1.0f, const float zNear=1.0f, const float zFar=24.0f, const float zOffsetFromCamera=-1.0f, const std::string &shadersPath="resources/shaders/", const uint32_t maxObjectsPerPass=20)
Get the instance of the Renderer (the Renderer is a singleton).
Definition: Renderer.cpp:514
GLFWwindow * getWindow() const
Get the GLFW window object, associated with the Renderer.
Definition: Renderer.cpp:561
float lightIntensity
The light intensity (set to -1.0f if no lighting is to be used).
Definition: Renderer.hpp:124