Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting a GLFW window as not resizable

Tags:

opengl

glfw

I have a GLFW3 window that I am trying to change from resizable to not resizable.

I tried changing the Window Hint after the window was created but this doesn't do anything as the hints only affect window to be created.

what I tried:

glfwWindowHint(GLFW_RESIZABLE, GL_FALSE)

Is this possible? One way of doing it that I thought of was having a onResize function that changes the window size back to the current size after being set not resizable. This seems very hacky.

like image 679
Simba Avatar asked Nov 30 '14 05:11

Simba


2 Answers

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.


GLFW currently has no API for changing that state after the window is created.

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

  1. The workaround you already have.
  2. Create a new window when you switch that state.
  3. 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.

like image 22
derhass Avatar answered Sep 28 '22 03:09

derhass