LibGame  v0.4.0
The LG Game Engine - Copyright (C) 2024 ETMSoftware
lg_opengl_2d.c File Reference

Functions

int lg_init_renderer_2d ()
 
void lg_free_renderer_2d ()
 
int lg_render_line_2d (int x1, int y1, int x2, int y2, LG_Color_u color)
 
int lg_render_rect_2d (Rec2Di r, LG_Color_u color)
 
int lg_render_tex_2d (const LG_Texture *tex, const Rec2Di *src, const Rec2Di *dest)
 

Detailed Description

LG_Renderer2D structs and funcs for OpenGL 2D rendering

Originally a replacement for SDL 2D accelerated rendering.

Specifically deal with rendering of 2D lines, 2D rectangles, and 2D textures.

Use specific matrices/shaders.

Function Documentation

◆ lg_init_renderer_2d()

int lg_init_renderer_2d ( )

Initialize the 2D renderer

Call lg_init_line_renderer_2d(), lg_init_rect_renderer_2d() and lg_init_tex_renderer_2d()

Returns
LG_OK if OK

◆ lg_free_renderer_2d()

void lg_free_renderer_2d ( )

Call lg_free_line_renderer_2d(), lg_free_rect_renderer_2d(), and lg_free_tex_renderer_2d()

◆ lg_render_line_2d()

int lg_render_line_2d ( int  x1,
int  y1,
int  x2,
int  y2,
LG_Color_u  color 
)

Expect SDL coord sys for input (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

Parameters
x1
y1
x2
y2
colorA LG_Color_u
Returns
LG_OK if OK

◆ lg_render_rect_2d()

int lg_render_rect_2d ( Rec2Di  r,
LG_Color_u  color 
)

Render a filled rect

Expect SDL coord sys for input (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

Parameters
rA Rec2Di
colorA LG_Color_u
Returns
LG_OK if OK

◆ lg_render_tex_2d()

int lg_render_tex_2d ( const LG_Texture tex,
const Rec2Di src,
const Rec2Di dest 
)

Replace: int SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *srcrect, const SDL_Rect *dstrect)

Expect SDL coord sys for input (logical coords, ie inside [0 -> env->top_win_logical_w] x [0 -> env->top_win_logical_h])

  • If NULL, src is the entire texture
  • If NULL, dest is the entire rendering target (the texture will be stretched to fill the given rectangle)
Parameters
texA LG_Texture
srcA Rec2Di
destA Rec2Di
Returns
LG_OK if OK