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 x, int y);
\r
22 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
23 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
26 glVertex2d(nWidth*.25, nHeight*.75);
\r
27 glVertex2d(nWidth*.75, nHeight*.75);
\r
28 glVertex2d(nWidth*.75, nHeight*.25);
\r
29 glVertex2d(nWidth*.25, nHeight*.25);
\r
33 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
\r
38 glutLeaveMainLoop();
\r
45 printf("main window toggle fullscreen\n");
\r
46 glutFullScreenToggle();
\r
53 if (nChildWindow!=-1)
\r
55 glutSetWindow(nChildWindow);
\r
56 printf("child window resize\n");
\r
57 if (!bChildSizeDone)
\r
58 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)+50,glutGet(GLUT_WINDOW_HEIGHT)+50);
\r
60 glutReshapeWindow(glutGet(GLUT_WINDOW_WIDTH)-50,glutGet(GLUT_WINDOW_HEIGHT)-50);
\r
61 bChildSizeDone = !bChildSizeDone;
\r
65 printf("main window resize\n");
\r
67 glutReshapeWindow(600,300);
\r
69 glutReshapeWindow(300,300);
\r
77 if (nChildWindow!=-1)
\r
79 glutSetWindow(nChildWindow);
\r
81 /* The window position you request is relative to the top-left
\r
82 * corner of the client area of the parent window.
\r
85 glutPositionWindow(glutGet(GLUT_WINDOW_X)+50,glutGet(GLUT_WINDOW_Y)+50);
\r
87 glutPositionWindow(glutGet(GLUT_WINDOW_X)-50,glutGet(GLUT_WINDOW_Y)-50);
\r
88 bChildPosDone = !bChildPosDone;
\r
92 printf("main window position\n");
\r
94 /* The window position you request is the outer top-left of the window,
\r
95 * the client area is at a different position if the window has borders
\r
96 * and/or a title bar.
\r
99 glutPositionWindow(600,300);
\r
101 glutPositionWindow(300,300);
\r
109 if (nChildWindow==-1)
\r
111 /* open child window */
\r
112 printf("open child window\n");
\r
113 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
114 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
116 nChildWindow = glutCreateSubWindow(nWindow,(int)(nWidth*.35),(int)(nHeight*.35),(int)(nWidth*.3),(int)(nHeight*.3));
\r
117 glutKeyboardFunc( SampleKeyboard );
\r
118 glutDisplayFunc( Redisplay );
\r
119 glutReshapeFunc( Reshape );
\r
123 /* close child window */
\r
124 printf("close child window\n");
\r
125 glutSetWindow(nWindow);
\r
126 glutDestroyWindow(nChildWindow);
\r
128 bChildSizeDone = GL_FALSE;
\r
129 bChildPosDone = GL_FALSE;
\r
141 glutPostRedisplay();
\r
144 void Reshape(int x, int y)
\r
146 int win = glutGetWindow();
\r
148 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
149 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
150 printf("reshape %s, %dx%d\n",win==nWindow?"main":"child",
\r
153 glViewport(0,0,nWidth,nHeight);
\r
154 glMatrixMode(GL_PROJECTION);
\r
156 gluOrtho2D(0,nWidth,0,nHeight);
\r
158 if (win==nWindow && nChildWindow!=-1)
\r
160 glutSetWindow(nChildWindow);
\r
161 glutPositionWindow((int)(nWidth*.35),(int)(nHeight*.35));
\r
162 glutReshapeWindow((int)(nWidth*.3),(int)(nHeight*.3));
\r
163 glutSetWindow(nWindow);
\r
167 void Redisplay(void)
\r
169 int win = glutGetWindow();
\r
171 if (nLoopMain++%20==0)
\r
173 int border, caption;
\r
175 nPosX = glutGet(GLUT_WINDOW_X);
\r
176 nPosY = glutGet(GLUT_WINDOW_Y);
\r
177 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
178 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
179 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
180 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
181 /* returned position is top-left of client area, to get top-left of
\r
182 * of window you'll need to add the size of the border and caption
\r
183 * of the current window (can be 0).
\r
184 * Note that the window position is not necessarily positive (e.g.
\r
185 * when the window is on a monitor to the left of the primary monitor
\r
186 * or simply when maximized--try pressing the maximize button).
\r
187 * the returned size is the size of the client area
\r
188 * Note that the top-left of a child window is relative to the
\r
189 * top-left of the client area of the parent.
\r
191 /* printf("window border: %dpx, caption: %dpx\n",border,caption); */
\r
193 printf("main window %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
\r
197 nPosY-border-caption);
\r
199 printf("child window %dx%d, top-left of client at: (%d,%d), relative to parent\n",
\r
206 glClearColor(.2f,0.f,0.f,0.f);
\r
212 glClearColor(.0f,.2f,0.f,0.f);
\r
213 glColor3f(.5,.5,.5);
\r
214 glutPostWindowRedisplay(nWindow);
\r
216 glClear(GL_COLOR_BUFFER_BIT);
\r
220 glutPostWindowRedisplay(win);
\r
224 int main(int argc, char* argv[])
\r
226 int border, caption;
\r
227 glutInit( &argc, argv );
\r
228 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE /*| GLUT_BORDERLESS*/); // do try as well with GLUT_BORDERLESS and GLUT_CAPTIONLESS
\r
229 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
\r
231 /* Get border and caption size of default window style */
\r
232 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
233 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
234 printf("default window style border: %dpx, caption: %dpx\n",border,caption);
\r
236 /* NB: The window position you request is the outer top-left of the
\r
237 * window, the client area is at a different position if the window has
\r
238 * borders and/or a title bar.
\r
240 glutInitWindowPosition(150,250);
\r
241 glutInitWindowSize(200,200);
\r
243 nWindow = glutCreateWindow("test");
\r
244 printf("main window id: %d\n", nWindow);
\r
246 glutKeyboardFunc( SampleKeyboard );
\r
247 glutDisplayFunc( Redisplay );
\r
248 glutReshapeFunc( Reshape );
\r
251 printf("glutMainLoop returned\n");
\r
253 return EXIT_SUCCESS;
\r