render

The render namespace contains all the functions you need put simple shapes on screen, get various information about the system & more!

Declaration:

namespace render
{

    // empty rectangle
    void add_rect(vec2_t pos, vec2_t size, color_t color, float rounding = 0.f);
    
    // outlined empty rectangle
    void add_rect_outlined(vec2_t pos, vec2_t size, color_t color, float rounding = 0.f);
    
    // filled rectangle
    void add_rect_filled(vec2_t pos, vec2_t size, color_t color, float rounding = 0.f);
    
    // empty circle
    void add_circle(vec2_t pos, color_t color, float radius);
    
    // filled circle
    void add_circle_filled(vec2_t pos, color_t color, float radius);
    
    // text using a built-in font
    void add_text(vec2_t pos, string text, color_t color, int font);
    
    // text using a custom font
    void add_text(vec2_t pos, string text, color_t color, font_t@ font);
    
    // outlined text using a built-in font
    void add_text_shadowed(vec2_t pos, string text, color_t color, int font);
    
    // outlined text using a custom font
    void add_text_shadowed(vec2_t pos, string text, color_t color, font_t@ font);
    
    // create a custom font from a path
    font_t@ create_font(string file_name, float size);
    
    // turn a world position into a screen position
    // will return vec2_t(-1.f, -1.f) if they are off-screen
    vec2_t to_screen(vec3_t pos);
    
    // get the cursor position
    vec2_t get_cursor_pos();
    
    // get the last clicked position
    vec2_t get_click_pos();
    
    // get the display size (WIDTH, HEIGHT)
    vec2_t get_display_size();
    
    // get the current delta-time between frames
    float get_delta_time();
    
    // get the current time
    double get_time();
    
    // bounds check
    bool area_contains(vec2_t pos, vec2_t size, vec2_t test_pos);
    
    // checks whether "key" is pressed, google "windows virtual keycodes" for more info
    bool get_key_state(int key);

}

Information:

All of the "add_xxx" functions can only be called inside of a "render" callback, if you attempt to call them outside of this callback you will receive an error. "create_font" should only be called once at the start of your script to prevent issues.

Examples:

Drawing a red circle at the world origin

auto world_origin = vec3_t(0.f, 0.f, 0.f);

void render()
{

    auto world_screen = render::to_screen(world_origin);

    // check if the world origin is on screen
    // if so, draw a red circle
    if (world_screen.x > 0.f && world_screen.y > 0.f)
        render::add_circle(world_screen, { 255, 0, 0, 255 }, 12.f);

}

Last updated