21#include <unordered_map>
40 uint32_t shaderProgram = 0;
44 uint32_t renderOrientation = 0;
45 uint32_t cameraOrientation = 0;
46 uint32_t worldDetails = 0;
47 uint32_t lightUboId = 0;
48 uint32_t perspColourUboId = 0;
49 uint32_t orthoColourUboId = 0;
53 float fieldOfView = 0.0f;
57 Vec4 clearColour =
Vec4(0.0f, 0.0f, 0.0f, 1.0f);
59 std::unordered_map<std::string, uint32_t> textures;
61 FT_Library library = 0;
62 std::vector<uint8_t> textMemory;
63 std::unordered_map<std::string, FT_Face> fontFaces;
65 Mat4 cameraTransformation =
Mat4(1.0f);
67 bool cameraRotationByMatrix =
false;
69 std::string loadShaderFromFile(
const std::string& fileLocation)
const;
70 uint32_t compileShader(
const std::string& shaderSourceFile,
71 const uint32_t shaderType)
const;
72 std::string getProgramInfoLog(
const uint32_t linkedProgram)
const;
73 std::string getShaderInfoLog(
const uint32_t shader)
const;
75 void checkForOpenGLErrors(
const std::string& when,
const bool abort)
const;
77 void transform(
Model& model,
Vec3& offset,
78 const Mat4& rotation, uint64_t currentPose)
const;
80 uint32_t getTextureHandle(
const std::string& name)
const;
81 uint32_t generateTexture(
const std::string& name,
const uint8_t* data,
82 const unsigned long width,
83 const unsigned long height,
86 void init(
const int width,
const int height,
const std::string& windowTitle,
87 const std::string& shadersPath);
89 void setWorldDetails(
bool perspective);
91 void bindTexture(
const std::string& name);
93 void clearScreen()
const;
95 Renderer(
const std::string& windowTitle,
const int width,
const int height,
96 const float fieldOfView,
const float zNear,
const float zFar,
97 const std::string& shadersPath,
98 const uint32_t objectsPerFrame,
99 const uint32_t objectsPerFrameInc);
103 std::vector<std::tuple< Model*, Vec3, Mat4, Vec4, std::string, bool, uint64_t>> renderList;
105 void renderTuple(std::tuple< Model*, Vec3, Mat4, Vec4, std::string, bool, uint64_t> tuple);
107 GLuint depthMapFramebuffer = 0;
108 GLuint depthMapTexture = 0;
110 const uint32_t depthMapTextureWidth = 2048;
111 const uint32_t depthMapTextureHeight = 2048;
113 bool renderingDepthMap =
false;
117 void captureScreen();
143 void start(
const std::string& windowTitle,
const int width,
const int height,
144 const float fieldOfView,
const float zNear,
const float zFar,
145 const std::string& shadersPath,
146 const uint32_t objectsPerFrame,
147 const uint32_t objectsPerFrameInc);
171 rotate(
Mat4(1.0f), 1.57f,
Vec3(1.0f, 0.0f, 0.0f)) *
172 translate(
Mat4(1.0f),
Vec3(0.0f, -10.0f, 0.0f));
268 const int height = 0,
269 const float fieldOfView = 0.785,
270 const float zNear = 1.0f,
271 const float zFar = 24.0f,
272 const std::string& shadersPath =
274 "resources/shaders/",
276 const uint32_t objectsPerFrame = 200,
277 const uint32_t objectsPerFrameInc = 1000);
289 void generateTexture(
const std::string& name,
const Image& image);
302 void generateTexture(
const std::string& name,
const std::string& text,
304 const int fontSize = 48,
305 const std::string& fontPath =
307 "resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
309 const bool replace =
true);
327 const Vec3& bottomRight);
347 const Vec4& colour,
const std::string& textureName =
"",
348 const uint64_t currentPose = 0,
349 const bool perspective =
true);
361 const std::string& textureName,
const uint64_t currentPose = 0);
381 const Vec4& colour,
const std::string& textureName =
"",
382 const uint64_t currentPose = 0,
383 const bool perspective =
true);
395 const std::string& textureName,
const uint64_t currentPose = 0);
409 void render(
Model& model,
const std::string& textureName,
const uint64_t currentPose = 0,
410 const bool perspective =
true);
423 void render(
Model& model,
const Vec4& colour,
const uint64_t currentPose = 0,
424 const bool perspective =
true);
482 bool screenCapture =
false;
486 void operator=(
Renderer const&) =
delete;
488 void operator=(
Renderer&&) =
delete;
Image loading and manipulation.
Vectors, matrices and other math things.
An object on the small3d scene.
An image, loaded from a .png file, which can be used for generating textures.
Definition Image.hpp:29
A 3D model. It can be loaded from a WavefrontFile or GlbFile. It can also be constructed procedurally...
Definition Model.hpp:34
Renderer class (OpenGL 3.3 / OpenGL ES 3.0)
Definition Renderer.hpp:34
Vec3 cameraPosition
The camera position in world space. Ignored for orthographic rendering.
Definition Renderer.hpp:178
Mat4 shadowCamTransformation
Shadow camera transformation.
Definition Renderer.hpp:170
void stop()
Used to shutdown the renderer. When Android was supported it was used in apps when they lost focus.
Definition Renderer.cpp:576
float lightIntensity
The light intensity (set to -1.0f if no lighting is to be used).
Definition Renderer.hpp:230
const Mat4 getCameraRotation() const
: Get the rotation of the camera by transformation matrix
Definition Renderer.cpp:534
~Renderer()
Destructor.
Definition Renderer.cpp:560
const Vec3 getCameraOrientation() const
: Get the orientation of the camera
Definition Renderer.cpp:529
void setCameraRotation(const Vec3 &rotation)
: Set the rotation of the camera
Definition Renderer.cpp:503
float shadowSpaceSize
Size of the shadows space (half-edge of the orthographic projection cube)
Definition Renderer.hpp:165
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:726
void setCameraTransformation(const Mat4 &transformation)
: Set the camera by transformation matrix
Definition Renderer.cpp:523
void setBackgroundColour(const Vec4 &colour)
Set the background colour of the screen.
Definition Renderer.cpp:1027
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:758
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:538
GLint origFramebuffer
Set to the id of the original framebuffer, in case it is temporarily replaced during shadow mapping.
Definition Renderer.hpp:132
void deleteTexture(const std::string &name)
Deletes the texture indicated by the given name.
Definition Renderer.cpp:716
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 ba...
Definition Renderer.cpp:471
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:545
void clearBuffers(Model &model) const
Clear a Model from the GPU buffers (the Model itself remains intact).
Definition Renderer.cpp:1000
void swapBuffers()
This is a double buffered system and this command swaps the buffers.
Definition Renderer.cpp:1033
void rotateCamera(const Vec3 &rotation)
: Modify the rotation of the camera
Definition Renderer.cpp:511
Vec3 lightDirection
Vector, indicating the direction of the light in the scene. It points towards a directional light sou...
Definition Renderer.hpp:159
GLint origRenderbuffer
Set to the id of the original renderbuffer, in case it is temporarily replaced during shadow mapping.
Definition Renderer.hpp:126
GLFWwindow * getWindow()
Get the GLFW window used by the renderer.
Definition Renderer.cpp:1101
bool shadowsActive
Render shadows?
Definition Renderer.hpp:137
An object that appears on the 3D scene. It is made up of a Model, together with information for posit...
Definition SceneObject.hpp:38
Window management class.
Definition Windowing.hpp:27
Definition BinaryFile.hpp:15
4x4 float matrix
Definition Math.hpp:112
3 component float vector
Definition Math.hpp:21
4 component vector
Definition Math.hpp:68