Carpenter Engine
A C++ game engine with a build once run anywhere solution
Loading...
Searching...
No Matches
Public Member Functions | List of all members
Engine::Graphics::Renderer Class Reference

a class used to interact with html canvases More...

#include <Renderer.hpp>

Public Member Functions

 Renderer (const char *id="canvas")
 The default constructor.
 
void ClearBuffer ()
 Clears the canvas to the default clear color.
 
void DrawMesh (Mesh *mesh, Vec3f position={0, 0, 0}, Vec3f scale={1, 1, 1}, Vec3f rotation={0, 0, 0})
 Draws a mesh to the canvas.
 
void UseShader (Shader &shader)
 Sets the currently loaded shader.
 
void UseTexture (Texture &texture, unsigned int slot=GL_TEXTURE0)
 Takes the texture and binds it to the specified slot.
 
void UseMaterial (Material *material)
 Sets the currently loaded material.
 
void SetCameraReference (Camera &camera)
 Sets the camera reference.
 
void SetBackgroundColor (Vec3f color)
 Sets the background color of the canvas.
 

Detailed Description

a class used to interact with html canvases

Each canvas has its own unique renderer using OpenGL ES 3.0. This allows us to render unique meshes, textures, and shaders to canvases on the web. If you are trying to render to the main canvas, you can access it using Engine::Game::GetInstance().GetRenderer(), and that will return the main renderer.

Authors
  • Roberto Selles/Henderythmix

Constructor & Destructor Documentation

◆ Renderer()

Engine::Graphics::Renderer::Renderer ( const char *  id = "canvas")

The default constructor.

Parameters
idthe element id of the html canvas

Member Function Documentation

◆ DrawMesh()

void Engine::Graphics::Renderer::DrawMesh ( Mesh *  mesh,
Vec3f  position = {0, 0, 0},
Vec3f  scale = {1, 1, 1},
Vec3f  rotation = {0, 0, 0} 
)

Draws a mesh to the canvas.

Draws a mesh to the canvas with the currently loaded data. The data loaded (but not required) includes:

  • Shaders
  • Uniforms
  • Textures
Parameters
meshthe mesh to draw
positionthe position of the mesh
scalethe scaling of the mesh
rotationthe rotation of the mesh in degrees

◆ SetBackgroundColor()

void Engine::Graphics::Renderer::SetBackgroundColor ( Vec3f  color)

Sets the background color of the canvas.

Parameters
colorthe color to set (RGB)

◆ SetCameraReference()

void Engine::Graphics::Renderer::SetCameraReference ( Engine::Camera camera)

Sets the camera reference.

The goal of this object is to provide a reference to the camera for the renderer. Any game object can be a camera, and all it does is set a reference point to the camera's position and rotation.

Parameters
camerathe object to use as a camera

◆ UseMaterial()

void Engine::Graphics::Renderer::UseMaterial ( Material material)

Sets the currently loaded material.

Allows a pointer to a material to be used.

Parameters
materialthe material to use

◆ UseShader()

void Engine::Graphics::Renderer::UseShader ( Shader shader)

Sets the currently loaded shader.

Call this before drawing a mesh, but you are also suggested to use UseMaterial instead.

◆ UseTexture()

void Engine::Graphics::Renderer::UseTexture ( Texture texture,
unsigned int  slot = GL_TEXTURE0 
)

Takes the texture and binds it to the specified slot.

To bind a texture to the renderer slot, you use the texture you wish to bind, and the slot you wish to bind it to.

By default, the method binds the texture to slot 0 orGL_TEXTURE0`. If you wish to select another slot, please refer to the OpenGL documentation, or here are a few standards the team follows:

  • GL_TEXTURE0: Albedo/Color
  • GL_TEXTURE1: Normal

Example

Engine::Graphics::Texture texture("Assets/placeholder.png");
class TestObject : public Engine::Node {
void Draw() override {
Engine::Game::getInstance().GetRenderer().UseTexture(texture, GL_TEXTURE0);
Engine::Game::getInstance().GetRenderer().DrawMesh(&mesh);
}
};
Graphics::Renderer & GetRenderer()
Definition Game.cpp:65
void UseTexture(Texture &texture, unsigned int slot=GL_TEXTURE0)
Takes the texture and binds it to the specified slot.
Definition Renderer.cpp:149
void DrawMesh(Mesh *mesh, Vec3f position={0, 0, 0}, Vec3f scale={1, 1, 1}, Vec3f rotation={0, 0, 0})
Draws a mesh to the canvas.
Definition Renderer.cpp:69
A wrapper class for a texture for the game engine.
Definition Texture.hpp:35
A single node in a game scene.
Definition Node.hpp:43
Parameters
texturethe texture to bind
slotthe slot to bind the texture to.

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