|
From: <ipe...@it...> - 2012-06-14 05:06:38
|
Hi everybody.
In many cases it is desirable to keep the window size within a
particular range.
For instance we need to keep the window width to at least 400 pixels.
One way to do this is to write the following code.
void Reshape(int width, int height)
{
if (width<400)
{
glutReshapeWindow(400, height);
glutPostRedisplay ();
return;
}
..
}
int main()
{
..
glutReshapeFunc( Reshape );
..
}
This above example doesn't work in Windows XP.
I'm not sure if it is a bug or it is suppossed to work this way.
It used to work with glut.
Searching inside the freeglut's code I saw that the following happen:
1. The user resizes the window.
2. WM_SIZE is sent to the WIndowProc.
There "window->State.NeedToResize" is set to GL_TRUE
3. WM_PAINT is sent to the WIndowProc.
There fghRedrawWindow( window ) is called
4. fghRedrawWindow calls fghReshapeWindow and then
resets "window->State.NeedToResize" to GL_FALSE
static void fghRedrawWindow ( SFG_Window *window )
{
..
if( window->State.NeedToResize )
{
fghReshapeWindow(
window,
window->State.Width,
window->State.Height
);
window->State.NeedToResize = GL_FALSE;
}
..
}
5. In the meantime, fghReshapeWindow does the resize and then
calls the glutReshapeFunc callback, in our example "Reshape(..)".
6. We call glutReshapeWindow inside "Reshape(..)" and
"window->State.NeedToResize" is set to GL_TRUE
void FGAPIENTRY glutReshapeWindow( int width, int height )
{
..
fgStructure.CurrentWindow->State.NeedToResize = GL_TRUE;
..
}
But before it gets processed, it is reset when it returns
to fghRedrawWindow (step 4).
So it never executes the user's request for a new resize.
The problem is solved if we reset variable "window->State.NeedToResize"
before the call to fghReshapeWindow:
static void fghRedrawWindow ( SFG_Window *window )
{
..
if( window->State.NeedToResize )
{
window->State.NeedToResize = GL_FALSE;
fghReshapeWindow(
window,
window->State.Width,
window->State.Height
);
}
..
}
Best Regards
Ioannis
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
|