wxGTK + OpenGL + gtk3 + Display Scaling

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
heinermueller
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sat Oct 26, 2013 11:54 am

wxGTK + OpenGL + gtk3 + Display Scaling

Post 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)?
heinermueller
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sat Oct 26, 2013 11:54 am

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post by heinermueller »

heinermueller
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sat Oct 26, 2013 11:54 am

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post 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)
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post 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.
heinermueller
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sat Oct 26, 2013 11:54 am

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post 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
Manolo
Can't get richer than this
Can't get richer than this
Posts: 827
Joined: Mon Apr 30, 2012 11:07 pm

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post 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())?
heinermueller
Experienced Solver
Experienced Solver
Posts: 99
Joined: Sat Oct 26, 2013 11:54 am

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post 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.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxGTK + OpenGL + gtk3 + Display Scaling

Post by ONEEYEMAN »

Hi,
You should ask that question on the GTK forum.

Thank you.
Post Reply