The small3d library
|
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 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). 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). | |
Renderer class (OpenGL 3.3 / OpenGL ES 3.0)
void small3d::Renderer::clearBuffers | ( | Model & | model | ) | const |
void small3d::Renderer::clearBuffers | ( | SceneObject & | sceneObject | ) | const |
Clear a SceneObject (multiple models) from the GPU buffers (the SceneObject itself remains intact).
sceneObject | The scene object |
void small3d::Renderer::deleteTexture | ( | const std::string & | name | ) |
Deletes the texture indicated by the given name.
name | The name of the texture. |
void small3d::Renderer::generateTexture | ( | const std::string & | name, |
const Image & | image | ||
) |
Generate a texture on the GPU from the given image.
name | The name by which the texture will be known |
image | The image from which the texture will be generated |
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.
name | The name by which the texture will be known |
text | The text that will be contained in the texture |
colour | The colour of the text |
fontSize | The size of the font which will be used |
fontPath | Path to the TrueType font (.ttf) which will be used |
replace | If true, an exception will be thrown if a texture with the same name already exists. Otherwise it will be overwritten. |
const Vec3 small3d::Renderer::getCameraOrientation | ( | ) | const |
: Get the orientation of the camera
const Mat4 small3d::Renderer::getCameraRotation | ( | ) | const |
: Get the rotation of the camera by transformation matrix
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.
|
static |
Get the instance of the Renderer (the Renderer is a singleton).
windowTitle | The title of the game's window |
width | The width of the window. If width and height are not set or set to 0, the game will run in full screen mode. |
height | The height of the window |
fieldOfView | Field of view in radians (angle between the top and the bottom plane |
zNear | Projection plane z coordinate (use positive value) |
zFar | Far end of frustum z coordinate (use positive value) |
shadersPath | The 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. |
objectsPerFrame | Ignored parameter (used for compatibility with Vulkan edition). |
objectsPerFrameInc | Ignored parameter (used for compatibility with Vulkan edition). |
int small3d::Renderer::getScreenHeight | ( | ) |
Get the real screen height.
int small3d::Renderer::getScreenWidth | ( | ) |
Get the real screen width.
void small3d::Renderer::render | ( | Model & | model, |
const std::string & | textureName, | ||
const uint64_t | currentPose = 0 , |
||
const bool | perspective = true |
||
) |
Render a Model.
model | The model |
textureName | The name of the texture to attach to the model. The texture has to have been generated already. |
currentPose | The current animation pose |
perspective | True = 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. |
void small3d::Renderer::render | ( | Model & | model, |
const Vec3 & | position, | ||
const Mat4 & | rotation, | ||
const std::string & | textureName, | ||
const uint64_t | currentPose = 0 |
||
) |
Render a Model.
model | The model |
position | The position of the model (x, y, z) |
rotation | Rotation transformation matrix |
textureName | The name of the texture to attach to the model. The texture has to have been generated already. |
currentPose | The current animation pose |
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.
model | The model |
position | The position of the model (x, y, z) |
rotation | Rotation transformation matrix |
colour | The colour of the model |
textureName | The 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. |
currentPose | The current animation pose |
perspective | If 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. |
void small3d::Renderer::render | ( | Model & | model, |
const Vec3 & | position, | ||
const Vec3 & | rotation, | ||
const std::string & | textureName, | ||
const uint64_t | currentPose = 0 |
||
) |
Render a Model.
model | The model |
position | The position of the model (x, y, z) |
rotation | Rotation (x, y, z) |
textureName | The name of the texture to attach to the model. The texture has to have been generated already. |
currentPose | The current animation pose |
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.
model | The model |
position | The position of the model (x, y, z) |
rotation | Rotation (x, y, z) |
colour | The colour of the model |
textureName | The 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. |
currentPose | The current animation pose |
perspective | If 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. |
void small3d::Renderer::render | ( | Model & | model, |
const Vec4 & | colour, | ||
const uint64_t | currentPose = 0 , |
||
const bool | perspective = true |
||
) |
Render a Model.
model | The model |
colour | The colour of the model |
currentPose | The current animation pose |
perspective | True = 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. |
void small3d::Renderer::render | ( | SceneObject & | sceneObject, |
const std::string & | textureName | ||
) |
Render a SceneObject.
sceneObject | The object |
textureName | The name of the texture to attach to the object. The texture has to have been generated already. |
void small3d::Renderer::render | ( | SceneObject & | sceneObject, |
const Vec4 & | colour | ||
) |
Render a SceneObject.
sceneObject | The object |
colour | The colour the object. |
void small3d::Renderer::rotateCamera | ( | const Vec3 & | rotation | ) |
: Modify the rotation of the camera
rotation | The rotation to modify by (x, y, z) |
void small3d::Renderer::setBackgroundColour | ( | const Vec4 & | colour | ) |
Set the background colour of the screen.
colour | The background colour |
void small3d::Renderer::setCameraRotation | ( | const Vec3 & | rotation | ) |
: Set the rotation of the camera
rotation | The rotation (x, y, z) |
void small3d::Renderer::setCameraTransformation | ( | const Mat4 & | transformation | ) |
: Set the camera by transformation matrix
transformation | The tranformation matrix |
Mat4 small3d::Renderer::shadowCamTransformation |
Shadow camera transformation.