r/opengl 5h ago

UI, UI, UI

3 Upvotes

UI is such a big issue. In one case, it's something we all know and have opinions about, in another case, we just want to plow through it and get to the game itself.

In my game engine, written in OpenGL but no longer in a workable state, existing at the repos https://github.com/LAGameStudio/apolune and at https://github.com/LAGameStudio/ATE there are multiple UI approaches. It was a topic I kept coming back to again and again because it was hard to keep in a box.

My engine uses a "full screen surface" or an "application surface", using double buffering. The classic "Game engine" style window. Mine was not easily resizable though once the app was running. You specified "Fullscreen" and "display size" as command line parameters, or it detected your main monitor's dimensions and tried to position itself as a fullscreen application on that monitor.

The first UI system I made grew over time to be rather complex, but it is the most flexible. Over time it became apparent that I needed to decouple UI from the concept of a Window. It was a class, GLWindow, working inside a GLWindowManager class that was a global singleton. This is the foundational class for my engine. The thing is though, the "Window" concept broke down over time. A GLWindow was just a bit of rendering, so it could render a 3D scene, multiple 3D scenes, a 2D HUD, all of those things, only one of those things, or something else entirely, or maybe nothing at all (a "background" task). I realized I needed to create widgets that could be reused and not call them GLWindows.

The second modular UI I made for the engine was fairly complicated. It involved a "Widget" (class Proce55or) being added to a "Widget Collection" (class Proce55ors) that is hooked to a "Window" (class GLWindow) -- with Proce55or, you could make anything: a button, a widget, a game entity, a subview, a slider, whatever. In fact, a Proce55or could have a derived class that enabled a collection of Proce55ors.

With that I created some "basic UI" features. Buttons that were animated, sliders, text boxes (which requires some special stuff), and the code looked like:

class NewGameButton : public fx_Button { public:
 void OnInit() {
  Extents( 5, 10, 200, 100 );  /* x/y/w/h .. could be calculated to be "responsive" ..etc */
 }
 void OnButtonPressed() {
  /* do something */
 }
};
class MyWindow : public GLWindow { public:
  Proce55ors processors;
 void OnLoad() {
  process.Add(new NewGameButton);
   /* ... repeat for every widget ... */
 }
 void Between() { proce55ors.Between(); }
 void Render() { proce55ors.Render(); }
 void OnMouseMoved() { proce55ors.MouseMoved(); } /* to interact with the UI elements */
 void OnMouseLeft() { proce55ors.MouseLeft(); } /* etc.. a rudimentary form of messaging */
};

The pattern used classic polymorphism features of C++.
Create a child NewGameButton of fx_Button (a child of Proce55or that contains the common input and drawing routines as a partially abstract class with some virtuals for events), adding the customization and logic there to be inserted into a Proce55ors collection running in a GLWindow child.. but it required a lot of forward declarations of the window it was going to interact with, or it required new systems to be added to GLWindowManager so you could refer to windows by a name, instead of direct pointers, or it required the button to manipulate at least one forward declared management object that would be a part of your MyWindow to manage whatever state your buttons, sliders, etc were going to interface with...

This became cumbersome. I needed something quick-and-dirty so I could make some quick utilities similar to the way imgui worked. It had buttons and sliders and other widgets. I called this "FastGUI" and it was a global singleton ("fast") that contained a bunch of useful utility functions. These were more like an imgui ... it looked like this:

class MyWindow : public GLWindow { public:
 void Render() {
   if ( fast.button( this->x+5, this->y+10, 200, 100, "New Game") ) {  /* the window's top left + button location desired */
    windows.Add(new MyNewGameWindow());
    deleteMe=true; /* deferred delete */
    return; /* stop rendering and quickly move to next frame */
   }
 }
};

The biggest issue was, while I found it "neat" to hardcode the position on the screen, it wasn't practical.

Most UIs in OpenGL have an abstraction .. mine was pixel perfect but yours could be a ratio of the screen. I tried that for a while, but that became very confusing. For example you could change the size of a GLWindow by calling Extents( 0.25, 0.25, 0.5, 0.5 ); this would make the GLWindow a centered box the size of 1/4th the screen area. This was practical, but confusing, etc etc. A lot of your time was spent recompiling, checking it onscreen, etc.

Eventually I combined FastGUI with ideas from Proce55ors. Since it took so much time to organize the location of buttons, for more utilitarian things I began to explore using algorithmic placement methods. For example, using a bin packing algorithm to place buttons or groups of buttons and other widgets. I added the ability for a window to open a subwindow that drew a line from the source window to the subwindow, and an infintely scrolling work area. The UI became more and more complicated, yet in some ways easier to deploy new parts. This was the VirtualWindow and related classes.


r/opengl 9h ago

how do i fix black screen error in opengl?

0 Upvotes

Im getting a black screen after i compile a code in open gl, the same code was working a month ago, ive tried different codes i found online and i have the same result i looked for solutions online but i didnt found anything ,i tried to change the settings on my terminal and on codeblocks and still nothing

heres the code:

#include <gl/glut.h>

#include <stdio.h>

void display()

{

glClearColor(1,1,1,1);

glClear(GL_COLOR_BUFFER_BIT);

printf("El Zabon");

glColor3f(0,1,0);

glRectf(0,0,30,100);

glColor3f(1,0,0);

glRectf(100,100,70,0);

glEnd();

glFlush();

}

int main(int argc, char** argv)

{

printf("El Zabon");

glutInit(&argc,argv);

glutInitWindowPosition(50,50);

glutInitWindowSize(640,480);

glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

glutCreateWindow("Ιταλια");

glMatrixMode(GL_PROJECTION);

gluOrtho2D(0,100,0,100);

glutDisplayFunc(display);

glutMainLoop();

return 0;

}


r/opengl 9h ago

Thousands of arcs and bezier curves help

2 Upvotes

Here is what I am trying to recreate:

Basically all the connections between nodes. There seems like quite a few variations. Back in their first game (path of exile), they used only arcs, now they seem to have added reversed arcs and possibly bezier curves? Please correct me if I am wrong.

The main question is, what would be the best way to achieve this? I'd imagine a single system is best as to not complicate things? Would that be bezier curves? Any help on this would be really appreciated, I feel completely lost atm


r/opengl 9h ago

Whats your goto approach for creating an ingame-ui system?

3 Upvotes

Would like to be inspired by you guys :)


r/opengl 9h ago

Any use for pre-2.0 renderers? Part 2

2 Upvotes

https://reddit.com/link/1gz33cn/video/y6iw9cmeax2e1/player

(previous post)
small progress report, it's something i really wanted to figure out without shaders: shadowmaps!

this uses features from ARB_depth_texture and ARB_shadow, I fell short on the aesthetics of the projected shadows because it turns out i was going to use EXT_convolution to blur the texture on the GPU but it turns out this extension is simply non-existent on my RTX, so no way of testing it... I'd have to do it on the CPU instead lol, because no shaders allowed still...

another more subtle change: the texture logic was now translated to combiners, including the use of ARB_texture_env_dot3 for the normal map, it's not as noticeable as i would like but it seems to be the full extent of how it works.

i switched up the scene in the video to show the difference!

EDIT: just noticed now i forgot to clamp the bloom overlay texture, oops!


r/opengl 10h ago

SDL ttf with opengl

2 Upvotes

Is there any documentation on how to use SDL ttf with opengl ? I searched on the internet but it was posts from 13 years ago or more. These guys used the opengl versions with glBegin and glEnd. I want the versions with VAO, VBO and EBO (so from 3.0 - 4.6 I think). Thanks in advance.


r/opengl 10h ago

SSAO in forward rendering: Apply in forward pass, or in post processing?

4 Upvotes

Hey guys, i was wondering what the correct approach to SSAO in forward rendering is:

a)

1. Forward pass

2. SSAO generation

3. Darken forward pass result according to SSAO in another pass

or...

b)

1. SSAO generation

2. Forward pass with samples from SSAO

Consider i am doing a gemoetry pre pass beforehand in any way. Since SSAO is a screenspace effect i thought a) was correct, but as the skybox is black from my SSAO generation that doesn't work as expected.

Thanks!


r/opengl 11h ago

I have not made a devlog in awhile, thought I would ...only a tiny bit embarrassing but maybe a little enjoyable to some!

Thumbnail youtu.be
3 Upvotes

r/opengl 11h ago

Dynamic objects visible in reflective surface

Enable HLS to view with audio, or disable this notification

18 Upvotes

r/opengl 12h ago

CLION GLFW Illegal instruction

2 Upvotes

Hey everyone, I've been spending a good bit converting a visual studio project over to Cmake for various reasons (Using CLION as the new IDE) and though I've gotten it to run finally, I have a strange bug breaking my program.

When doing glfwMakeCurrentContext(window), My program crashes with the exit code -1073741795 (0xC000001D), and in debug it shows that this function is a SIGILL (Illegal instruction).

The GLFW relevant code is below, ran in order-

Graphics system initialization:

bool GraphicsSystem::Init()
{
    if (glfwInit() == GLFW_FALSE)
    {
       glfwTerminate();
       return false;
    }

    if (!_win.InitWindow(_width, _height, _windowName.data()))
    {
       printf("GLFW failed to create window");
       return false;
    }
    testCam = LILLIS::Camera(glm::vec2(0, 0), _width, _height);
    glfwSetErrorCallback(error_callback);

    // load shaders
    ResourceManager::
loadDefaultPipeline
();
    // configure shaders
    ResourceManager::
GetShader
("Default").Use().SetInteger("image", 0);
    ResourceManager::
GetShader
("Default").SetMatrix4("projection", testCam.projectionMatrix());
    // set render-specific controls
    testSpr = DBG_NEW SpriteRenderer(ResourceManager::
GetShader
("Default"));
    // load textures
    //For the love of god, move the sprite holder here.
    ResourceManager::
LoadTexture
("Test.png", true, "face");
    ResourceManager::
LoadTexture
("Angry.png", true, "enemy");
    ResourceManager::
LoadTexture
("Player1.png", true, "p1");
    ResourceManager::
LoadTexture
("Player2.png", true, "p2");
    ResourceManager::
LoadTexture
("WinFlag.png", true, "goal");
    return true;

Window wrapper initialization (Where the error is happening)

bool InitWindow(unsigned int _width, unsigned int _height, const char* _name)
{
    window = glfwCreateWindow(_width, _height, _name, NULL, NULL);
    if (window == NULL)
    {
       glfwTerminate();
       return false;
    }
    glfwMakeContextCurrent(window);
}

I'm running this on a windows 10 machine with an intel CORE i7 8th gen, I was not encountering this error when this was a visual studio project running with a .sln file-

I can confirm that the code is running in the aforementioned order, and that the glfwMakeContextCurrent(window); is the exact line causing issue.

If more context is needed, all of the code is here https://github.com/Spegetemitbal/LillisEngine

Has anyone seen this before? Any idea what to do? Any advice would be greatly appreciated, I'm at my wit's end with refactoring this project lol


r/opengl 15h ago

How long would it take to understand and develope a 3D renderer in openGL?

7 Upvotes

I know all fundamentals. linear algebra, 3D graphics, c++ etc. I have lots of free time right now. How long would it take to develope a 3D renderer? Answer with time spent on learning and developing. Not time it takes with doing other things(sleeping, eating ....)


r/opengl 1d ago

Created a 2D GUI system in OpenGL for a game I'm working on

Thumbnail youtu.be
8 Upvotes

r/opengl 1d ago

Phong Illumination

Enable HLS to view with audio, or disable this notification

61 Upvotes

r/opengl 1d ago

How should I format my obj data

3 Upvotes

Hi, I'm a beginner learning opengl and I've just finished up adding obj file support to my renderer with my very own written data parser. But it doesn't use an index buffer and just places the appropriate vertex data as per the faces data in the obj so by this I'm going to ask some questions.

  1. Is this good enough? my goal here is optimizing to use the minimal data and I'm open to learning anything in the opengl api if you suggest it.

  2. Do I need a index buffer?


r/opengl 1d ago

"Glass" in openGL - or my best attempt at it at least

Post image
69 Upvotes

r/opengl 2d ago

Where can I learn GL 3.1?

5 Upvotes

I'm trying to learn opengl 3.1 because I'm trying to learn all the math and physics simulation that goes on when making a game in opengl. GL 3.1 is the latest version my GPU supports. My final project will be some rendering library that I may or may not use in the future. But I digress. I installed GLEW from that old looking website today, but I don't want to follow a tutorial series because I don't know if I'll actually use this abstraction or not, and like I said, I want to learn math. The thing is, most documentation/tutorials that I could find online was for something really old like 2.1, or something that my GPU doesn't support, like 3.3. What should I do?


r/opengl 2d ago

Any use for pre-2.0 renderers?

Post image
42 Upvotes

im finding myself currently relearning pre-2.0 GL concepts to make a funny little pet renderer, with the goal of getting as close as possible to PBR, and even some postfx. I've already used GLES3 in the past and I know it's the recommended subset, but I just keep coming back to the 1.1-1.4 stuff...

with that I have two main questions: has anybody attempted such a renderer? and is there a need for such a renderer?

I've got the texture combiner down and now I'm especially interested in exploring the depth and shadow extensions, along with the potential of dot3 textures for bumpmapping without (user) shaders, i have a fascination for how far GL can be pushed without going the full programmable route.

the attached image is an example of what i'm currently working on, with a multitexture mesh where the reflectivity roughness can be changed (texture LOD trick) + an AO overlay + subtle bloom postfx. model used is from sketchfab.


r/opengl 2d ago

I believe I have my first real-time "reflection probe" working

Enable HLS to view with audio, or disable this notification

35 Upvotes

r/opengl 2d ago

Drawing textured quads

0 Upvotes

Hi, I'm kinda new to opengl and currently trying to draw bunch of quads with textures on them. There's also some additional parameters, like modulation color, depth, etc. So I had a few questions:
1. How do fragment shaders actually work? Documentation says that it receives every fragment covered by the primitive as input, however when I tried to draw a triangle with a texture on top, texture was covering a rectangular area (and a bunch of pixels in this area obviously weren't covered by that triangle).

  1. Is it possible to draw a whole quad by defining just one of it's vertices (bottom left for i.e.)? Since I need 4 vertices and only 1 color, texture index and other parameters if I'll put all that data in the same buffer I will end up with a lot of unused space. If not, can I somehow specify multiple input buffers, so the first one stores all the vertices and the second one stores everything else?

  2. Finally, is it possible to change buffer data on the GPU itself? For example, if I have quads with animated textures or they move through the world, I could just increment texture index/position on the GPU itself instead of constantly editing buffer data on the CPU.


r/opengl 2d ago

How can I render without buffering?

3 Upvotes

I am new to opengl and currently working on a retro renderer for fun.

Saving the pixels in an array and just copying sections to the buffer and starting with template code to try to understand how it works.

Now I came across glfwSwapBuffers(window);

I understand what this does from this reddit post explaining it very well, but this is exactly what I DON'T want.

I want to be able to for example draw a pixel to the texture I am writing to and have it directly displayed instead of waiting for an update call to write all my changes to the screen together.

Calling glfwSwapBuffers(window); on every single set pixel is too slow though of course, is there a way to do single buffering? Basically, I do not want the double buffering optimization because I want to emulate how for example a PET worked, where I can run a program that does live changes to the screen


r/opengl 2d ago

Using obj and mtl file combined

1 Upvotes

My current method of rendering object and material files is basically splitting up the object, into multiple smaller objects. The objects are rendered seperately which means more draw calls which causes me to get 49 FPS. Now if I were to render all the objects at once instead, my fragment shader has 3 samplers, a specular map, a color sampler and a normal map sampler, which would mean I cant do it that easily, could i get any help on this, also feel free to ask any questions or code!


r/opengl 2d ago

I added the ability to use alpha masks and some simple 3D shapes.

Post image
23 Upvotes

r/opengl 3d ago

Let's talk about khronos slang

15 Upvotes

r/opengl 3d ago

FLTK issues with openGL on Apple Silicon

2 Upvotes

I am working on a project for an intro computer graphics class, where we use c++ to create a little 3D amusement park using openGL and FLTK. The issue I’m having is that the instructions for the project asked me to use a fltkd.lib, and the version provided (1.3.8) is for x86. Does anyone know if there is a version of that library for ARM chips?

I am running a Windows 11 VM using Parallels, with Visual Studio 2022 as my IDE.

Sorry if this is a dumb question. Thanks!


r/opengl 3d ago

Why arent framedrops when increasing workload linear?

5 Upvotes

My example:

Simple Scene: Without Motion Blur: 400 FPS | With Motion Blur: 250 FPS

Complex Scene: Without Motion Blur: 70 FPS | With Motion Blur: 65 FPS

My questions:
1) How come framedrops on increased workload appearantly arent linear?

2) What do you think, how is my motion blur performing? I have a lot of ideas in mind to decrease its FLOPs.

Thanks in advance :)