Setting the GLFW Window as Not Resizable

I have a GLFW3 window that I am trying to resize from resizable to non resizable.

I tried to change the window hint after the window was created, but it does not do anything, since the hints only affect the window that will be created.

what i tried:

glfwWindowHint(GLFW_RESIZABLE, GL_FALSE) 

Is it possible? One way to do this that I was thinking about is to have an onResize function that resizes the window back to its current size after it was set without resizing. It seems very hacky.

+9
source share
4 answers

Currently, GLFW does not have an API to change this state after creating a window.

If you want to use GLFW, I see two options:

  • The workaround that you already have.
  • Create a new window when switching this state.
  • Use the native GLFW access to get real window handles and implement a function for each platform (you don't care).

All options do not seem to me too attractive. Option 2 is especially bad because GL contexts are tied to windows in GLFW, this should be possible with an extra (invisible) window and general GL contexts, but it will be ugly.

Option 3 has the advantage that it should work flawlessly once it is implemented for all relevant platforms. Since GLFW is open source, this also allows option 3b): implement this directly in GLFW and extend the API. You might even be able to integrate it into the official version of GLFW.

+6
source

Your approach works with GLFW 3.2.1-1 on Ubuntu 18.10:

main.cpp

 #include <GLFW/glfw3.h> int main(void) { GLFWwindow* window; if (!glfwInit()) return -1; glfwWindowHint(GLFW_RESIZABLE, GL_FALSE); window = glfwCreateWindow(640, 480, __FILE__, NULL, NULL); if (!window) { glfwTerminate(); return -1; } glfwMakeContextCurrent(window); while (!glfwWindowShouldClose(window)) { glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; } 

Compile and run:

 g++ -std=c++11 -Wall -Wextra -pedantic-errors -o main.out main.cpp -lglfw ./main.out 

When you hover over the borders of the created window, the cursor never switches to resize mode.

+10
source

This one works , but I highly recommend other solutions, as it is only if you strictly need to be able to switch .

 IntBuffer wid = BufferUtils.createIntBuffer(1); IntBuffer hei = BufferUtils.createIntBuffer(1); glfwGetWindowSize(window, wid, hei); int windowWidth = wid.get(); int windowHeight = hei.get(); // I recommend making this public while(!glfwWindowShouldClose(window)) { glfwSetWindowSize(window, windowWidth, windowHeight); // People can still maximize the window ... Comment if you have a solution :) } 
0
source

My decision:

 // before create: glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // create window // ... // after create void setResizable(arg) { if(arg) glfwSetWindowSizeLimits(window, 0, 0, 0xffff, 0xffff); else { int w, h; glfwGetWindowSize(window, &w, &h); glfwSetWindowSizeLimits(window, w, h, w, h); } } 
0
source

Source: https://habr.com/ru/post/978888/


All Articles