-
Notifications
You must be signed in to change notification settings - Fork 0
Objects
Class LibGui::Object is for simple objects made up from vertexes.
There are 8 constructors (+1 bonus) 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);As I mentioned above, there is one bonus constructor, it's very different from others as it's used to copy LibGui::Objects. It has to be like this because OpenGL remembers data in so-called buffers, when you initialize object LibGui generates new buffers and gets their IDs, on destruction it deletes those buffers, so when you copy LibGui::Object with default copy constructor, c++ just copies buffer IDs and not actual buffers, thats ok until you delete on of those objects, these buffers get deleted and the copy suddenly has no data.
This custom constructor copies the original object, but generates new copy buffers, so when you delete original, the copy's ok. Just remember that is operation is kinda expensive so don't do it too often and prefer using references, if possible.
| 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 |
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).
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.
Sets vao to object's vertex array object id, vbo to vertex buffer object id and ebo to element buffer object id.
Features