Skip to content

Objects

TechnologicalTurtle edited this page Jul 20, 2026 · 10 revisions

Objects

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

Initialization

There are 8 constructors you can use to create LibGui::Object, but they are very similar and differ in only few parameters. Only irreversible parameter is shape, which is generated by one of shape generator functions.

// the 'normal' one, you will use most
LibGui::Object(const Vec2 position, const Vec2 scale, const Color color, const LibGui::Shapes::Shape& shape, const int UniformFlags = 0);
// example
LibGui::Object MyObject({250, 250}, {200, 200}, Color::Red, LibGui::Shapes::Rectangle());

// variant of previous, where instead of color you can pass texture on object
// this variant is also for every next constructor, but the concept is same so I won't list it.
LibGui::Object(const Vec2 position, const Vec2 scale, LibGui::Texture& texture, const LibGui::Shapes::Shape& shape, const int UniformFlags = 0);

// here you can also set a window, if you have more of them
LibGui::Object(const Vec2 position, const Vec2 scale, const Color color, const LibGui::Shapes::Shape& shape, LibGui::Window& window, const int UniformFlags = 0);

// use custom shader
LibGui::Object(const Vec2 position, const Vec2 scale, const Color color, const LibGui::Shapes::Shape& shape, LibGui::Shader& shader, const int UniformFlags = 0);

// combination of last two constructors
LibGui::Object(const Vec2 position, const Vec2 scale, const Color color, const LibGui::Shapes::Shape& shape, LibGui::Window& window, LibGui::Shader& shader, const int UniformFlags = 0);

Properties

Property Type 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}
Color color coefficient for all objects vertex colors
float direction rotation of object in degrees
char UniformFlags has it's own page here
Shader& shader is reference to a Shader object, this object will be used for rendering
LibGui::Texture* 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