Initial GLUT window at bottom of stack

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
“);
scanf(”%f”,&r);
printf("%f
",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).]

This is a problem with Windows, not GLUT (I believe). GLFW (another OpenGL toolkit) does some tricks to work around this problem.

…yet another “feature” introduced by Microsoft to make life easier for programmers

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.

Success!
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.

Originally posted by LBear:
Success!

Congratulations

[b]

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. [/b]

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 source (see init.c : glfwInit, and window.c : _glfwSetForegroundWindow + glfwOpenWindow).