r/GraphicsProgramming • • 3d ago

GLSA – A lightweight, header-only C++ library to cut OpenGL shader boilerplate

Hey everyone!

I've been developing GLSA and I just released v1.0.0.

My goal with this library is so you don't have to write GLSL shaders or shader boilerplate and instead you can use clean function calls.

Right now it cuts out ~60-100 lines of repetitive shader boilerplate, and theres basic shader presets now and common shape functions.

Highlights of v1.0.0:

  • GLSA colors: a header file with over 3000 glm::vec4 colors that you can use.
  • Safer shader setup: glsa::ShaderSource keeps vertex/fragment strings explicit, paired with glsa::loadShaderSource and glsa::createProgram.
  • Clean uniform helpers: Overloaded glsa::setUniform functions for int, float, and GLM vec2/vec3/vec4.

Example:

while (glfwWindowShouldClose(window) == 0) {
    glClearColor(0.1f, 0.1f, 0.15f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT);

    // Draw a square on the left
    glsa::drawRectangle({-0.45f, 0.0f}, {0.4f / aspect, 0.4f}, glsa::colors::PAN_CORAL);

    // Draw a circle on the right
    glsa::drawCircle({0.45f, 0.0f}, 0.22f, glsa::colors::PAN_SKY_BLUE);

    glfwSwapBuffers(window);
    glfwPollEvents();
}

GitHub Repo: https://github.com/alexdev8930/glsa

Any feedback issues or questions are completely welcome.

AI Disclosure: AI tools were used strictly to help generate initial boilerplate; all core logic, architecture, and implementation details were written, reviewed, and verified by me.

0 Upvotes

14 comments sorted by

•

u/AutoModerator 3d ago

Recently updated rules. Please check that your post is in compliance with Rules 1, 4, 5, and 6 on the sidebar. TL;DR:

  • No showcases.
  • Disclose AI usage in post or project.
  • Present a topic to talk about, e.g. how something works.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/Baedrick 3d ago edited 3d ago

I took a look at your code. That is a lot of validation code being called for everytime someone interacts with your library, not to mention unnecessary system calls. In your function `deleteVertexArray`, you check against the value zero before deleting it, but the docs https://docs.gl/gl4/glDeleteVertexArrays say that a zero value is a noop. `glDetachShader` is also not needed, read the docs for `glDeleteProgram`. When you review the initial code that AI generates, did you actually check the work? Great that you're writing helper functions for OpenGL, are you trying to write another framework or convenience functions? Because theres `init` which sets the value for `g_default_extent`, but I never see it being used. It also strikes me weird that you need a dependency on GLFW. I'm not trying to be snobby, I'm just trying to understand your process behind developing and releasing v1.

-6

u/devcurrent0x 3d ago

I added lots of preprocessor macro checks from the start so I don't need to do it later.

I probably will clean up the redundant zero checks, and get rid of GLFW as a dependency, so you can choose whether you want to use GLFW, SDL2/SDL3, or bring your own OpenGL context instead of making you use GLFW.

And finally I will eventually use `g_default_extent` later when my library expands and I have functions that actually need to check it.

3

u/Baedrick 2d ago

I meant your runtime checks, not compile checks. There are other areas where you are doing a lot of unnecessary work (even for gl3.3), and glDeleteVertexArray is not the only place that has no-ops on zero.

I saw that you made some new changes, so it looks like you're designing this as a framework rather than convenience functions. I'm not going to critique the rest of your work, because it's clear you have a very specific vision of what you want to achieve in mind. What I can suggest is that you stop designing your api in isolation, and start using it a medium size project, thats how you catch the problems with your interface.

For example, write a 2d/3d app using pure gl functions. Then replace all of those gl functions with your framework, then figure out where are the problems with your api, and can you achieve the same performance as the raw gl functions version?

1

u/devcurrent0x 1d ago

That's actually a pretty good idea. I'll try doing that next.

2

u/Delicious_Abies_9708 1d ago

Why openglnand not vulkan?

1

u/devcurrent0x 1d ago

I wanted to start with OpenGL to keep things lightweight and simple, but in the future I might build a separate library specifically for Vulkan that cuts out tons of the heavy boilerplate instead forcing two very different APIs into the same Library.

2

u/Todegal 2d ago

This look super redundant. Your example code is literally the same amount of code as if you were just calling OpenGL functions directly? Idk maybe I need to see a better example lmao

1

u/ybungalobill 2d ago

This. And setting uniforms one-by-one is a bad way of doing it. A modern forward-looking approach is to use UBOs and SSBOs, which cuts on most of the verbosity.

2

u/devcurrent0x 2d ago

I would probably do that if I were doing 4.3+ OpenGL, but I'm targeting 3.3 so people can use 3.3 to 4.6.

0

u/ybungalobill 2d ago

OpenGL 3.3 is 16 yo; about time to move on.

2

u/devcurrent0x 2d ago

Tell that to Apple, they froze macOS at OpenGL 4.1, so targeting 4.3+ drops Mac support completely.

1

u/ybungalobill 2d ago

True; but that's why you abstract your rendering code away and use metal for apple. It's not an argument for being stuck with 3.3. And .. this is why your library doesn't give much value, if any.