Skip to content

Objects

TechnologicalTurtle edited this page Jul 14, 2026 · 10 revisions

Objects

Class LibGui::Object is for simple objects made up from vertexes.

Creation

Normal initialization looks just like this:

LibGui::Object MyObject();

But you can actually pass which window to render on (the initialization window on default) and which shader to use:

// render on MyWindow using default shader
LibGui::Object MyObject(MyWindow);

// render on initialization window using shader MyShader
LibGui::Object MyObject(MyShader);

// render on MyWindow using shader MyShader
LibGui::Object MyObject(MyWindow, MyShader);

Then you just call one of Initialization functions to set it up:

InitAsCustomPolygon()

// init with custom vertex data
void InitAsCustomPolygon(const std::vector<Vertex>& Vertices);
// for example
MyObject.InitAsCustomPolygon({ // btw-vertex position should be from -1 to 1 for scaling to be in pixels
      Vertex{Vec2{ 0.0f,  0.0f},   Color::Red},
      Vertex{Vec2{ 0.0f, -1.0f},   Color::Green},
      Vertex{Vec2{-1.0f,  0.0f},   Color::Blue}
});

InitAsCustom()

// init with entierly custom data (indices are order of vertices to be drawn in)
void InitAsCustom(const std::vector<Vertex>& Vertices, const std::vector<unsigned int>& Indices);
MyObject.InitAsCustomPolygon({ // btw-vertex position should be from -1 to 1 for scaling to be in pixels
      Vertex{Vec2{ 0.0f,  0.0f},   Color::Red},
      Vertex{Vec2{ 0.0f, -1.0f},   Color::Green},
      Vertex{Vec2{-1.0f,  0.0f},   Color::Blue}
}, {0, 1, 2});

InitAsRectangle()

// init as rectangle with solid color (anchor means where is center of rectangle)
void InitAsRectangle(Vec2 position, Vec2 size, Color Color, Vec2 anchor = Vec2{ 0.5f, 0.5f });
// for example
MyObject.InitAsRectangle({100, 100}, {200, 200}, Color::Blue);

InitAsRectangle()

// init as rectangle with LibGui::Texture (anchor means where is center of rectangle)
void InitAsRectangle(Vec2 position, Vec2 size, Texture& tex, Vec2 anchor = Vec2{ 0.5f, 0.5f });
// for example
LibGui::Texture MyTurtleTexture("CoolTurtle.png");
MyObject.InitAsRectangle({100, 100}, {200, 200}, MyTurtleTexture);

InitAsRegularPolygon()

// init as regular polygon (I... I just don't know what to put here...)
void InitAsRegularPolygon(Vec2 position, int verticesCount, int radius, Color Color);
// for example
MyObject.InitAsRegularPolygon({300, 200}, 5, 100, Color::Red);

InitAsLineStrip()

// init as line between vector of points
void InitAsLineStrip(const std::vector<Vertex>& points);
// for example
MyObject.InitAsLineStrip({
      {0, 0},
      {100, 100},
      {200, 0}
});

InitAsLineStrip()

// init as line between vector of points with certain color
void InitAsLineStrip(const std::vector<Vec2>& points, Color Color);
// for example
MyObject.InitAsLineStrip({
      {0, 0},
      {100, 100},
      {200, 0}
}, Color::Green);

Properties

Property Description
Vec2 pos position of object in pixels or (from -1 to 1) based on UniformFlags
Vec2 scale object vertex position multiplier, so if you put vertex of LibGui::Object on position {0, 1} and set scale to {5, 53.5}, it will end up on {0, 53.5}
Vec2 color coefficient for all objects vertex colors
float direction rotation of object in degrees
char UniformFlags has it's own page here
Vec2& shader is reference to a LibGui::Shader object, this object will be used for rendering
Vec2* texture pointer to texture of this object, if nullptr, no texture is used

Rendering

Use LibGui::Object::Render(...) to render objects, this will send uniforms like scale or position to GPU, then render, if you want to send those uniforms yourself (for example, if you have custom shader) set custom_uniSetup to true like LibGui::Object::Render(true).

UniformFlags

Theese tell the uniform setup function how to translate position, scale and how to render it. On default these are set to
|Render as polygon|read scale y in pixels|read scale x in pixels|read position y in pixels|read position x in pixels
but you can change it like this:

// create flags with normalized x position and x scale
char myFlags = UniformFlag_XPos_Normalized | UniformFlag_XScale_Normalized;


MyObject.UniFlags = myFlags;
MyObject.pos = {0.5f, 200.0f};
MyObject.scale = {1, 100};

The pixel coordinate system is inspired by raylib's one, it's in pixels and {0, 0} is in upper left corner.
To read more about normalized coordinates go here, press Ctrl+F and serach NDC.

Clone this wiki locally