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

window flickering when using "glEnable( GL_SCISSOR_TEST );" #807

Closed
VisComKreiser opened this issue Aug 28, 2016 · 8 comments
Closed

window flickering when using "glEnable( GL_SCISSOR_TEST );" #807

VisComKreiser opened this issue Aug 28, 2016 · 8 comments

Comments

@VisComKreiser
Copy link

I am using GLFW and GLEW in my OpenGL application and tried to integrate imgui.

The setup works fine but my window starts flickering when using "glEnable( GL_SCISSOR_TEST );" at the beginning where i set up all my states

I tried it also in the GLFW example from the repository and the same effect occurs.

Is there an issue with the double buffering or is glEnable( GL_SCISSOR_TEST ); not compatible to use with imgui?

Thanks for your help!

@VisComKreiser
Copy link
Author

i figured out that it works when i use glDisable( GL_SCISSOR_TEST ); before ImGui_ImplGlfwGL3_NewFrame(); and reset it to glEnable( GL_SCISSOR_TEST ); after.
This results in a viewport set only where the imgui window shows up, and i have to reset it to my full window size.

I assume ImGui_ImplGlfwGL3_NewFrame(); doesn't restore some states not correctly or I'm using something wrongly, I'll further investigate.

@ocornut
Copy link
Owner

ocornut commented Sep 5, 2016

Hello @VisComKreiser and sorry for my late answer. I'm not sure I understand your problem. The imgui_impl_glfw_gl3.cpp renderer does:

// start
GLboolean last_enable_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
glEnable(GL_SCISSOR_TEST);

// loop
glScissor((int)pcmd->ClipRect.x, (int)(fb_height - pcmd->ClipRect.w), (int)(pcmd->ClipRect.z - pcmd->ClipRect.x), (int)(pcmd->ClipRect.w - pcmd->ClipRect.y));

// footer
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);

So that would overwrite your scissor rectangle (4 float) if you had one in place. Is that the problem you are having?

We could potentially save and restore the actual scissor rectangle, adding:

// start
int rect[4];
glGetIntegerv(GL_SCISSOR_BOX, rect);

// footer
glScissor(rect[0], rect[1], rect[2], rect[3]);

Would that fix your issue?

@VisComKreiser
Copy link
Author

Thanks for your answer, I was just wondering why it wasn't present in the ImGui_ImplGlfwGL3_RenderDrawLists function where the viewport is restored in this manner.
I added it just below the glViewport call and now it works perfectly fine.

Thanks for your help and the great library! Making research much more comfortable.

@ocornut
Copy link
Owner

ocornut commented Sep 5, 2016

Sorry, just to clarify, was that your problem? Did adding those lines fix it for you?
I can add those missing lines to the existing example code as well.

@VisComKreiser
Copy link
Author

Yes, that was exactly my problem and it is solved now.

I added it in "void ImGui_ImplGlfwGL3_RenderDrawLists(ImDrawData* draw_data)" directly under the glViewport call, the check for GL_SCISSOR_TEST itself is already there, see your sample code as it is now in my project:

....
if (last_enable_scissor_test) glEnable(GL_SCISSOR_TEST); else glDisable(GL_SCISSOR_TEST);
glViewport(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
glScissor(last_viewport[0], last_viewport[1], (GLsizei)last_viewport[2], (GLsizei)last_viewport[3]);
....

@VisComKreiser
Copy link
Author

If you want the scissor region as the actual GL_SCISSOR_BOX, your code you postet would maybe fit better to the example. I just hat the whole window covered all the time, so I can use the same values as for glViewport.

@ocornut
Copy link
Owner

ocornut commented Sep 5, 2016

Added code.

@VisComKreiser
Copy link
Author

Thanks for your help and the extension! I appreciate it.

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

No branches or pull requests

2 participants