Making GLFW behave properly

Started by
3 comments, last by JTippetts 18 years, 8 months ago
Is there a way to prevent a GLFW window from being resized or maximized?
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Advertisement
<false>
Not really, unless you want to modify the underlying source that gets the platform-specific events, to ignore the event or revert back to the previous window size. (in _glfwPlatformPollEvents and _glfwPlatformWaitEvents found in the window.c file for each platform)
</false>

But! a workaround would be to set up a callback function (using glfwSetWindowSizeCallback) to listen for resize events, then set the window size to the previous size (using glfwSetWindowSize). Unfortunately, this might result in some strange visual effects (user tries to resize window but it snaps back to the previous size)...

<false>
Oh, and to be safe, you shouldn't call the glfwSetWindowSize function from within your callback... that would probably result in an infinite callback->setSize->callback->setSize... loop. Send an event to an event subsystem and handle it once you're out of the callback and back in your main loop.
</false>

*EDIT*
Okay! I just threw this code snippet together, to see how <del>right</del> wrong I might be:
#include <iostream>#include "GL/glfw.h"void resize(int x, int y){std::cout << "inside callback" << std::endl;    glfwSetWindowSize(640, 480);}int main(){    glfwInit();        glfwOpenWindow(640, 480, 8, 8, 8, 0, 0, 0, GLFW_WINDOW);    glfwSetWindowSizeCallback(&resize);        glClearColor(1.0, 1.0, 1.0, 1.0);        while(!glfwGetKey('Q'))    {        glClear(GL_COLOR_BUFFER_BIT);        glfwSwapBuffers();    }        glfwCloseWindow();    glfwTerminate();    return 0;}


it turns out, you _can_ call glfwSetWindowSize without worry about an infinite loop (on Win32, haven't tested it under other platforms). And, the only visual anomoly is that the window will move to the left if you try to resize from the left side (resizing from the right side will result in the window remaining the same size and not moving).

Also, if the user hits the maximize button, the title bar and borders will change its style to that of the maximized title bar (on Win32 it's square, I don't know the symptom on other platforms right now), and the window will jump to position (0, 0).

So, just call glfwSetWindowSize from inside your resize callback, and that will eliminate attempts to resize the window :) Anyone else willing to try this on other platforms? (I'm away from home and only have access to a WinXP machine)


[Edited by - void* on July 25, 2005 12:09:22 AM]
Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified bug-ridden slow implementation of half of Common Lisp."
That worked prety nice. Thanks. I just wish GLFW was a little more straight forward. Callback functions don't like classes all that well.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
Quote:Original post by PnP Bios
That worked prety nice. Thanks. I just wish GLFW was a little more straight forward. Callback functions don't like classes all that well.


Yeah, I spent most of my time forwarding GLFW callbacks to classes. It's a shame they don't give you a user pointer :(
Many times, I've thought about hacking GLFW up a bit in the input handling area, to suit my needs a little better. I prefer GLFW over SDL because it is lighter weight, and most of SDL is excess baggage, but the input handling is a little inflexible.

This topic is closed to new replies.

Advertisement