Setting a GLFW window as not resizable
GLFW currently has no API for changing that state after the window is created.
When you want to use GLFW, I see two options:
- The workaround you already have.
- Create a new window when you switch that state.
- Use the GLFW native access to obtain the real window handles and implement the feature for each platform (you care about).
All variants don't seem too appealing to me. Option 2 is especially bad because of the way GL contexts are tied to windows in GLFW, it should be possible by using an extra (invisible) window and shared 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. As GLFW is open source, this enables also option 3b): implement this directly in GLFW and extend the API. You might even be able to get this integrated into the official GLFW version.
This works but I highly recommend the other solutions, as this is only if you strictly need to be able to toggle it.
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 :)
}
Your approach works as of GLFW 3.2.1-1 in Ubuntu 18.10:
main.cpp
#include <GLFW/glfw3.h>
int main(void) {
GLFWwindow* window;
if (!glfwInit())
return -1;
glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
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
As I hover the borders of the created window, the cursor never changes to resize mode.
You can change the GLFW_RESIZABLE
attribute of an existing window with the following code:
bool enable;
glfwSetWindowAttrib(window, GLFW_RESIZABLE, enable);