Problem displaying both Imgui and Scene at the same time


#1

I’m using Freeglut with OpenGL3.

When i setup imgui my previous scene is not rendered anymore but imgui demo widget is shown.
I’ve pretty much followed the opengl2 with freeglut example but adapted it to opengl3 meaning:

these after glut setup
ImGui::CreateContext();
ImGui::StyleColorsDark();
ImGui_ImplOpenGL3_Init();
ImGui_ImplFreeGLUT_Init();
ImGui_ImplFreeGLUT_InstallFuncs();

these after glutmainloop
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplFreeGLUT_Shutdown();
ImGui::DestroyContext();

and my display function is:
clear screen
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplFreeGLUT_NewFrame();
static float f = 0.0f;
static int counter = 0;
ImGui::Begin(“Hello, world!”);
ImGui::Text(“This is some useful text.”);
ImGui::Text(“Application average %.3f ms/frame (%.1f FPS)”, 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
ImGui::End();
ImGui::Render();
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
use shader program (vertex+fragment)
send necessary uniforms
draw hierarchy scene using vaos

What am i missing?
I want to use imgui as an overlay over the scene.
The imgui setup also overwrites my input listeners that are done in glut setup:

glutKeyboardFunc(_keyboardDownCallback);
glutKeyboardUpFunc(_keyboardUpCallback);
glutSpecialFunc(_specialDownCallback);
glutSpecialUpFunc(_specialUpCallback);


#2

You are not providing enough information. The problem is related to your actual scene drawing code.

If ImGui_ImplOpenGL3_RenderDrawData() is conflicting with state that you expect to carry over multiple frames, try to comment out parts of ImGui_ImplOpenGL3_RenderDrawData until you find which state is affected. It may be possible to improve it to save/restore more state.


#3

I should have said more clearly that after the setup itself my scene is no longer rendered.
Imgui’s render draw data is not the culprit.

EDIT: ImGui_ImplFreeGLUT_InstallFuncs this was the culprit it overwrites my callbacks that i have in glut setup.


#4

Unfortunately Glut doesn’t allow to read the old callback so we can’t automatically forward the calls to your already registered callbacks.

Don’t call ImGui_ImplFreeGLUT_InstallFuncs() and call the individual callbacks yourself.

Or, to put it bluntly, you really should not use GLUT in 2019. This is library designed in 1994 and by any criteria it is a little absurd to use Glut today when you can use GLFW or SDL.


#5

Lesson learned about glut.
It was’t my choice however. It was given to us as starting code to build upon.
I made workaround so that when i press tilde it would draw imgui and switch input calls to imgui’s functions. Then when i press tilde again it reverts to my own functions.

Anyway i’m not sure how this discussion site works, but i guess you can close this topic now that there is no longer an issue?


#6

It was given to us as starting code to build upon.

Whoever did that is ill informed and should probably be suggested to reevaluate their tool.
I mostly added a freeglut back-end as part of a my mildly obsessive stance to suggest that dear imgui can work everywhere.

No need to close anything this is regular forum afaik.

Good luck!