Skip to content

Objects

TechnologicalTurtle edited this page Jul 13, 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

  • pos is position of object in pixels/from -1 to 1 based on UniformFlags
  • scale is 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}
  • color gets multplied with all objects vertex colors
  • direction is rotation of object in degrees
  • UniformFlags have it's own page UniformFlags
  • shader is reference to a LibGui::Shader object, this objject will use for rendering
  • texture is 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).

Clone this wiki locally