The small3d library
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
small3d::Renderer Class Reference

Renderer class (OpenGL 3.3 / OpenGL ES 3.0) More...

#include <Renderer.hpp>

Public Member Functions

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 back into focus.
 
void stop ()
 : Used to shutdown the renderer. When Android was supported it was used in apps when they lost focus.
 
void setCameraRotation (const Vec3 &rotation)
 : Set the rotation of the camera More...
 
void rotateCamera (const Vec3 &rotation)
 : Modify the rotation of the camera More...
 
void setCameraTransformation (const Mat4 &transformation)
 : Set the camera by transformation matrix More...
 
const Vec3 getCameraOrientation () const
 : Get the orientation of the camera More...
 
const Mat4 getCameraRotation () const
 : Get the rotation of the camera by transformation matrix More...
 
const Vec3 getCameraRotationXYZ () const
 : Get the rotation of the camera in x, y, z representation. This will NOT work if the rotation was set via the setRotation(Mat4) function. More...
 
int getScreenWidth ()
 Get the real screen width. More...
 
int getScreenHeight ()
 Get the real screen height. More...
 
 ~Renderer ()
 Destructor.
 
GLFWwindow * getWindow () const
 Get the GLFW window object, associated with the Renderer.
 
void generateTexture (const std::string &name, const Image &image)
 Generate a texture on the GPU from the given image. More...
 
void generateTexture (const std::string &name, const std::string &text, const Vec3 &colour, const int fontSize=48, const std::string &fontPath="resources/fonts/CrusoeText/CrusoeText-Regular.ttf", const bool replace=true)
 Generate a texture on the GPU that contains the given text. More...
 
void deleteTexture (const std::string &name)
 Deletes the texture indicated by the given name. More...
 
void createRectangle (Model &rect, const Vec3 &topLeft, const Vec3 &bottomRight)
 Populates a Model object with a rectangle stretching between the given coordinates. More...
 
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. More...
 
void render (Model &model, const Vec3 &position, const Vec3 &rotation, const std::string &textureName, const uint64_t currentPose=0)
 Render a Model. More...
 
void render (Model &model, const Vec3 &position, const Mat4 &rotation, const Vec4 &colour, const std::string &textureName="", const uint64_t currentPose=0, const bool perspective=true)
 Render a Model. More...
 
void render (Model &model, const Vec3 &position, const Mat4 &rotation, const std::string &textureName, const uint64_t currentPose=0)
 Render a Model. More...
 
void render (Model &model, const std::string &textureName, const uint64_t currentPose=0, const bool perspective=true)
 Render a Model. More...
 
void render (Model &model, const Vec4 &colour, const uint64_t currentPose=0, const bool perspective=true)
 Render a Model. More...
 
void render (SceneObject &sceneObject, const Vec4 &colour)
 Render a SceneObject. More...
 
void render (SceneObject &sceneObject, const std::string &textureName)
 Render a SceneObject. More...
 
void clearBuffers (Model &model) const
 Clear a Model from the GPU buffers (the Model itself remains intact). More...
 
void clearBuffers (SceneObject &sceneObject) const
 Clear a SceneObject (multiple models) from the GPU buffers (the SceneObject itself remains intact). More...
 
void setBackgroundColour (const Vec4 &colour)
 Set the background colour of the screen. More...
 
void swapBuffers ()
 This is a double buffered system and this command swaps the buffers.
 
 Renderer (Renderer const &)=delete
 
void operator= (Renderer const &)=delete
 
 Renderer (Renderer &&)=delete
 
void operator= (Renderer &&)=delete
 

Static Public Member Functions

static RenderergetInstance (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). More...
 

Public Attributes

GLint origRenderbuffer = 0
 : Set to the id of the original renderbuffer, in case it is temporarily replaced during shadow mapping.
 
GLint origFramebuffer = 0
 : Set to the id of the original framebuffer, in case it is temporarily replaced during shadow mapping.
 
bool shadowsActive = false
 : Render shadows?
 
Vec3 lightDirection = Vec3(0.0f, 0.7f, 0.3f)
 Vector, indicating the direction of the light in the scene. It points towards a directional light source.
 
float shadowSpaceSize = 20.0f
 Size of the shadows space (half-edge of the orthographic projection cube)
 
Mat4 shadowCamTransformation
 Shadow camera transformation. More...
 
Vec3 cameraPosition = Vec3(0, 0, 0)
 The camera position in world space. Ignored for orthographic rendering.
 
float lightIntensity = 1.0f
 The light intensity (set to -1.0f if no lighting is to be used).
 

Detailed Description

Renderer class (OpenGL 3.3 / OpenGL ES 3.0)

Member Function Documentation

◆ clearBuffers() [1/2]

void small3d::Renderer::clearBuffers ( Model model) const

Clear a Model from the GPU buffers (the Model itself remains intact).

Parameters
modelThe model

◆ clearBuffers() [2/2]

void small3d::Renderer::clearBuffers ( SceneObject sceneObject) const

Clear a SceneObject (multiple models) from the GPU buffers (the SceneObject itself remains intact).

Parameters
sceneObjectThe scene object

◆ createRectangle()

void small3d::Renderer::createRectangle ( Model rect,
const Vec3 topLeft,
const Vec3 bottomRight 
)

Populates a Model object with a rectangle stretching between the given coordinates.

Parameters
rectModel object in which the rectangle data will be entered
topLeftTop left corner of the rectangle
bottomRightBottom right corner of the rectangle

◆ deleteTexture()

void small3d::Renderer::deleteTexture ( const std::string &  name)

Deletes the texture indicated by the given name.

Parameters
nameThe name of the texture.

◆ generateTexture() [1/2]

void small3d::Renderer::generateTexture ( const std::string &  name,
const Image image 
)

Generate a texture on the GPU from the given image.

Parameters
nameThe name by which the texture will be known
imageThe image from which the texture will be generated

◆ generateTexture() [2/2]

void small3d::Renderer::generateTexture ( const std::string &  name,
const std::string &  text,
const Vec3 colour,
const int  fontSize = 48,
const std::string &  fontPath = "resources/fonts/CrusoeText/CrusoeText-Regular.ttf",
const bool  replace = true 
)

Generate a texture on the GPU that contains the given text.

Parameters
nameThe name by which the texture will be known
textThe text that will be contained in the texture
colourThe colour of the text
fontSizeThe size of the font which will be used
fontPathPath to the TrueType font (.ttf) which will be used
replaceIf true, an exception will be thrown if a texture with the same name already exists. Otherwise it will be overwritten.

◆ getCameraOrientation()

const Vec3 small3d::Renderer::getCameraOrientation ( ) const

: Get the orientation of the camera

Returns
The orientation of the camera

◆ getCameraRotation()

const Mat4 small3d::Renderer::getCameraRotation ( ) const

: Get the rotation of the camera by transformation matrix

Returns
The camera tranformation matrix (this is inversed when rendering)

◆ getCameraRotationXYZ()

const Vec3 small3d::Renderer::getCameraRotationXYZ ( ) const

: Get the rotation of the camera in x, y, z representation. This will NOT work if the rotation was set via the setRotation(Mat4) function.

Returns
The rotation in x, y, z representation (this is negated when rendering)

◆ getInstance()

Renderer & small3d::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 
)
static

Get the instance of the Renderer (the Renderer is a singleton).

Parameters
windowTitleThe title of the game's window
widthThe width of the window. If width and height are not set or set to 0, the game will run in full screen mode.
heightThe height of the window
fieldOfViewField of view in radians (angle between the top and the bottom plane
zNearProjection plane z coordinate (use positive value)
zFarFar end of frustum z coordinate (use positive value)
shadersPathThe path where the shaders will be stored, relative to the application's executing directory. It defaults to the path provided by the engine, but it can be changed, so as to accommodate for executables which are going to be using it. Even though the path to the folder can be changed, the folder structure within it and the names of the shaders must remain as provided. The shader code can be changed, provided that their inputs and outputs are maintained the same.
objectsPerFrameIgnored parameter (used for compatibility with Vulkan edition).
objectsPerFrameIncIgnored parameter (used for compatibility with Vulkan edition).
Returns
The Renderer object. It can only be assigned to a pointer by its address (Renderer *r = &Renderer::getInstance(...), since declaring another Renderer variable and assigning to it would invoke the default constructor, which has been deleted.

◆ getScreenHeight()

int small3d::Renderer::getScreenHeight ( )

Get the real screen height.

Returns
The screen height

◆ getScreenWidth()

int small3d::Renderer::getScreenWidth ( )

Get the real screen width.

Returns
The screen width

◆ render() [1/8]

void small3d::Renderer::render ( Model model,
const std::string &  textureName,
const uint64_t  currentPose = 0,
const bool  perspective = true 
)

Render a Model.

Parameters
modelThe model
textureNameThe name of the texture to attach to the model. The texture has to have been generated already.
currentPoseThe current animation pose
perspectiveTrue = perspective drawing, otherwise orthographic If false, the depth buffer is cleared. Do not intermingle perspective and orthographic rendering. Perform all the orthographic rendering in the end.

◆ render() [2/8]

void small3d::Renderer::render ( Model model,
const Vec3 position,
const Mat4 rotation,
const std::string &  textureName,
const uint64_t  currentPose = 0 
)

Render a Model.

Parameters
modelThe model
positionThe position of the model (x, y, z)
rotationRotation transformation matrix
textureNameThe name of the texture to attach to the model. The texture has to have been generated already.
currentPoseThe current animation pose

◆ render() [3/8]

void small3d::Renderer::render ( Model model,
const Vec3 position,
const Mat4 rotation,
const Vec4 colour,
const std::string &  textureName = "",
const uint64_t  currentPose = 0,
const bool  perspective = true 
)

Render a Model.

Parameters
modelThe model
positionThe position of the model (x, y, z)
rotationRotation transformation matrix
colourThe colour of the model
textureNameThe name of the texture to attach to the model (optional). The texture has to have been generated already. If this is set, the colour parameter will be ignored.
currentPoseThe current animation pose
perspectiveIf true perform perspective rendering, otherwise orthographic. If false, the depth buffer is cleared. Do not intermingle perspective and orthographic rendering. Perform all the orthographic rendering in the end.

◆ render() [4/8]

void small3d::Renderer::render ( Model model,
const Vec3 position,
const Vec3 rotation,
const std::string &  textureName,
const uint64_t  currentPose = 0 
)

Render a Model.

Parameters
modelThe model
positionThe position of the model (x, y, z)
rotationRotation (x, y, z)
textureNameThe name of the texture to attach to the model. The texture has to have been generated already.
currentPoseThe current animation pose

◆ render() [5/8]

void small3d::Renderer::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.

Parameters
modelThe model
positionThe position of the model (x, y, z)
rotationRotation (x, y, z)
colourThe colour of the model
textureNameThe name of the texture to attach to the model (optional). The texture has to have been generated already. If this is set, the colour parameter will be ignored.
currentPoseThe current animation pose
perspectiveIf true perform perspective rendering, otherwise orthographic. If false, the depth buffer is cleared. Do not intermingle perspective and orthographic rendering. Perform all the orthographic rendering in the end.

◆ render() [6/8]

void small3d::Renderer::render ( Model model,
const Vec4 colour,
const uint64_t  currentPose = 0,
const bool  perspective = true 
)

Render a Model.

Parameters
modelThe model
colourThe colour of the model
currentPoseThe current animation pose
perspectiveTrue = perspective drawing, otherwise orthographic If false, the depth buffer is cleared. Do not intermingle perspective and orthographic rendering. Perform all the orthographic rendering in the end.

◆ render() [7/8]

void small3d::Renderer::render ( SceneObject sceneObject,
const std::string &  textureName 
)

Render a SceneObject.

Parameters
sceneObjectThe object
textureNameThe name of the texture to attach to the object. The texture has to have been generated already.

◆ render() [8/8]

void small3d::Renderer::render ( SceneObject sceneObject,
const Vec4 colour 
)

Render a SceneObject.

Parameters
sceneObjectThe object
colourThe colour the object.

◆ rotateCamera()

void small3d::Renderer::rotateCamera ( const Vec3 rotation)

: Modify the rotation of the camera

Parameters
rotationThe rotation to modify by (x, y, z)

◆ setBackgroundColour()

void small3d::Renderer::setBackgroundColour ( const Vec4 colour)

Set the background colour of the screen.

Parameters
colourThe background colour

◆ setCameraRotation()

void small3d::Renderer::setCameraRotation ( const Vec3 rotation)

: Set the rotation of the camera

Parameters
rotationThe rotation (x, y, z)

◆ setCameraTransformation()

void small3d::Renderer::setCameraTransformation ( const Mat4 transformation)

: Set the camera by transformation matrix

Parameters
transformationThe tranformation matrix

Member Data Documentation

◆ shadowCamTransformation

Mat4 small3d::Renderer::shadowCamTransformation
Initial value:
=
rotate(Mat4(1.0f), 1.57f, Vec3(1.0f, 0.0f, 0.0f)) *
translate(Mat4(1.0f), Vec3(0.0f, -10.0f, 0.0f))

Shadow camera transformation.


The documentation for this class was generated from the following files: