wjakob / nanogui

Minimalistic GUI library for OpenGL
Other
4.66k stars 608 forks source link

Support for OpenGl 2? #212

Closed ghost closed 7 years ago

ghost commented 7 years ago

Hi, I have successfully compiled all the examples, however during run-time, I get the following error: image

How can I change the settings so that I can use OpenGl-2? I can compile and run Nuklear with X11 on the same machine. Thanks,

svenevs commented 7 years ago

NanoGUI is OpenGL 3.x or higher, so it's very unlikely you will ever get this to work :/ Of you're new to OpenGL, 3.x got rid of the "fixed function pipeline", and is not backwards compatible with 2.x and earlier. So you're ultimately going to have to decide: update your OpenGL code, or don't use nanogui. Pros and cons to both, switching to OpenGL 3 has some overhead for sure. But there's a long list of reasons why it went down like this, first and foremost is performance.

You can try using the explicit screen constructor and request 2.something. this example shows how to get a 4.1 profile, but I seriously doubt you will be able to get nanogui to work with OpenGL 2.x. Good luck, sorry for the bad news

ghost commented 7 years ago

Thanks a lot for the answer. The only problem is that all this code runs within a VM/Docker image. Nuklear and imGUI both work with lower OpenGL versions, but i want to use NanoGUI. I will have to scratch my head around it. This is the project I am working on: https://github.com/QuantScientist/DeepSleep

phicore commented 7 years ago

The underliyng nanovg engine can run on OpenGL2, so it should not be too hard to get it working for nanogui

wjakob commented 7 years ago

I agree that it might be possible based on the NanoVG support for OpenGl 2.x. This is really not a priority for us, so: patches are welcomed that add (optional) OpenGL 2.x support. For now I'll go ahead and close this issue since there is no problem with NanoGUI itself.

ghost commented 7 years ago

Agreed and understandable.

svenevs commented 7 years ago

For what it's worth, if you decide to go down this route, the following is what I know based off the long-ago attempt I made to do this. I was working with a medium sized framework and was hopeful to get NanoGUI to 2.x, but ultimately ended up concluding it was less work to re-do the framework for 3.x instead.

  1. There are many gl* calls in nanogui, each of which would need to be checked for compatibility. It's a rather long list. Many are available since 2.0, and instead of trying to implement equivalent functionality, since implementing 2.x would be a compat feature anyway, #error maybe?

    • You can find the relevant calls to check against with

      $ cd /path/to/nanogui
      # acquire the list of gl calls from the include directory
      $ egrep -Hn --color=auto -r ^[[:space:]]*gl[[:alnum:]]+\(.*\) include/
      # acquire the list of gl calls from the src/ directory
      $ egrep -Hn --color=auto -r ^[[:space:]]*gl[[:alnum:]]+\(.*\) src/
    • The file of closest focus should be src/screen.cpp, since that's where all the magic happens. A random selection gives glGetFramebufferAttachmentParameteriv, which is 3.x or higher

      • Depending on decision / workaround, potentially all stencil related utilities would have to be worked around?
      • I know little about the raw GL setup for scissoring and stencil and fancy features, so it may not actually be that bad to backport.
  2. To get something working, you'll need conditional compilation. The easiest way would be to create another CMake option that defaults to OFF, something like NANOGUI_GL2_COMPAT or something. Then right before this one, something like

    if(NANOGUI_GL2_COMPAT)
        list(APPEND NANOGUI_EXTRA_DEFS NANOGUI_GL2_COMPAT)
    endif()
    • The current build system adds those as compiler-level definitions.
    • Using this, despite the comment (bad merge from the GLES stuff?) define NANOVG_GL2_IMPLEMENTATION instead

      #if defined(NANOGUI_GL2_COMPAT)
          #define NANOVG_GL2_IMPLEMENTATION
      #else
          #define NANOVG_GL3_IMPLEMENTATION
      #endif
      #include <nanovg_gl.h>

3. Figure out what to do with glfw. The submodule being used in this library only provides glfw3. On the other hand, the glad stuff should all be kosher.

As @phicore said, it technically is possible. I include it only to help kick-start if you're new to the framework, but I'm honestly only familiar with the build system and a few core classes...

ghost commented 7 years ago

I resolved this issue. See: https://github.com/ocornut/imgui/issues/1094

image

cesss commented 6 years ago

@QuantScientist Can you explain what steps did you need to perform in order to get it working under OpenGL 2.x? I also require OpenGL 2.x, because sometimes you really need your program to be run on a virtual machine, and there you don't have 3.x.

Also, I don't understand the link to the imgui issue... are nanogui and imgui related in some way?

Thanks!