Viewport screen resolution not scaling properly in OSX retina

36 views
Skip to first unread message

PWalker

unread,
Mar 11, 2020, 10:19:23 AM3/11/20
to OpenSceneGraph Users
Hello,

The viewport dpi is different from the window dpi on OSX. Is there a way to fix the viewport dimensions, preferably by autodetecting the size of the frame buffer, so that the viewport size matches the window size?

There must be a way to detect the frame buffer size in OSG, but I cannot find it.

The particular issue occurs with the FLTK sample program when compiled on my macbook.


On OSX, the viewport fills the bottom left  quarter of the window. I have read the scale factor to apply to the viewport is 2x the window size, but the resulting dimensions of the rescaled viewport are not exactly right. is there a way to access the framebuffer to get its dimensions?

On windows, I understand this issue could be fixed with a call to

///    ::SetProcessDPIAware();  //.. .alternately: SetProcessDpiAwareness()

but there seems to be no equivalent on for OSX.

I was unsuccessful accessing the function glfwGetFramebufferSize defined in <GLFW/glfw3.h>

I have also tried to modify the sample code AdapterWidget() with the following commented lines to access the frame buffer size from OSG, with no luck.

            AdapterWidget(x,y,w,h,label),xpixscale(1.0),ypixscale(1.0)
            {
                getCamera()->setViewport(new osg::Viewport(0,0,xpixscale*w,ypixscale*h));
                getCamera()->setProjectionMatrixAsPerspective(30.0f, static_cast<double>(w)/static_cast<double>(h), 1.0f, 10000.0f);
                getCamera()->setGraphicsContext(getGraphicsWindow());
                getCamera()->setDrawBuffer(GL_BACK);
                getCamera()->setReadBuffer(GL_BACK);
           
                setThreadingModel(osgViewer::Viewer::SingleThreaded);
 //           unsigned int swidth, sheight;
 //                  osgViewer::GraphicsWindow * _gw = getGraphicsWindow();
 //                  osg::GraphicsContext * gc = (osg::GraphicsContext*) _gw;
 //                  osg::GraphicsContext::WindowingSystemInterface * wsi = gc->getWindowingSystemInterface();
 //                  //yields wsi->Name == "Cocoa" but no other useful information
 //                  osg::DisplaySettings *ds = gc->getWindowingSystemInterface()->getDisplaySettings();  // This is NULL
 //                  sheight = ds->getScreenHeight();
 //                  swidth =  ds->getScreenWidth();
 //                  std::cout << sheight << " " << swidth << std::endl;
            }

There must be a solution to detecting the frame buffer size in OSG so the viewport size can be scaled to the window size. but I cannot find it. Does anyone have a solution?

Thanks

Robert Osfield

unread,
Mar 12, 2020, 4:23:53 AM3/12/20
to OpenSceneGraph Users
I don't have an MacOS/OSX box or expertise on it but I do know that the OSG's built in osgViewer windowing functionality for the Mac does have handling for it.  If you are using a 3rd party library like FLTK or GLFW then it'll likely bypass this.

Does osgviewer work OK for you?  Have you tried just using the OSG's native windowing?

OpenSceneGraph Users

unread,
Mar 12, 2020, 11:25:02 AM3/12/20
to OpenSceneGraph Users
Robert is right, windowing toolkits often have their own ways of handling this. For example, Qt and FLTK (and others) define a pixel ratio that you can get via their API. I did a google search for "fltk gui retina" which took me to https://www.fltk.org/doc-1.4/drawing.html . See that link for getting the screen scale factor, which you then apply anywhere you use pixel size/coordinates in your program. The resulting code code is cross-platform, since the pixel scale will be 1.0 for Win/Linux but something higher on OSX.

Ravi

On Thu, Mar 12, 2020 at 4:24 AM OpenSceneGraph Users <osg-...@lists.openscenegraph.org> wrote:
I don't have an MacOS/OSX box or expertise on it but I do know that the OSG's built in osgViewer windowing functionality for the Mac does have handling for it.  If you are using a 3rd party library like FLTK or GLFW then it'll likely bypass this.

Does osgviewer work OK for you?  Have you tried just using the OSG's native windowing?

--
You received this message because you are subscribed to the Google Groups "OpenSceneGraph Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to osg-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/osg-users/de7c0c0e-37ff-42a2-941d-425661e9cbb6%40googlegroups.com.
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
Reply all
Reply to author
Forward
0 new messages