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

Renderer class (OpenGL 3.3) More...

#include <Renderer.hpp>

Public Member Functions

 ~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 glm::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 glm::vec3 &topLeft, const glm::vec3 &bottomRight)
 Populates a Model object with a rectangle stretching between the given coordinates. More...
 
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. More...
 
void render (Model &model, const glm::vec3 &offset, const glm::vec3 &rotation, const std::string &textureName)
 Render a Model. More...
 
void render (Model &model, const std::string &textureName, const bool perspective=true)
 Render a Model. More...
 
void render (Model &model, const glm::vec4 &colour, const bool perspective=true)
 Render a Model. More...
 
void render (SceneObject &sceneObject, const glm::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 clearScreen () const
 Clears the screen.
 
void clearScreen (const glm::vec4 &colour) const
 Clears the screen. More...
 
void swapBuffers () const
 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 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). More...
 

Public Attributes

glm::vec3 lightDirection
 Vector, indicating the direction of the light in the scene.
 
glm::vec3 cameraPosition
 The camera position in world space.
 
glm::vec3 cameraRotation
 The camera rotation (around the x, y and z axes)
 
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)

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

◆ clearScreen()

void small3d::Renderer::clearScreen ( const glm::vec4 &  colour) const

Clears the screen.

Parameters
colourThe colour with which the screen is to be cleared

◆ createRectangle()

void small3d::Renderer::createRectangle ( Model &  rect,
const glm::vec3 &  topLeft,
const glm::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 glm::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.

◆ getInstance()

Renderer & small3d::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 
)
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
frustumScaleHow much the frustum scales the items rendered
zNearProjection plane z coordinate (use positive value)
zFarFar end of frustum z coordinate (use positive value)
zOffsetFromCameraThe position of the projection plane with regard to the camera.
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.
maxObjectsPerPassIgnored 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.

◆ render() [1/6]

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

Parameters
modelThe model
offsetThe offset (position) where to draw the model (ignored in orthographic rendering)
rotationRotation (x, y, z) (ignored in orthographic rendering)
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.
perspectiveIf true perform perspective rendering, otherwise orthographic.

◆ render() [2/6]

void small3d::Renderer::render ( Model &  model,
const glm::vec3 &  offset,
const glm::vec3 &  rotation,
const std::string &  textureName 
)

Render a Model.

Parameters
modelThe model
offsetThe offset (position) where to draw the model
rotationRotation (x, y, z)
textureNameThe name of the texture to attach to the model. The texture has to have been generated already.

◆ render() [3/6]

void small3d::Renderer::render ( Model &  model,
const std::string &  textureName,
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.
perspectiveTrue = perspective drawing, otherwise orthographic

◆ render() [4/6]

void small3d::Renderer::render ( Model &  model,
const glm::vec4 &  colour,
const bool  perspective = true 
)

Render a Model.

Parameters
modelThe model
colourThe colour of the model
perspectiveTrue = perspective drawing, otherwise orthographic

◆ render() [5/6]

void small3d::Renderer::render ( SceneObject &  sceneObject,
const glm::vec4 &  colour 
)

Render a SceneObject.

Parameters
sceneObjectThe object
colourThe colour the object.

◆ render() [6/6]

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.

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