hide() / show() a Fl_Gl_Window

27 views
Skip to first unread message

Rob McDonald

unread,
Aug 6, 2022, 2:00:23 AM8/6/22
to fltk.general
I now have a need to hide() a Fl_Gl_Window and then later show() it again.

The documentation appears to say that the OpenGL context is destroyed when the Fl_Gl_Window is hide()'ed.

When I try to show() the Fl_Gl_Window, I get a segfault in my draw() code that is called from Fl_Gl_Window::flush().

I think it is because I have not re-established the OpenGL context that was destroyed during the hide().

What kind of special care needs to be taken to be able to hide() / show() a Fl_Gl_Window?

Thanks for any help,

Rob

Manolo

unread,
Aug 6, 2022, 3:00:18 AM8/6/22
to fltk.general
No more calls besides glwin->show(); are necessary after a GL window was hidden.
The GL context is re-created by member function ::make_current() which is itself automatically called
by the normal event loop.

You can see that with test/fullscreen.cxx : replace line #154 therein
    sw->mode(d ? Fl_Mode(FL_DOUBLE|FL_RGB) : FL_RGB);
by
    if (d) sw->hide(); else sw->show();
and run this app. Use its "Double Buffered" button to hide and then re-show the GL panel.

ed.vi...@gmail.com

unread,
Sep 8, 2022, 1:01:02 PM9/8/22
to fltk.general
You can use Fl_Gl_Windiw::context_valid() to test if the context is no longer valid and you need to reinitialize. If using GLSL 330 or higher, you need to reload the shaders, etc. into the new context.

Ed

Reply all
Reply to author
Forward
0 new messages