Ember
A C++ 20 'game engine' built with SDL3 with wide platform support.
Public Member Functions | List of all members
OpenglRenderer Class Referencefinal

Opengl Renderer implementation. More...

#include <ember_gl.h>

Inheritance diagram for OpenglRenderer:
Renderer

Public Member Functions

 OpenglRenderer ()
 
 ~OpenglRenderer () override
 
void setup_shaders (Shader *default_shader, Shader *framebuffer_shader)
 
void initialize () override
 Initialize the renderer and its resources. More...
 
void resize_viewport (int view_width, int view_height) override
 Resize the rendering context. More...
 
void set_context (const void *ctx) override
 Set the platform-specific rendering context. More...
 
void * get_context () override
 Get the platform-specific rendering context. More...
 
void destroy () override
 Destroy rendering resources. More...
 
std::shared_ptr< Textureload_texture (const std::string &file_path) override
 Load a texture from disk. More...
 
std::shared_ptr< Textureget_texture (const std::string &path) override
 Get a previously loaded texture. More...
 
bool load_font (const std::string &file_path, const std::string &font_alias, int font_size) override
 Load a font. More...
 
void set_default_font (const std::string &font_name) override
 Set the current font to use for rendering. More...
 
void unload_font (const Font &font) override
 Unload a loaded font. More...
 
void unload_texture (Uint32 id) override
 Unload a texture by its ID. More...
 
void draw_texture (const Texture *texture, const Rect2 &dest_rect, float rotation, const glm::vec4 &color, const Rect2 &src_rect, int z_index, bool flip_h, bool flip_v, const UberShader &uber_shader) override
 Draw a textured quad. More...
 
void draw_rect (Rect2 rect, float rotation, const glm::vec4 &color, bool filled, int z_index) override
 Draw a rectangle (filled or outlined). More...
 
void draw_text (const std::string &text, float x, float y, float rotation, float scale, const glm::vec4 &color, const std::string &font_alias, int z_index, const UberShader &uber_shader, int ft_size) override
 Draw text to screen. More...
 
void draw_line (float x1, float y1, float x2, float y2, float width, float rotation, const glm::vec4 &color, int z_index) override
 Draw a line. More...
 
void draw_triangle (float x1, float y1, float x2, float y2, float x3, float y3, float rotation, const glm::vec4 &color, bool filled, int z_index) override
 Draw a triangle. More...
 
void draw_circle (float center_x, float center_y, float rotation, float radius, const glm::vec4 &color, bool filled, int segments, int z_index) override
 Draw a circle. More...
 
void draw_polygon (const std::vector< glm::vec2 > &points, float rotation, const glm::vec4 &color, bool filled, int z_index) override
 Draw a polygon. More...
 
void flush () override
 Submit all batched draw calls. More...
 
void present () override
 Swap buffers to present the rendered frame. More...
 
void clear (glm::vec4 color) override
 Clear the screen to the given color. More...
 
Uint32 get_framebuffer_texture () const override
 
- Public Member Functions inherited from Renderer
virtual ~Renderer ()=default
 
void set_view_matrix (const glm::mat4 &view_matrix=glm::mat4(1.f))
 
glm::mat4 get_view_matrix () const
 
virtual HashMap< std::string, std::shared_ptr< Texture > > & get_loaded_textures ()
 
virtual std::vector< std::string > & get_loaded_fonts_name ()
 

Additional Inherited Members

- Public Attributes inherited from Renderer
int Viewport [2] = {800, 600}
 Viewport size. More...
 
SDL_Window * Window = nullptr
 SDL Window. More...
 
Backend Type = Backend::GL_COMPATIBILITY
 Default Type of renderer. More...
 
- Protected Member Functions inherited from Renderer
glm::vec2 rotate_point (const glm::vec2 &point, const glm::vec2 &center, float radians)
 Rotate a point around a center point. More...
 
Recti calc_display ()
 Calculate the display rectangle for rendering based on the viewport and window size. More...
 
void submit (const BatchKey &key, float x, float y, float w, float h, float u0, float v0, float u1, float v1, const glm::vec4 &color, float rotation=0.0f, bool is_filled=true)
 Add a quad (textured or untextured) to the appropriate batch. More...
 
- Protected Attributes inherited from Renderer
HashMap< BatchKey, Batch_batches
 All batches by key. More...
 
FT_Library _ft = {}
 FreeType library instance. More...
 
HashMap< std::string, Fontfonts
 Loaded fonts. More...
 
std::string current_font_name
 Currently selected font alias. More...
 
glm::mat4 _projection = glm::mat4(1.f)
 Projection matrix. More...
 
glm::mat4 _view = glm::mat4(1.f)
 View matrix. More...
 
HashMap< std::string, std::shared_ptr< Texture > > _textures
 Cached textures. More...
 
HashMap< Uint32, glm::vec2 > _texture_sizes
 HACK_FIX: Cached texture sizes by ID. More...
 

Detailed Description

Opengl Renderer implementation.

Constructor & Destructor Documentation

◆ OpenglRenderer()

OpenglRenderer::OpenglRenderer ( )

◆ ~OpenglRenderer()

OpenglRenderer::~OpenglRenderer ( )
overridedefault

Member Function Documentation

◆ clear()

void OpenglRenderer::clear ( glm::vec4  color)
overridevirtual

Clear the screen to the given color.

Parameters
colorColor to clear the screen with (default is black).

Implements Renderer.

◆ destroy()

void OpenglRenderer::destroy ( )
overridevirtual

Destroy rendering resources.

Implements Renderer.

◆ draw_circle()

void OpenglRenderer::draw_circle ( float  center_x,
float  center_y,
float  rotation,
float  radius,
const glm::vec4 &  color,
bool  filled,
int  segments,
int  z_index 
)
overridevirtual

Draw a circle.

Implements Renderer.

◆ draw_line()

void OpenglRenderer::draw_line ( float  x1,
float  y1,
float  x2,
float  y2,
float  thickness,
float  rotation,
const glm::vec4 &  color,
int  z_index 
)
overridevirtual

Draw a line.

Implements Renderer.

◆ draw_polygon()

void OpenglRenderer::draw_polygon ( const std::vector< glm::vec2 > &  points,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
overridevirtual

Draw a polygon.

Implements Renderer.

◆ draw_rect()

void OpenglRenderer::draw_rect ( Rect2  rect,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
overridevirtual

Draw a rectangle (filled or outlined).

Implements Renderer.

◆ draw_text()

void OpenglRenderer::draw_text ( const std::string &  text,
float  x,
float  y,
float  rotation,
float  scale,
const glm::vec4 &  color,
const std::string &  font_alias,
int  z_index,
const UberShader uber_shader,
int  ft_size 
)
overridevirtual

Draw text to screen.

Implements Renderer.

◆ draw_texture()

void OpenglRenderer::draw_texture ( const Texture texture,
const Rect2 dest_rect,
float  rotation,
const glm::vec4 &  color,
const Rect2 src_rect,
int  z_index,
bool  flip_h,
bool  flip_v,
const UberShader uber_shader 
)
overridevirtual

Draw a textured quad.

Implements Renderer.

◆ draw_triangle()

void OpenglRenderer::draw_triangle ( float  x1,
float  y1,
float  x2,
float  y2,
float  x3,
float  y3,
float  rotation,
const glm::vec4 &  color,
bool  filled,
int  z_index 
)
overridevirtual

Draw a triangle.

Implements Renderer.

◆ flush()

void OpenglRenderer::flush ( )
overridevirtual

Submit all batched draw calls.

Implements Renderer.

◆ get_context()

void * OpenglRenderer::get_context ( )
overridevirtual

Get the platform-specific rendering context.

Implements Renderer.

◆ get_framebuffer_texture()

Uint32 OpenglRenderer::get_framebuffer_texture ( ) const
inlineoverridevirtual

Reimplemented from Renderer.

◆ get_texture()

std::shared_ptr< Texture > OpenglRenderer::get_texture ( const std::string &  path)
overridevirtual

Get a previously loaded texture.

Parameters
pathPath or alias of the texture.
Returns
Reference to the Texture.

Implements Renderer.

◆ initialize()

void OpenglRenderer::initialize ( )
overridevirtual

Initialize the renderer and its resources.

Implements Renderer.

◆ load_font()

bool OpenglRenderer::load_font ( const std::string &  font_path,
const std::string &  font_alias,
int  font_size 
)
overridevirtual

Load a font.

Parameters
font_pathPath to TTF file.
font_aliasAlias name to refer to this font.
font_sizeSize of font in pixels.
Returns
true if loaded successfully.

Implements Renderer.

◆ load_texture()

std::shared_ptr< Texture > OpenglRenderer::load_texture ( const std::string &  path)
overridevirtual

Load a texture from disk.

Parameters
pathPath to image file.
Returns
Reference to the loaded Texture.

Implements Renderer.

◆ present()

void OpenglRenderer::present ( )
overridevirtual

Swap buffers to present the rendered frame.

This function is called to display the rendered content on the screen.

Implements Renderer.

◆ resize_viewport()

void OpenglRenderer::resize_viewport ( int  view_width,
int  view_height 
)
overridevirtual

Resize the rendering context.

Parameters
view_widthWidth of the view.
view_heightHeight of the view.

Implements Renderer.

◆ set_context()

void OpenglRenderer::set_context ( const void *  ctx)
overridevirtual

Set the platform-specific rendering context.

Implements Renderer.

◆ set_default_font()

void OpenglRenderer::set_default_font ( const std::string &  font_name)
overridevirtual

Set the current font to use for rendering.

Parameters
font_nameAlias of the font to use.

Implements Renderer.

◆ setup_shaders()

void OpenglRenderer::setup_shaders ( Shader default_shader,
Shader framebuffer_shader 
)

◆ unload_font()

void OpenglRenderer::unload_font ( const Font font)
overridevirtual

Unload a loaded font.

Implements Renderer.

◆ unload_texture()

void OpenglRenderer::unload_texture ( Uint32  id)
overridevirtual

Unload a texture by its ID.

Implements Renderer.


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