• Ever wanted an RSS feed of all your favorite gaming news sites? Go check out our new Gaming Headlines feed! Read more about it here.
  • We have made minor adjustments to how the search bar works on ResetEra. You can read about the changes here.

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
This might not seem too mind blowing to people who have never tried to actually do something like this from scratch, but this right here might as well be black fucking magic:

EG_lDY5WoAMVroc


What you're seeing is a demonstration of an experimental build of UI library called ImGui. ImGui is made by Omar Cornut, the dude behind the emulator Meka and games like Wonder Boy: The Dragon's Trap. ImGui is a cross platform user interface for programming projects that works with stuff like OpenGL or DirectX. If you've never done any sort of programming before, it's actually a ton of work just to get a window drawn to your screen through your operating system shell, especially when you do things cross platform. This is because the underlaying window handling technologies between windows, OSX, and linux (even different distros of linux) are often radically different and wholly incompatible. A technology called SDL is already pretty magical in that it basically makes the "build a window" portion of making an OpenGL application completely vanish, but it offers no user interface options, you have to build that from scratch.

Now, for complex reasons, handling multiple SDL2 windows is kind of tough, handling multiple OpenGL contexts is also kind of tough (an OpenGL context is basically like a "copy" of OpenGL reserved for a window), and when you throw multiple monitors into the mix, everything gets much, much tougher. In the demo above, an ImGui window is straddling two separate monitors. That's really remarkable in and of itself, but it gets more crazy.

See, ImGui normally embeds into your OpenGL program. You build an OpenGL app, tell SDL to make you a window, and it's like your window has OpenGL inside of it. ImGui uses OpenGL to draw itself, which is how it gets around the need for underlaying window technologies in linux and windows and all that being incompatible. The original idea was that ImGui was a window UI that created virtual windows inside of your OpenGL app. This meant that ImGui windows could only remain inside your app. But this experimental build of ImGui is called the "docker" build, until it gets rolled into the proper stable ImGui build. This build of ImGui is amazing -- you can now drag an ImGui window out of your application. When you drag the ImGui window outside of your app, ImGui seamlessly handles turning it into an entirely separate SDL-OpenGL window. It's fucking insane:

46300244-80708900-c5a3-11e8-8365-f89cfd06080e.gif


I can't express enough how this is normally thousands of lines of boiler plate code to do this kind of stuff, and it currently exists as essentially a drag and drop solution that you can throw on top of basically any existing application. And the UI is cross platform. A slick UI like this on a single platform is normally a massive amount of work, but now you can embed it into any graphical program with just a few lines of code, and it'll just work on any OS??

Now, all of that is amazing enough, but that's not all that's going on in the pic. You might notice the monitors in the pic, one of them is an ancient 4:3 CRT monitor. The computer I do my development on is actually modern, with a modern video card. It only has HDMI and Display ports to output with, no VGA option. Even when I use an HDMI -> DVI -> VGA adapter, the chip actually doesn't do analogue conversion and can't connect to a CRT monitor. It doesn't output an analogue signal at all. You see, in the pic above, that's actually two separate computers. The second monitor on the right is connected to a mini Xi3 Piston PC:

EG_lmM4XYAAdHpD


This makes what ImGui is doing way, way more impressive. The screen on the right is acting like a display for the PC on the left using OpenSSH. I set up a VNC sever on the PC on the left using x11vnc, then used VNCViewer on the PC on the right. By manually configuring the intel GPU on the PC on the left to set up a virtual head, I was able to extend my desktop to the size of both screens at once, then use x11vnc to crop the display to a vnc server, which the PC on the right connected with. The two PCs are actually only communicating through the router, across the network.

This means that ImGui is spreading a window that shouldn't exist, seamlessly, across two monitors, with each monitor being an entirely separate computer, and it just fucking works with no real setup on my part. And every technology being used here is FOSS - free and open source software. This entire setup would have been literally impossible like 10 years ago even for expensive enterprise tools, yet it's free and open today. Absolutely mind blowing.
 

Rookhelm

Member
Oct 27, 2017
3,690
I don't really understand, but I appreciate the complexity and level of effort involved.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
I don't really understand, but I appreciate the complexity and level of effort involved.

it's a lack of effort that is really what's amazing. Doing something like this used to take a extreme amount of effort. That this can be done essentially with no hitches this smoothly is what is so incredible. Especially for free.
 

Rookhelm

Member
Oct 27, 2017
3,690
it's a lack of effort that is really what's amazing. Doing something like this used to take a extreme amount of effort. That this can be done essentially with no hitches this smoothly is what is so incredible. Especially for free.

I've dabbled in programming, so I get the gist at a very basic level, but I don't know all the terms and truly what it takes.

Anecdote, but I was listening to the Steve Jobs biography recently, and the programmers basically said it was impossible to make rounded corners on the windows. They made it happen, but it's so crazy to think that it used to be a hard problem to solve.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
I've dabbled in programming, so I get the gist at a very basic level, but I don't know all the terms and truly what it takes.

Anecdote, but I was listening to the Steve Jobs biography recently, and the programmers basically said it was impossible to make rounded corners on the windows. They made it happen, but it's so crazy to think that it used to be a hard problem to solve.

I don't really know anything about how the mac works, but i'm betting that was a compositor problem, basically a problem relating to painter's algorithm and how transparency is handled today. Even with today's modern video hardware, accurately doing transparent items is still a hard problem to solve. I would guess that the old apple interface was just a straight 1:1 mapped bitmap image, but who knows.
 

Arebours

Member
Oct 27, 2017
2,656
Imgui is great. Basically read through the entire source when I taught myself how to do (immediate mode) gui programming - which is an interesting topic in it's own right.

Have actually done the same with large parts of sdl2 as well.
 
Last edited:

Vapelord

Member
Oct 27, 2017
1,830
Montreal
ImGui seamlessly handles turning it into an entirely separate SDL-OpenGL window.

I've retired from programming but the amount of times I've heard "Oh that will be a seamless transition from our test enviroment to live" and only have it blow up in spectacular fashion makes me leery of these claims :P
 

Komo

Info Analyst
Verified
Jan 3, 2019
7,110
For people who need the TLDR.

Basically there's a library (extension of a program which lets it do more stuff), and this experimental build lets you drag the GUI outside of the application window. So OP is now dragging this window across two monitors but those two monitors are on separate PCs entirely only being connected by the internet..
 

CarpeDeezNutz

Avenger
Oct 27, 2017
2,732
For people who need the TLDR.

Basically there's a library (extension of a program which lets it do more stuff), and this experimental build lets you drag the GUI outside of the application window. So OP is now dragging this window across two monitors but those two monitors are on separate PCs entirely only being connected by the internet..
Thank you for dumbing it down.

fascinating thread thanks OP. I've dabbled in computer programming but nothing like this.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
For people who need the TLDR.

Basically there's a library (extension of a program which lets it do more stuff), and this experimental build lets you drag the GUI outside of the application window. So OP is now dragging this window across two monitors but those two monitors are on separate PCs entirely only being connected by the internet..

One other thing I forgot to add -- the two PCs are using different operating systems on top of all this. The monitor on the right is running Windows, the monitor on the left is running Xubuntu, but they are acting like one single display.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
Have actually done the same with large parts of sdl2 as well.

Yeah, but as I said earlier, handling multiple windows with SDL2 is still pretty tricky. The SDL2 portion is actually the easiest bit, you just call SDL_CreateWindow and store the pointer in, like, a dynamic vector or an array or something. What makes it difficult is the OpenGL bit, because of the handling of contexts. Each SDL window needs it's own openGL context, but doing that makes each window like it's own, entirely separate instance of OpenGL, which makes doing things like sharing textures in VRAM more tricky. The solution is to create a shared context, where the first OpenGL context you create is given an index, then every context pointer after is explicitly told to share the context. But this mucks up with multiple monitors, due to some underlaying OpenGL driver problems. Far as I can tell, ImGui is letting SDL2 handle the multiple windows and monitors entirely, which is pretty amazing.
 

Arebours

Member
Oct 27, 2017
2,656
Yeah, but as I said earlier, handling multiple windows with SDL2 is still pretty tricky. The SDL2 portion is actually the easiest bit, you just call SDL_CreateWindow and store the pointer in, like, a dynamic vector or an array or something. What makes it difficult is the OpenGL bit, because of the handling of contexts. Each SDL window needs it's own openGL context, but doing that makes each window like it's own, entirely separate instance of OpenGL, which makes doing things like sharing textures in VRAM more tricky. The solution is to create a shared context, where the first OpenGL context you create is given an index, then every context pointer after is explicitly told to share the context. But this mucks up with multiple monitors, due to some underlaying OpenGL driver problems. Far as I can tell, ImGui is letting SDL2 handle the multiple windows and monitors entirely, which is pretty amazing.
You misunderstood me, I meant to say that studying much of the sdl2 source has been very useful to me.

That said I want to say that when I used imgui there was no coupling to opengl or sdl, you had to implement your own back end and imgui just gave you a list of sorted and clipped rectangles. It's one of the reasons I like the library to begin with.
 
OP
OP

Deleted member 12790

User requested account closure
Banned
Oct 27, 2017
24,537
You misunderstood me, I meant to say that studying much of the sdl2 source has been very useful to me.

Oh, misread your post

That said I want to say that when I used imgui there was no coupling to opengl or sdl, you had to implement your own back end and imgui just gave you a list of sorted and clipped rectangles. It's one of the reasons I like the library to begin with.

It actually still works like this. ImGui, the project page, has a bunch of bespoke implementations fo various backends, I just stick with SDL and OpenGL because it's what I've worked with for like 20 years now. but check this out:

fmKcYQI.png


I've actually talked with Omar Bock about building a Sega Dreamcast port of ImGui, which is possible due to the extreme abstraction. Truly magic software. Even just limiting yourself to OpenGL, it supports all sort of extension wranglers seamlessly:

Code:
#if defined(IMGUI_IMPL_OPENGL_LOADER_GL3W)
    #define IMGUI_GL_EXTENSION_LOADER \
    bool err = gl3wInit() != 0;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLEW)
    #define IMGUI_GL_EXTENSION_LOADER \
    bool err = glewInit() != GLEW_OK;
#elif defined(IMGUI_IMPL_OPENGL_LOADER_GLAD)
    #define IMGUI_GL_EXTENSION_LOADER \
    bool err = gladLoadGL() == 0;
#else
    #define IMGUI_GL_EXTENSION_LOADER \
    bool err = false;
#endif

I had never used anything but GLEW before ImGui. Their preprocessor macros actually lead me to gl3w!