Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using OpenGL 3 bindings to display in an OpenGL 2.1 context ? #1513

Open
rtoumazet opened this issue Dec 20, 2017 · 12 comments
Open

Using OpenGL 3 bindings to display in an OpenGL 2.1 context ? #1513

rtoumazet opened this issue Dec 20, 2017 · 12 comments

Comments

@rtoumazet
Copy link

Hi,

I'm getting into a strange problem while trying to add imgui to one of my projects : this project was started in 2002 and uses what's now called legacy OpenGL.

I wanted to take advantage of the switch to move to modern OpenGL (3.3+).

Unfortunately there are some caveats : when compiling the basic example on my desktop computer (with a fairly recent graphics card), everything works fine and the windows are correctly displayed.

On the other hand, when compiling the OpenGL 3 example on a laptop (with an integrated Intel HD4000 graphics card), I get a 0xC0000005 exception before any rendering is done, and if I remove glfwWindowHint calls to get a compatibility context, the display is garbled, and the inputs are erratic at best :
image

The graphics card is supposed to have a 3.3 context capability, but it looks like the drivers aren't up to the task. And as it's a branded laptop, the drivers are proprietary, old, and can't be replaced by vanilla Intel drivers ...

I've tried compiling the OpenGL 2 version on the laptop, and it works fine.

So my question is : using OpenGL 3 bindings, is it possible to force OpenGL to display imgui through an OpenGL 2 context ?

Thanks for reading :)

@ocornut
Copy link
Owner

ocornut commented Dec 20, 2017

A few things to try:
Read #1466 and try to see if tweaking the shader #version and context version fixes it for you?

So my question is : using OpenGL 3 bindings, is it possible to force OpenGL to display imgui through an OpenGL 2 context ?

I don't really understand what you are asking. You have access to all the code in opengl2 and opengl3 folders with code for both styles, just use/copy what works for you.

It's however quite suspicious that the opengl3 doesn't work and it would be judicious to understand the reason.

@rtoumazet
Copy link
Author

rtoumazet commented Dec 20, 2017

(ADMIN: Restored accidental edit to original post)

Thanks for your quick answer Omar, I really appreciate :)

A few things to try:
Read #1466 and try to see if tweaking the shader #version and context version fixes it for you?

I modified the version, with no visible behaviour change unfortunately ...

I don't really understand what you are asking. You have access to all the code in opengl2 and opengl3 folders with code for both styles, just use/copy what works for you.

My ultimate goal would be to be able to choose between legacy or modern opengl at runtime, depending on the graphics card capability, in order to have my program working on a wide range of machines ...

I guess I will have to stick to OpenGL 2 bindings and to forget about modern OpenGL migration for now then ...

@rtoumazet
Copy link
Author

Looks like you edited my post instead of answering it :p

Use an if statement to run different part of the code? :)

I actually tested this route, without being successful :D

The problem is that we don't know what are the criteria triggering this issue. Most probably finding what makes the OpenGL3 path fail on your setup would be the best solution imho.

I second that ... I guess I'll have to dig further :)

@ocornut
Copy link
Owner

ocornut commented Dec 21, 2017

(My apologies! It is the second time this happens here.. I restored your post according to the e-mail notification now. It's quite unusual and dangerous that github even gives me this button.)

I actually tested this route, without being successful :D

Not sure what you mean here. Unless you referring to the second paragraph, that you don't know what to test for? Otherwise having both code paths in the same exe should work.

@rtoumazet
Copy link
Author

I tried to factorize the code, keeping only one main codepath and calling specific OpenGL variants depending on the version used, but it didn't work.
Based on what you said, I created 2 different codepaths, and it worked fine. I guess I'll leave it there for now :)

BTW, thanks for your work, not only on Dear Imgui, but also on everything else (gaming wise, emulation wise and all ...) 🥇

@rtoumazet
Copy link
Author

First of all, happy new year everyone ! :D

Next, I've been doing some more research about the initial problem I'm having at the beginning of the thread (ie the garbled display in the first post).
The display card in my laptop is OpenGL 3.3 compatible (verified querying in app and using OpenGL Extensions Viewer), and should work. The only missing extension being the context profile one, but commenting out the following line
//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
allows the example to run, but with the rendering artifacts.

So what's new you might (rightfully) ask ?
Actually the display works perfectly when there's only one window displayed ... as soon as there's more, everything gets corrupted.

I don't know enough of Dear Imgui inner working to see if it's interesting, but I thought it might ring a bell to someone ...

@ocornut
Copy link
Owner

ocornut commented Jan 2, 2018

Hello Runik, and happy new year!
I don't have time to look at it immediately but may I suggest looking at #1466, and you can try to change the glsl version? I'm just curious if this might have an effect.

@rtoumazet
Copy link
Author

I changed the glsl version to 150 with no visible improvement, unfortunately ...
I'm sure it's something trivial, but I can't put my finger on it yet.

@ocornut ocornut added the opengl label Jan 7, 2018
ocornut added a commit that referenced this issue Jul 10, 2018
…mple app default to GL 3.0 + GLSL 130 (instead of GL 3.2 + GLSL 150) unless on Mac. (#1938, #1900, #1513, #1466, etc.)
@ocornut
Copy link
Owner

ocornut commented Jul 10, 2018

@rtoumazet Sorry for the bump (better late than never!). I have made some changes to the imgui_impl_opengl3.cpp bindings to support lower GLSL versions. However it is tricky to fully test locally as modern drivers have different properties emulating old contexts and I don't think there is a way pre-GL 3.0 to disable backward compatibility.

I would be interested if you could confirm how the examples currently fare with your laptop?
It would also be interesting to double-check and test again with the version from when you initially posted (~Dec 20) and make sure that it still doesn't run (aka confirm that some OS/driver update didn't fix an old issue).

Thank you for your help.

@rtoumazet
Copy link
Author

Don't worry Omar, I know how it is ;)
I just tested the latest repository, and unfortunately the results are the same ... glfw + opengl3 gets garbled when more than one window is displayed, and it works fine with just one window.
Everything works ok in opengl2.

No driver change on the laptop (Toshiba isn't interested in updating a 2012 proprietary graphic driver :p)

@ocornut
Copy link
Owner

ocornut commented Jul 11, 2018

Thanks for your test and feedback! With your help I would really like to solve this.

  1. I realize that I don't know which OS are we talking about here? Windows 7/10? Linux?
    In case you are running on Linux, could you post the output of glxinfo -B ?

  2. Could you try modifying the main.cpp to use different variations.

Currently:

    // GL 3.0 + GLSL 130
    const char* glsl_version = "#version 130";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

Try to changing to:

    const char* glsl_version = "#version 120";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);

or

    const char* glsl_version = "#version 110";
    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

Note that the example now display shader compilation/link error in stdout (which should appear in the console under Windows) so worth checking there.

Thank you.

@rtoumazet
Copy link
Author

Ok, so here we go :)

  1. The laptop is powered by Windows 7.
  2. Checked both versions, with no improvements. The console displays "No errors." 3 times, and the display is still garbled when more than one window is displayed :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants