Carpenter Engine
A C++ game engine with a build once run anywhere solution
|
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. | |
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.
Engine::Graphics::Renderer::Renderer | ( | const char * | id = "canvas" | ) |
The default constructor.
id | the element id of the html canvas |
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:
mesh | the mesh to draw |
position | the position of the mesh |
scale | the scaling of the mesh |
rotation | the rotation of the mesh in degrees |
void Engine::Graphics::Renderer::SetBackgroundColor | ( | Vec3f | color | ) |
Sets the background color of the canvas.
color | the color to set (RGB) |
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.
camera | the object to use as a camera |
void Engine::Graphics::Renderer::UseMaterial | ( | Material * | material | ) |
Sets the currently loaded material.
Allows a pointer to a material to be used.
material | the material to use |
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.
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 or
GL_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/ColorGL_TEXTURE1
: Normaltexture | the texture to bind |
slot | the slot to bind the texture to. |