glfwSetWindowSizeCallback - Error?

soulfreezer wrote on Thursday, August 05, 2010:

Hello,

I have problems to understand how the callback in GLFW works. If I use the
glfwSetWindowSizeCallback-function, my callback-function will be called two
times?! Is this a bug? Is the first opening of a window detected as
"resize"-event?

Here is my little code, maybe can someone help me out with this :frowning:

#include “Run.h”
#include “FileLogger.h”

FileLogger fileLogger;

void init()
{
fileLogger.log(“Calling init()-Method…”);
fileLogger.log("…");
fileLogger.log(“init()-Method finished.”);
}

void GLFWCALL WindowResize( int width, int height )
{
fileLogger.log(“Calling WindowResize()-Method…”);
fileLogger.log("…");
fileLogger.log(“WindowResize()-Method finished.”);
}

void renderLoop()
{
glClear(GL_COLOR_BUFFER_BIT);
glfwSwapBuffers();
}

int main( void )
{
int running = GL_TRUE;
glfwInit();

if( !glfwOpenWindow( 1024, 768, 32,32,32,32,0,0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}

init();

glfwSetWindowSizeCallback( WindowResize );

while( running )
{
renderLoop();
running = !glfwGetKey( GLFW_KEY_ESC ) && glfwGetWindowParam(
GLFW_OPENED );
}

glfwTerminate();
return 0;
}

Here the Headerfile:

#ifndef RUN_H_
#define RUN_H_
#include <GL/glfw.h>
void GLFWCALL WindowResize( int width, int height );
void renderLoop();
void init();
#endif /* RUN_H_ */

In my Logfile I find this strange output:

05.08.2010 21:34:07 Calling init()-Method…
05.08.2010 21:34:07 …
05.08.2010 21:34:07 init()-Method finished.
05.08.2010 21:34:07 Calling WindowResize()-Method…
05.08.2010 21:34:07 …
05.08.2010 21:34:07 WindowResize()-Method finished.
05.08.2010 21:34:07 Calling WindowResize()-Method…
05.08.2010 21:34:07 …
05.08.2010 21:34:07 WindowResize()-Method finished.

I am working under Ubuntu 10.04 LTS - Lucid Lynx -

Thanx so much for help

greetz
soul

soulfreezer wrote on Thursday, August 05, 2010:

hmmm…maybe I have an idea……

if I replace this line

if( !glfwOpenWindow( 1024, 768, 32,32,32,32,0,0, GLFW_WINDOW ) )

with this line:

if( !glfwOpenWindow( 400, 400, 32,32,32,32,0,0, GLFW_WINDOW ) )

then I get only one resize-Event!

Could it be, that the size of my window is automaticly corrected by ubuntu to
my desctop-size, which is smaller than the resolution 1024x768! Then, if the
first opening of the window is countet as resize-event i would get 2 resize
events at all.

?

elmindreda wrote on Thursday, August 05, 2010:

Yes, what you wrote in your second entry sounds like a likely reason. However,
you should assume that the resize callback can be called at any time and not
count on it being called a specific number of times.

melekor wrote on Thursday, August 05, 2010:

GLFW doesn’t guarantee anything about the number of times your callback is
invoked. GLFW pretty much just wraps the OS, so chances are if you are seeing
two resize events then it is because the OS is sending two. In fact, you can
and will get different results running your code on different OSes and
different settings. This is to be expected and is not a bug in GLFW.

With regards to your specific case, I suppose you could argue that GLFW should
be clamping the window size to the desktop size before the window is created,
since resizing could cause flicker or something like that.

soulfreezer wrote on Friday, August 06, 2010:

Thanx so much! Now I understand it :wink: