3 #include <GL/freeglut.h>
\r
5 int nWindow, nChildWindow = -1;
\r
7 GLboolean bChildPosDone = GL_FALSE, bChildSizeDone = GL_FALSE;
\r
9 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY );
\r
11 void Reshape(int width, int height);
\r
12 void Position(int x, int y);
\r
13 void WindowStatus(int state);
\r
20 int width = glutGet(GLUT_WINDOW_WIDTH);
\r
21 int height = glutGet(GLUT_WINDOW_HEIGHT);
\r
24 glVertex2d(width*.25, height*.75);
\r
25 glVertex2d(width*.75, height*.75);
\r
26 glVertex2d(width*.75, height*.25);
\r
27 glVertex2d(width*.25, height*.25);
\r
31 void UnhideTimer(int window)
\r
33 glutSetWindow(window);
\r
37 void ChangeTitleTimer(int unused)
\r
39 glutSetIconTitle("new icon title");
\r
40 glutSetWindowTitle("new test title");
\r
43 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
\r
48 glutLeaveMainLoop();
\r
55 printf("main window toggle fullscreen\n");
\r
56 glutFullScreenToggle();
\r
63 if (nChildWindow!=-1 && cChar=='r') /* Capital R always resizes the main window*/
\r
65 glutSetWindow(nChildWindow);
\r
66 printf("child window resize\n");
\r
67 if (!bChildSizeDone)
\r
68 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)+50,glutGet(GLUT_WINDOW_HEIGHT)+50);
\r
70 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)-50,glutGet(GLUT_WINDOW_HEIGHT)-50);
\r
71 bChildSizeDone = !bChildSizeDone;
\r
75 glutSetWindow(nWindow);
\r
76 printf("main window resize\n");
\r
77 if (glutGet(GLUT_WINDOW_WIDTH)<400)
\r
78 glutReshapeWindow(600,300);
\r
80 glutReshapeWindow(300,300);
\r
88 if (nChildWindow!=-1 && cChar=='m') /* Capital M always moves the main window*/
\r
90 glutSetWindow(nChildWindow);
\r
91 /* The window position you request is relative to the top-left
\r
92 * corner of the client area of the parent window.
\r
95 glutPositionWindow(glutGet(GLUT_WINDOW_X)+50,glutGet(GLUT_WINDOW_Y)+50);
\r
97 glutPositionWindow(glutGet(GLUT_WINDOW_X)-50,glutGet(GLUT_WINDOW_Y)-50);
\r
98 bChildPosDone = !bChildPosDone;
\r
102 glutSetWindow(nWindow);
\r
103 printf("main window position\n");
\r
104 /* The window position you request is the outer top-left of the window,
\r
105 * the client area is at a different position if the window has borders
\r
106 * and/or a title bar.
\r
108 if (glutGet(GLUT_WINDOW_X)<400)
\r
109 glutPositionWindow(600,300);
\r
111 glutPositionWindow(300,300);
\r
119 if (nChildWindow!=-1 && cChar=='d') /* Capital D always moves+resizes the main window*/
\r
121 glutSetWindow(nChildWindow);
\r
122 if (!bChildPosDone)
\r
123 glutPositionWindow(glutGet(GLUT_WINDOW_X)+50,glutGet(GLUT_WINDOW_Y)+50);
\r
125 glutPositionWindow(glutGet(GLUT_WINDOW_X)-50,glutGet(GLUT_WINDOW_Y)-50);
\r
126 bChildPosDone = !bChildPosDone;
\r
127 if (!bChildSizeDone)
\r
128 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)+50,glutGet(GLUT_WINDOW_HEIGHT)+50);
\r
130 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)-50,glutGet(GLUT_WINDOW_HEIGHT)-50);
\r
131 bChildSizeDone = !bChildSizeDone;
\r
135 if (glutGet(GLUT_WINDOW_X)<400)
\r
136 glutPositionWindow(600,300);
\r
138 glutPositionWindow(300,300);
\r
139 if (glutGet(GLUT_WINDOW_WIDTH)<400)
\r
140 glutReshapeWindow(600,300);
\r
142 glutReshapeWindow(300,300);
\r
149 if (nChildWindow==-1)
\r
151 int width = glutGet(GLUT_WINDOW_WIDTH);
\r
152 int height = glutGet(GLUT_WINDOW_HEIGHT);
\r
154 /* open child window */
\r
155 printf("open child window\n");
\r
157 nChildWindow = glutCreateSubWindow(nWindow,(int)(width*.35),(int)(height*.35),(int)(width*.3),(int)(height*.3));
\r
158 glutKeyboardFunc( SampleKeyboard );
\r
159 glutDisplayFunc( Redisplay );
\r
160 glutReshapeFunc( Reshape );
\r
161 glutPositionFunc( Position );
\r
162 glutWindowStatusFunc( WindowStatus );
\r
166 /* close child window */
\r
167 printf("close child window\n");
\r
168 glutSetWindow(nWindow);
\r
169 glutDestroyWindow(nChildWindow);
\r
171 bChildSizeDone = GL_FALSE;
\r
172 bChildPosDone = GL_FALSE;
\r
179 glutIconifyWindow();
\r
180 glutTimerFunc(1500, ChangeTitleTimer, 0);
\r
186 if (nChildWindow!=-1 && cChar=='h') /* Capital H always hides the main window*/
\r
188 glutSetWindow(nChildWindow);
\r
189 glutTimerFunc(2000, UnhideTimer, nChildWindow);
\r
193 glutSetWindow(nWindow);
\r
194 glutTimerFunc(2000, UnhideTimer, nWindow);
\r
205 glutPostRedisplay();
\r
208 void Reshape(int width, int height)
\r
210 int win = glutGetWindow();
\r
212 printf("reshape %s, client area: %dx%d\n",win==nWindow?"main":"child",
\r
215 glViewport(0,0,width,height);
\r
216 glMatrixMode(GL_PROJECTION);
\r
218 gluOrtho2D(0,width,0,height);
\r
220 if (win==nWindow && nChildWindow!=-1)
\r
222 /* Put child window in right place */
\r
223 int x = (int)(width*.35), y=(int)(height*.35), w=(int)(width*.3), h = (int)(height*.3);
\r
229 if (bChildSizeDone)
\r
234 glutSetWindow(nChildWindow);
\r
235 glutPositionWindow(x,y);
\r
236 glutReshapeWindow(w,h);
\r
237 glutSetWindow(nWindow);
\r
241 void Position(int x, int y)
\r
243 int win = glutGetWindow();
\r
245 printf("position, %s: (%d,%d)\n",win==nWindow?"top-left (non-client) of main":"top-left of child relative to parent",
\r
249 void WindowStatus(int state)
\r
251 int win = glutGetWindow();
\r
252 printf("windowstatus (win %i): %i\n",win,state);
\r
255 void Redisplay(void)
\r
257 int win = glutGetWindow();
\r
261 glClearColor(.2f,0.f,0.f,0.f);
\r
267 glClearColor(.0f,.2f,0.f,0.f);
\r
268 glColor3f(.5,.5,.5);
\r
269 glutPostWindowRedisplay(nWindow);
\r
271 glClear(GL_COLOR_BUFFER_BIT);
\r
275 glutPostWindowRedisplay(win);
\r
278 void Timer(int unused)
\r
280 int win = glutGetWindow();
\r
283 int border, caption;
\r
285 x = glutGet(GLUT_WINDOW_X);
\r
286 y = glutGet(GLUT_WINDOW_Y);
\r
287 width = glutGet(GLUT_WINDOW_WIDTH);
\r
288 height = glutGet(GLUT_WINDOW_HEIGHT);
\r
289 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
290 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
291 /* returned position is top-left of client area, to get top-left of
\r
292 * of window you'll need to add the size of the border and caption
\r
293 * of the current window (can be 0).
\r
294 * Note that the window position is not necessarily positive (e.g.
\r
295 * when the window is on a monitor to the left of the primary monitor
\r
296 * or simply when maximized--try pressing the maximize button).
\r
297 * the returned size is the size of the client area
\r
298 * Note that the top-left of a child window is relative to the
\r
299 * top-left of the client area of the parent.
\r
301 /* printf("window border: %dpx, caption: %dpx\n",border,caption); */
\r
303 printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
\r
309 printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n",
\r
313 /* (re)set the timer callback and ask glut to call it in 500 ms */
\r
314 glutTimerFunc(500, Timer, 0);
\r
318 int main(int argc, char* argv[])
\r
320 int border, caption;
\r
321 glutInit( &argc, argv );
\r
322 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE /*| GLUT_BORDERLESS*/); // do try as well with GLUT_BORDERLESS and GLUT_CAPTIONLESS
\r
323 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
\r
325 /* Get border and caption size of default window style */
\r
326 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
327 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
328 printf("default window style border: %dpx, caption: %dpx\n",border,caption);
\r
330 /* NB: The window position you request is the outer top-left of the
\r
331 * window, the client area is at a different position if the window has
\r
332 * borders and/or a title bar.
\r
334 glutInitWindowPosition(150,250);
\r
335 glutInitWindowSize(200,200);
\r
337 nWindow = glutCreateWindow("test");
\r
338 glutSetIconTitle("test icon title");
\r
339 printf("main window id: %d\n", nWindow);
\r
341 glutKeyboardFunc( SampleKeyboard );
\r
342 glutDisplayFunc( Redisplay );
\r
343 glutReshapeFunc( Reshape );
\r
344 glutPositionFunc( Position );
\r
345 glutWindowStatusFunc( WindowStatus );
\r
347 glutTimerFunc(300, Timer, 0);
\r
350 printf("glutMainLoop returned\n");
\r
352 return EXIT_SUCCESS;
\r