3 #include <GL/freeglut.h>
\r
5 int nWindow, nChildWindow = -1;
\r
11 GLboolean bChildPosDone = GL_FALSE, bChildSizeDone = GL_FALSE;
\r
13 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY );
\r
15 void Reshape(int width, int height);
\r
16 void Position(int x, int y);
\r
23 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
24 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
27 glVertex2d(nWidth*.25, nHeight*.75);
\r
28 glVertex2d(nWidth*.75, nHeight*.75);
\r
29 glVertex2d(nWidth*.75, nHeight*.25);
\r
30 glVertex2d(nWidth*.25, nHeight*.25);
\r
34 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
\r
39 glutLeaveMainLoop();
\r
46 printf("main window toggle fullscreen\n");
\r
47 glutFullScreenToggle();
\r
54 if (nChildWindow!=-1 && cChar=='r') /* Capital R always resizes the main window*/
\r
56 glutSetWindow(nChildWindow);
\r
57 printf("child window resize\n");
\r
58 if (!bChildSizeDone)
\r
59 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)+50,glutGet(GLUT_WINDOW_HEIGHT)+50);
\r
61 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)-50,glutGet(GLUT_WINDOW_HEIGHT)-50);
\r
62 bChildSizeDone = !bChildSizeDone;
\r
66 glutSetWindow(nWindow);
\r
67 printf("main window resize\n");
\r
69 glutReshapeWindow(600,300);
\r
71 glutReshapeWindow(300,300);
\r
79 if (nChildWindow!=-1 && cChar=='m') /* Capital M always moves the main window*/
\r
81 glutSetWindow(nChildWindow);
\r
82 /* The window position you request is relative to the top-left
\r
83 * corner of the client area of the parent window.
\r
86 glutPositionWindow(glutGet(GLUT_WINDOW_X)+50,glutGet(GLUT_WINDOW_Y)+50);
\r
88 glutPositionWindow(glutGet(GLUT_WINDOW_X)-50,glutGet(GLUT_WINDOW_Y)-50);
\r
89 bChildPosDone = !bChildPosDone;
\r
93 glutSetWindow(nWindow);
\r
94 printf("main window position\n");
\r
95 /* The window position you request is the outer top-left of the window,
\r
96 * the client area is at a different position if the window has borders
\r
97 * and/or a title bar.
\r
100 glutPositionWindow(600,300);
\r
102 glutPositionWindow(300,300);
\r
110 if (nChildWindow==-1)
\r
112 /* open child window */
\r
113 printf("open child window\n");
\r
114 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
115 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
117 nChildWindow = glutCreateSubWindow(nWindow,(int)(nWidth*.35),(int)(nHeight*.35),(int)(nWidth*.3),(int)(nHeight*.3));
\r
118 glutKeyboardFunc( SampleKeyboard );
\r
119 glutDisplayFunc( Redisplay );
\r
120 glutReshapeFunc( Reshape );
\r
121 glutPositionFunc( Position );
\r
125 /* close child window */
\r
126 printf("close child window\n");
\r
127 glutSetWindow(nWindow);
\r
128 glutDestroyWindow(nChildWindow);
\r
130 bChildSizeDone = GL_FALSE;
\r
131 bChildPosDone = GL_FALSE;
\r
143 glutPostRedisplay();
\r
146 void Reshape(int width, int height)
\r
148 int win = glutGetWindow();
\r
150 printf("reshape %s, %dx%d\n",win==nWindow?"main":"child",
\r
153 glViewport(0,0,width,height);
\r
154 glMatrixMode(GL_PROJECTION);
\r
156 gluOrtho2D(0,width,0,height);
\r
158 if (win==nWindow && nChildWindow!=-1)
\r
160 glutSetWindow(nChildWindow);
\r
161 glutPositionWindow((int)(width*.35),(int)(height*.35));
\r
162 glutReshapeWindow((int)(width*.3),(int)(height*.3));
\r
163 glutSetWindow(nWindow);
\r
167 void Position(int x, int y)
\r
169 int win = glutGetWindow();
\r
171 printf("position %s, %dx%d\n",win==nWindow?"main":"child",
\r
175 void Redisplay(void)
\r
177 int win = glutGetWindow();
\r
181 glClearColor(.2f,0.f,0.f,0.f);
\r
187 glClearColor(.0f,.2f,0.f,0.f);
\r
188 glColor3f(.5,.5,.5);
\r
189 glutPostWindowRedisplay(nWindow);
\r
191 glClear(GL_COLOR_BUFFER_BIT);
\r
195 glutPostWindowRedisplay(win);
\r
198 void Timer(int unused)
200 int win = glutGetWindow();
201 int border, caption;
\r
203 nPosX = glutGet(GLUT_WINDOW_X);
\r
204 nPosY = glutGet(GLUT_WINDOW_Y);
\r
205 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
206 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
207 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
208 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
209 /* returned position is top-left of client area, to get top-left of
\r
210 * of window you'll need to add the size of the border and caption
\r
211 * of the current window (can be 0).
\r
212 * Note that the window position is not necessarily positive (e.g.
\r
213 * when the window is on a monitor to the left of the primary monitor
\r
214 * or simply when maximized--try pressing the maximize button).
\r
215 * the returned size is the size of the client area
\r
216 * Note that the top-left of a child window is relative to the
\r
217 * top-left of the client area of the parent.
\r
219 /* printf("window border: %dpx, caption: %dpx\n",border,caption); */
\r
221 printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
\r
225 nPosY-border-caption);
\r
227 printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n",
\r
231 /* (re)set the timer callback and ask glut to call it in 1 second */
232 glutTimerFunc(300, Timer, 0);
236 int main(int argc, char* argv[])
\r
238 int border, caption;
\r
239 glutInit( &argc, argv );
\r
240 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE /*| GLUT_BORDERLESS*/); // do try as well with GLUT_BORDERLESS and GLUT_CAPTIONLESS
\r
241 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
\r
243 /* Get border and caption size of default window style */
\r
244 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
245 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
246 printf("default window style border: %dpx, caption: %dpx\n",border,caption);
\r
248 /* NB: The window position you request is the outer top-left of the
\r
249 * window, the client area is at a different position if the window has
\r
250 * borders and/or a title bar.
\r
252 glutInitWindowPosition(150,250);
\r
253 glutInitWindowSize(200,200);
\r
255 nWindow = glutCreateWindow("test");
\r
256 printf("main window id: %d\n", nWindow);
\r
258 glutKeyboardFunc( SampleKeyboard );
\r
259 glutDisplayFunc( Redisplay );
\r
260 glutReshapeFunc( Reshape );
\r
261 glutPositionFunc( Position );
\r
263 glutTimerFunc(300, Timer, 0);
\r
266 printf("glutMainLoop returned\n");
\r
268 return EXIT_SUCCESS;
\r