ST_engine
0.3-ALPHA
|
The renderer for the engine. More...
Classes | |
class | texture |
Functions | |
void | set_draw_color (uint8_t, uint8_t, uint8_t, uint8_t) |
void | clear_screen (SDL_Color color) |
void | clear_screen () |
void | present () |
void | draw_background (uint16_t arg) |
void | draw_background_parallax (uint16_t arg, uint16_t offset) |
void | draw_overlay (uint16_t arg, uint8_t sprite, uint8_t sprite_num) |
void | draw_texture (uint16_t arg, int32_t x, int32_t y) |
void | draw_texture_scaled (uint16_t arg, int32_t x, int32_t y, float scale_x, float scale_y) |
void | draw_rectangle (int32_t x, int32_t y, int32_t w, int32_t h, SDL_Color color) |
void | draw_rectangle_filled (int32_t x, int32_t y, int32_t w, int32_t h, SDL_Color color) |
void | draw_sprite (uint16_t arg, int32_t x, int32_t y, uint8_t sprite, uint8_t animation, uint8_t animation_num, uint8_t sprite_num) |
void | draw_sprite_scaled (uint16_t arg, int32_t x, int32_t y, uint8_t sprite, uint8_t animation, uint8_t animation_num, uint8_t sprite_num, float scale_x, float scale_y) |
uint16_t | draw_text_cached_glyphs (uint16_t font, const std::string &text, int x, int y, SDL_Color color_font) |
uint16_t | draw_text_lru_cached (uint16_t font, const std::string &arg2, int x, int y, SDL_Color color_font) |
void | upload_surfaces (ska::bytell_hash_map< uint16_t, SDL_Surface * > *surfaces) |
void | upload_fonts (ska::bytell_hash_map< uint16_t, TTF_Font * > *fonts) |
void | vsync_on () |
void | vsync_off () |
int8_t | initialize (SDL_Window *win, int16_t width, int16_t height) |
void | close () |
void | set_resolution (int16_t r_width, int16_t r_height) |
void | cache_font (TTF_Font *Font, uint16_t font_and_size) |
void | process_surfaces (std::vector< std::pair< uint16_t, SDL_Surface * >> &surfaces_pairs) |
The renderer for the engine.
A LRU Cache that caches rendered strings, it is used in the drawTextNormal() method of the renderer class.
This renderer is based entirely on the SDL2 renderer and uses it, along with some helper methods and rendering techniques to draw textures, text and primitives to the screen.
Caches textures and the string, font+size used to render them.
void ST::renderer_sdl::cache_font | ( | TTF_Font * | Font, |
uint16_t | font_and_size | ||
) |
Caches all glyphs of a font at a given size. Works with the draw_text_cached method. Do not confuse this method with the font_cache class, they have nothing in common, this caches fonts to be used with ASCII strings, font_cache is a LRU cache that works with any string.
Font | The Font to render with. |
font_and_size | The name+size of the font. |
Definition at line 361 of file renderer_sdl.cpp.
void ST::renderer_sdl::clear_screen | ( | ) |
Clears the screen with the color set by set_draw_color
Definition at line 616 of file renderer_sdl.cpp.
void ST::renderer_sdl::clear_screen | ( | SDL_Color | color | ) |
Clears the screen given a color
Definition at line 607 of file renderer_sdl.cpp.
void ST::renderer_sdl::close | ( | ) |
Closes the renderer. Deletes all textures and fonts.
Definition at line 95 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_background | ( | uint16_t | arg | ) |
Draws a texture that fills the entire screen (Background).
arg | The hash of the texture name. |
Definition at line 502 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_background_parallax | ( | uint16_t | arg, |
uint16_t | offset | ||
) |
arg | The hash of the name of the texture. |
offset | The offset in the texture for the parallax effect |
Definition at line 515 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_overlay | ( | uint16_t | arg, |
uint8_t | sprite, | ||
uint8_t | sprite_num | ||
) |
Draws an animated overlay. Works similarly to draw_sprite, except only one animation is supported.
arg | The hash of the texture name. |
sprite | The number of the sprite to use. |
sprite_num | The total number of frames this spritesheet has. |
Definition at line 594 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_rectangle | ( | int32_t | x, |
int32_t | y, | ||
int32_t | w, | ||
int32_t | h, | ||
SDL_Color | color | ||
) |
Draws a rectangle on the screen.
x | The X position to draw at. |
y | The Y position to draw at. |
w | The width of the rectangle. |
h | The height of the rectangle. |
color | The color of the rectangle. |
Definition at line 491 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_rectangle_filled | ( | int32_t | x, |
int32_t | y, | ||
int32_t | w, | ||
int32_t | h, | ||
SDL_Color | color | ||
) |
Draws a filled rectangle on the screen.
x | The X position to draw at. |
y | The Y position to draw at. |
w | The width of the rectangle. |
h | The height of the rectangle. |
color | The color of the rectangle. |
Definition at line 476 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_sprite | ( | uint16_t | arg, |
int32_t | x, | ||
int32_t | y, | ||
uint8_t | sprite, | ||
uint8_t | animation, | ||
uint8_t | animation_num, | ||
uint8_t | sprite_num | ||
) |
Draws a texture that is a spritesheet.
arg | The hash of the name of the spritesheet. |
x | The X position to render at. |
y | The Y position to render at. |
sprite | The number of the sprite in the texture. (Column in the spritesheet). |
animation | The number of the animation in the texture (Row in the spritesheet). |
animation_num | The total number of animations in a spritesheet (Rows in the spritesheet). |
sprite_num | The total number of sprites in a spritesheet. (Columns in a spritesheet). |
Definition at line 544 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_sprite_scaled | ( | uint16_t | arg, |
int32_t | x, | ||
int32_t | y, | ||
uint8_t | sprite, | ||
uint8_t | animation, | ||
uint8_t | animation_num, | ||
uint8_t | sprite_num, | ||
float | scale_x, | ||
float | scale_y | ||
) |
Draws a texture that is a spritesheet.
arg | The hash of the name of the spritesheet. |
x | The X position to render at. |
y | The Y position to render at. |
sprite | The number of the sprite in the texture. (Column in the spritesheet). |
animation | The number of the animation in the texture (Row in the spritesheet). |
animation_num | The total number of animations in a spritesheet (Rows in the spritesheet). |
sprite_num | The total number of sprites in a spritesheet. (Columns in a spritesheet). |
Definition at line 569 of file renderer_sdl.cpp.
uint16_t ST::renderer_sdl::draw_text_cached_glyphs | ( | uint16_t | font, |
const std::string & | text, | ||
int | x, | ||
int | y, | ||
SDL_Color | color_font | ||
) |
This will draw text using cached glyphs - the fastest way possible, works only with ASCII and relatively simple fonts (any complex cursive fonts won't be rendered properly).
arg | The font to render with. |
text | The text to render. |
x | The x position to render at. |
y | The y position to render at. |
color_font | The color to render with. |
size | The size of the font to render at. |
Note that the font must previously be loaded at the selected size.
Definition at line 175 of file renderer_sdl.cpp.
uint16_t ST::renderer_sdl::draw_text_lru_cached | ( | uint16_t | font, |
const std::string & | arg2, | ||
int | x, | ||
int | y, | ||
SDL_Color | color_font | ||
) |
Text rendering method for non-ASCII text – works with cyrillic, expanded Latin (Spanish, German, etc..) and I guess all of UTF8
arg | The font to render with. |
arg2 | The text to render. |
x | The x position to render at. |
y | The y position to render at. |
color_font | The color to render with. |
size | The size of the font to render at. |
Note that the font must previously be loaded at the selected size.
Definition at line 136 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_texture | ( | uint16_t | arg, |
int32_t | x, | ||
int32_t | y | ||
) |
Draw a texture at a given position.
arg | The hash of the texture name. |
x | The X position to render at. |
y | The Y position to render at. |
Definition at line 438 of file renderer_sdl.cpp.
void ST::renderer_sdl::draw_texture_scaled | ( | uint16_t | arg, |
int32_t | x, | ||
int32_t | y, | ||
float | scale_x, | ||
float | scale_y | ||
) |
Draw a texture at a given position and scale it.
arg | The hash of the texture name. |
x | The X position to render at. |
y | The Y position to render at. |
Definition at line 454 of file renderer_sdl.cpp.
int8_t ST::renderer_sdl::initialize | ( | SDL_Window * | r_window, |
int16_t | r_width, | ||
int16_t | r_height | ||
) |
Initializes the renderer.
window | The window to bind this renderer to. |
width | The virtual width of the window. |
height | The virtual height of the window. |
Definition at line 66 of file renderer_sdl.cpp.
void ST::renderer_sdl::present | ( | ) |
Presents the framebuffer to the window.
Definition at line 634 of file renderer_sdl.cpp.
void ST::renderer_sdl::process_surfaces | ( | std::vector< std::pair< uint16_t, SDL_Surface * >> & | surfaces_pairs | ) |
Iterates over all surfaces, adding them to texture atlases if they have dimensions that are a power of 2. If a surfaces how non POW2 dimensions, a separate texture is created for it. If the atlas becomes full, this function is called recursively with the remaining textures.
surfaces_pairs | Surfaces to process. |
Definition at line 236 of file renderer_sdl.cpp.
void ST::renderer_sdl::set_draw_color | ( | uint8_t | r, |
uint8_t | g, | ||
uint8_t | b, | ||
uint8_t | a | ||
) |
Sets a draw color.
r | Red value. |
g | Green value. |
b | Blue value. |
a | Alpha value. |
Definition at line 627 of file renderer_sdl.cpp.
void ST::renderer_sdl::set_resolution | ( | int16_t | r_width, |
int16_t | r_height | ||
) |
Sets the internal rendering resolution
r_width | Width |
r_height | Height |
Definition at line 643 of file renderer_sdl.cpp.
void ST::renderer_sdl::upload_fonts | ( | ska::bytell_hash_map< uint16_t, TTF_Font * > * | fonts_t | ) |
Upload fonts to the GPU. (save and cache their glyphs).
Definition at line 324 of file renderer_sdl.cpp.
void ST::renderer_sdl::upload_surfaces | ( | ska::bytell_hash_map< uint16_t, SDL_Surface * > * | surfaces | ) |
Upload all surface to the GPU. (Create textures from them).
surfaces | The surfaces to upload. |
Definition at line 202 of file renderer_sdl.cpp.
void ST::renderer_sdl::vsync_off | ( | ) |
Turns off vsync.
Definition at line 418 of file renderer_sdl.cpp.
void ST::renderer_sdl::vsync_on | ( | ) |
Turns on vsync.
Definition at line 403 of file renderer_sdl.cpp.