PDA

View Full Version : Initial GLUT window at bottom of stack



LBear
11-18-2002, 12:54 PM
If a GLUT application has a "scanf" before initialization of GLUT, the GLUT window will show up at the bottom of the stack of the windows on W2000. It can be demonstrated by putting a "scanf" function call just before the glutInit line in the simple.c example program included with GLUT. Adding glutPopWindow at different places did not seem to help. If the "scanf" is removed, the GLUT window shows up at top of the window stack as desired. The "main" of simple.c with the "scanf" is shown below.
Thanks

main(int argc, char **argv)
{

//adding the scanf line causes the graphics window to show up at bottom of window stack
float r;
printf("input a number\n");
scanf("%f",&r);
printf("%f\n",r);

glutInit(&argc, argv);
glutCreateWindow("single triangle");
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}


[This message has been edited by LBear (edited 11-18-2002).]

marcus256
11-19-2002, 12:34 PM
This is a problem with Windows, not GLUT (I believe). GLFW (http://hem.passagen.se/opengl/glfw/) (another OpenGL toolkit) does some tricks to work around this problem.

...yet another "feature" introduced by Microsoft to make life easier for programmers http://www.opengl.org/discussion_boards/ubb/mad.gif

LBear
11-21-2002, 05:33 AM
Thanks for the response!
I thought of adding a routine to glut to get the handle of the GLUT parent window and doing a win32 BringWindowToTop, hoping that would cause a "display" callback or "visibility change" callback. I could not find where the parent window handle is stored in the GLUT C code as I'm not a strong C person, I work mostly in Fortran.

LBear
11-22-2002, 05:49 AM
Success! http://www.opengl.org/discussion_boards/ubb/biggrin.gif
The handle for the GLUT parent window is stored in __glutWindowList[0] and it can be popped forward by calling SetForegroundWindow (instead of BringWindowToTop) with that handle, after GLUT initialization. The array __glutWindowList contains all the handles for the GLUT parent and all subwindows.

marcus256
11-22-2002, 11:04 AM
Originally posted by LBear:
Success! http://www.opengl.org/discussion_boards/ubb/biggrin.gif

Congratulations http://www.opengl.org/discussion_boards/ubb/smile.gif


The handle for the GLUT parent window is stored in __glutWindowList[0] and it can be popped forward by calling SetForegroundWindow (instead of BringWindowToTop) with that handle, after GLUT initialization. The array __glutWindowList contains all the handles for the GLUT parent and all subwindows.

Ahh, but be aware of this: SetForegroundWindow only works for foreground applications (typically a newly started application). If some seconds pass between application start and SetForegroundWindow, it is likely that your app is no longer the foreground app, and then SetForegroundWindow will do nothing (except for under Win 95 & NT 4).

This may not be important to you, but if it is, you are free to have a look at the GLFW (http://hem.passagen.se/opengl/glfw) source (see init.c : glfwInit, and window.c : _glfwSetForegroundWindow + glfwOpenWindow).