Jump to content
  • Advertisement
Sign in to follow this  
PnP Bios

Making GLFW behave properly

This topic is 4861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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]

Share this post


Link to post
Share on other sites
That worked prety nice. Thanks. I just wish GLFW was a little more straight forward. Callback functions don't like classes all that well.

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!