Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Improving window resize behaviour, possibly by manually setting bigger framebuffer size

Tags:

c++

c

opengl

glfw

I was considering using glfw in my application, while developing on mac

After successfully writing a very simple program to render a triangle on a colored backround, I noticed that when resizing the window, it takes quite some time to rerender the scene, as I suspect due to framebuffer resize.

This is not the case when I am repeating the experiment with NSOpenGLView. Is there a way to hint glfw to use bigger framebuffer size on start, to avoid expensive resizes?

I am using GLFW 3.

Could you also help me with enabling High DPI for retina display. Couldn't find something in docs on that, but it supported in version 3.

like image 871
tzador Avatar asked Jul 07 '13 12:07

tzador


1 Answers

Obtaining a larger framebuffer

Try to obtain a large initial frame-buffer by calling glfwCreateWindow() with large values for width & height and immediately switching to displaying a smaller window using glfwSetWindowSize() with the actual initial window size desired.

Alternately, register your own framebuffer size callback function using glfwSetFramebufferSizeCallback() and set the framebuffer to a large size according to your requirement as follows :

void custom_fbsize_callback(GLFWwindow* window, int width, int height)
{
    /* use system width,height */
    /* glViewport(0, 0, width, height); */

    /* use custom width,height */
    glViewport(0, 0, <CUSTOM_WIDTH>, <CUSTOM_HEIGHT>);
}

UPDATE :
The render pipeline stall seen during the window re-size(and window drag) operation is due to the blocking behavior implemented in the window manager.

To mitigate this in one's app, one needs to install handler functions for the window messages and run the render pipeline in a separate thread independent from the main app(GUI) thread.


High DPI support

The GLFW documentation says :

GLFW now supports high-DPI monitors on both Windows and OS X, giving windows full resolution framebuffers where other UI elements are scaled up. To achieve this, glfwGetFramebufferSize() and glfwSetFramebufferSizeCallback() have been added. These work with pixels, while the rest of the GLFW API work with screen coordinates.

AFAIK, that seems to be pretty much everything about high-DPI in the documentation.

Going through the code we can see that on Windows, glfw hooks into the SetProcessDPIAware() and calls it during platformInit. Currently i am not able to find any similar code for high-DPI support on mac.

like image 80
TheCodeArtist Avatar answered Sep 22 '22 12:09

TheCodeArtist