Page 1 of 1

wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 22, 2019 9:13 am
by heinermueller
Hi All

we are porting an application that already works under Windows and OSX to Linux (Mint) using wxGTK under gtk3. So far everything works surprisingly well with a simple recompilation. But we have a display issue: one of our laptops has a 4K screen, so gtk sets a dispaly scaling of 2. The result is that wxGTK respects the display scaling but OpenGL (more precisely: glViewport) does not. To reproduce

1. open wxFrame with wxGLCanvas
2. set inner size to e.g. 1024px width -> results in scaled frame with 2048 display pixels canvas width
3. open glViewport with the same 1024px -> will open *real* 1024 display pixels unscaled viewport

Result is a OpenGL viewport that fills only the bottom left quarter of the wxGLCanvas.

We can fix the issue by passing the display scaling to all of the OpenGL screen-based operations (eg. glViewport, glScissor) but this is inefficient and error prone. Is there an official way to pass the display scaling to OpenGL (as it apparently happens in Windows and OSX)?

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 22, 2019 10:25 am
by heinermueller

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 22, 2019 11:20 am
by heinermueller
Interim solution: you can change the GDK scale factor by setting the

GDK_SCALE=1

factor in the environment variables. Using this solution now, since we do not know about the display scaling implications (glViewport and glScissor for sure, not sure about framebuffer objects)

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 22, 2019 4:03 pm
by Manolo
In that ticket #17391 you can read that OpenGL knows nothing about the scale of the display. The best way to go is also told there: use const wxSize sizeInPixels = GetClientSize() * GetContentScaleFactor();.
No need to use GDK_SCALE, which will affect also the normal GUI.

Then use that sizeInPixels in all OGL functions that require it: glViewport, FBO, glScissor, glReadPixels, etc.

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Thu Oct 24, 2019 12:06 pm
by heinermueller
unfortunately

Code: Select all

GetContentScaleFactor();
always reports 1.0, then i replaced it with a direct call to

Code: Select all

gdk_monitor_get_scale_factor( gdk_display_get_monitor (gdk_display_get_default(), 0));
which seems to work. Is this a bug, shall i report it? wx version is 3.0.4, gtk runtime is 3.22., gtk compile time is 3.22.29

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Thu Oct 24, 2019 4:01 pm
by Manolo
Fixed two months ago.
https://github.com/wxWidgets/wxWidgets/ ... 5283137a2f

Can you test it (as the patch uses gtk_widget_get_scale_factor() instead of gdk_monitor_get_scale_factor())?

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 29, 2019 2:09 pm
by heinermueller

Code: Select all

gtk_widget_get_scale_factor( .. )
reports the correct current scale factor here, so the patch seems fine to me. Do you have any idea why the return value of gtk_widget_get_scale_factor is an int? There may be a display scaling of 150% resulting in a scale factor of 1.5 which is impossible to express with an int.

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Posted: Tue Oct 29, 2019 5:30 pm
by ONEEYEMAN
Hi,
You should ask that question on the GTK forum.

Thank you.