Go to the documentation of this file.
15 #include <GLFW/glfw3.h>
17 #define GLFW_EXPOSE_NATIVE_WIN32
18 #include <GLFW/glfw3native.h>
25 #include <unordered_map>
28 #include FT_FREETYPE_H
44 static int realScreenWidth, realScreenHeight;
46 uint32_t shaderProgram = 0;
50 uint32_t renderOrientation = 0;
51 uint32_t cameraOrientation = 0;
52 uint32_t worldDetails = 0;
53 uint32_t lightUboId = 0;
54 uint32_t perspColourUboId = 0;
55 uint32_t orthoColourUboId = 0;
59 float fieldOfView = 0.0f;
63 Vec4 clearColour =
Vec4(0.0f, 0.0f, 0.0f, 1.0f);
65 std::unordered_map<std::string, uint32_t> textures;
67 FT_Library library = 0;
68 std::vector<uint8_t> textMemory;
69 std::unordered_map<std::string, FT_Face> fontFaces;
71 Mat4 cameraTransformation =
Mat4(1.0f);
73 bool cameraRotationByMatrix =
false;
75 static void framebufferSizeCallback(GLFWwindow* window,
int width,
78 std::string loadShaderFromFile(
const std::string& fileLocation)
const;
79 uint32_t compileShader(
const std::string& shaderSourceFile,
80 const uint32_t shaderType)
const;
81 std::string getProgramInfoLog(
const uint32_t linkedProgram)
const;
82 std::string getShaderInfoLog(
const uint32_t shader)
const;
84 void checkForOpenGLErrors(
const std::string& when,
const bool abort)
const;
86 void transform(
Model& model,
Vec3& offset,
87 const Mat4& rotation, uint64_t currentPose)
const;
89 uint32_t getTextureHandle(
const std::string& name)
const;
90 uint32_t generateTexture(
const std::string& name,
const uint8_t* data,
91 const unsigned long width,
92 const unsigned long height,
95 void init(
const int width,
const int height,
const std::string& windowTitle,
96 const std::string& shadersPath);
97 void initWindow(
int& width,
int& height,
98 const std::string& windowTitle =
"");
100 void setWorldDetails(
bool perspective);
102 void bindTexture(
const std::string& name);
104 void clearScreen()
const;
106 Renderer(
const std::string& windowTitle,
const int width,
const int height,
107 const float fieldOfView,
const float zNear,
const float zFar,
108 const std::string& shadersPath,
109 const uint32_t objectsPerFrame,
110 const uint32_t objectsPerFrameInc);
114 std::vector<std::tuple< Model*, Vec3, Mat4, Vec4, std::string, bool, uint64_t>> renderList;
116 void renderTuple(std::tuple< Model*, Vec3, Mat4, Vec4, std::string, bool, uint64_t> tuple);
118 GLuint depthMapFramebuffer = 0;
119 GLuint depthMapTexture = 0;
121 const uint32_t depthMapTextureWidth = 2048;
122 const uint32_t depthMapTextureHeight = 2048;
124 bool renderingDepthMap =
false;
128 void captureScreen();
153 void start(
const std::string& windowTitle,
const int width,
const int height,
154 const float fieldOfView,
const float zNear,
const float zFar,
155 const std::string& shadersPath,
156 const uint32_t objectsPerFrame,
157 const uint32_t objectsPerFrameInc);
181 rotate(
Mat4(1.0f), 1.57f,
Vec3(1.0f, 0.0f, 0.0f)) *
182 translate(
Mat4(1.0f),
Vec3(0.0f, -10.0f, 0.0f));
290 const int height = 0,
291 const float fieldOfView = 0.785,
292 const float zNear = 1.0f,
293 const float zFar = 24.0f,
294 const std::string& shadersPath =
296 "resources/shaders/",
298 const uint32_t objectsPerFrame = 200,
299 const uint32_t objectsPerFrameInc = 1000);
316 void generateTexture(
const std::string& name,
const Image& image);
329 void generateTexture(
const std::string& name,
const std::string& text,
331 const int fontSize = 48,
332 const std::string& fontPath =
334 "resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
336 const bool replace =
true);
354 const Vec3& bottomRight);
374 const Vec4& colour,
const std::string& textureName =
"",
375 const uint64_t currentPose = 0,
376 const bool perspective =
true);
388 const std::string& textureName,
const uint64_t currentPose = 0);
408 const Vec4& colour,
const std::string& textureName =
"",
409 const uint64_t currentPose = 0,
410 const bool perspective =
true);
422 const std::string& textureName,
const uint64_t currentPose = 0);
436 void render(
Model& model,
const std::string& textureName,
const uint64_t currentPose = 0,
437 const bool perspective =
true);
450 void render(
Model& model,
const Vec4& colour,
const uint64_t currentPose = 0,
451 const bool perspective =
true);
503 bool screenCapture =
false;
507 void operator=(
Renderer const&) =
delete;
509 void operator=(
Renderer&&) =
delete;
const Mat4 getCameraRotation() const
: Get the rotation of the camera by transformation matrix
Definition: Renderer.cpp:637
4 component vector
Definition: Math.hpp:56
~Renderer()
Destructor.
Definition: Renderer.cpp:663
void swapBuffers()
This is a double buffered system and this command swaps the buffers.
Definition: Renderer.cpp:1141
float shadowSpaceSize
Size of the shadows space (half-edge of the orthographic projection cube)
Definition: Renderer.hpp:175
void setCameraTransformation(const Mat4 &transformation)
: Set the camera by transformation matrix
Definition: Renderer.cpp:626
void start(const std::string &windowTitle, const int width, const int height, const float fieldOfView, const float zNear, const float zFar, const std::string &shadersPath, const uint32_t objectsPerFrame, const uint32_t objectsPerFrameInc)
: Used to re-initialise the Renderer. When Android was supported it was used in apps after they came ...
Definition: Renderer.cpp:574
void rotateCamera(const Vec3 &rotation)
: Modify the rotation of the camera
Definition: Renderer.cpp:614
const Vec3 getCameraOrientation() const
: Get the orientation of the camera
Definition: Renderer.cpp:632
void render(Model &model, const Vec3 &position, const Vec3 &rotation, const Vec4 &colour, const std::string &textureName="", const uint64_t currentPose=0, const bool perspective=true)
Render a Model.
Definition: Renderer.cpp:866
int getScreenHeight()
Get the real screen height.
Definition: Renderer.cpp:55
bool shadowsActive
: Render shadows?
Definition: Renderer.hpp:147
void stop()
: Used to shutdown the renderer. When Android was supported it was used in apps when they lost focus.
Definition: Renderer.cpp:680
A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally...
Definition: Model.hpp:34
Vec3 lightDirection
Vector, indicating the direction of the light in the scene. It points towards a directional light sou...
Definition: Renderer.hpp:169
Mat4 shadowCamTransformation
Shadow camera transformation.
Definition: Renderer.hpp:180
void deleteTexture(const std::string &name)
Deletes the texture indicated by the given name.
Definition: Renderer.cpp:824
GLint origRenderbuffer
: Set to the id of the original renderbuffer, in case it is temporarily replaced during shadow mappin...
Definition: Renderer.hpp:136
Image loading and manipulation.
float lightIntensity
The light intensity (set to -1.0f if no lighting is to be used).
Definition: Renderer.hpp:252
void clearBuffers(Model &model) const
Clear a Model from the GPU buffers (the Model itself remains intact).
Definition: Renderer.cpp:1108
Renderer class (OpenGL 3.3 / OpenGL ES 3.0)
Definition: Renderer.hpp:38
void setBackgroundColour(const Vec4 &colour)
Set the background colour of the screen.
Definition: Renderer.cpp:1135
GLFWwindow * getWindow() const
Get the GLFW window object, associated with the Renderer.
Definition: Renderer.cpp:717
static Renderer & getInstance(const std::string &windowTitle="", const int width=0, const int height=0, const float fieldOfView=0.785, const float zNear=1.0f, const float zFar=24.0f, const std::string &shadersPath="resources/shaders/", const uint32_t objectsPerFrame=200, const uint32_t objectsPerFrameInc=1000)
Get the instance of the Renderer (the Renderer is a singleton).
Definition: Renderer.cpp:648
Definition: BinaryFile.hpp:15
const Vec3 getCameraRotationXYZ() const
: Get the rotation of the camera in x, y, z representation. This will NOT work if the rotation was se...
Definition: Renderer.cpp:641
GLint origFramebuffer
: Set to the id of the original framebuffer, in case it is temporarily replaced during shadow mapping...
Definition: Renderer.hpp:142
void setCameraRotation(const Vec3 &rotation)
: Set the rotation of the camera
Definition: Renderer.cpp:606
An image, loaded from a .png file, which can be used for generating textures.
Definition: Image.hpp:29
Vec3 cameraPosition
The camera position in world space. Ignored for orthographic rendering.
Definition: Renderer.hpp:188
3 component float vector
Definition: Math.hpp:19
void createRectangle(Model &rect, const Vec3 &topLeft, const Vec3 &bottomRight)
Populates a Model object with a rectangle stretching between the given coordinates.
Definition: Renderer.cpp:834
An object on the small3d scene.
int getScreenWidth()
Get the real screen width.
Definition: Renderer.cpp:51
An object that appears on the 3D scene. It is made up of a Model, together with information for posit...
Definition: SceneObject.hpp:38
4x4 float matrix
Definition: Math.hpp:99