3 #include <GL/freeglut.h>
\r
11 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY );
\r
21 glVertex2d(nWidth*.25, nHeight*.75);
\r
22 glVertex2d(nWidth*.75, nHeight*.75);
\r
23 glVertex2d(nWidth*.75, nHeight*.25);
\r
24 glVertex2d(nWidth*.25, nHeight*.25);
\r
28 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
\r
31 glutLeaveMainLoop();
\r
33 else if (cChar=='f')
\r
35 printf("main window toggle fullscreen\n");
\r
37 glutFullScreenToggle();
\r
39 else if (cChar=='r')
\r
41 printf("main window resize\n");
\r
44 glutReshapeWindow(600,300);
\r
46 glutReshapeWindow(300,300);
\r
48 else if (cChar=='m')
\r
50 printf("main window position\n");
\r
52 /* The window position you request is the outer top-left of the window,
\r
53 * the client area is at a different position if the window has borders
\r
54 * and/or a title bar.
\r
57 glutPositionWindow(600,300);
\r
59 glutPositionWindow(300,300);
\r
65 glutPostRedisplay();
\r
68 void Reshape(int x, int y)
\r
70 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
71 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
73 glViewport(0,0,nWidth,nHeight);
\r
74 glMatrixMode(GL_PROJECTION);
\r
76 gluOrtho2D(0,nWidth,0,nHeight);
\r
79 void Redisplay(void)
\r
81 if (nLoopMain++%6==0)
\r
83 int border, caption;
\r
85 nPosX = glutGet(GLUT_WINDOW_X);
\r
86 nPosY = glutGet(GLUT_WINDOW_Y);
\r
87 nWidth = glutGet(GLUT_WINDOW_WIDTH);
\r
88 nHeight = glutGet(GLUT_WINDOW_HEIGHT);
\r
89 border = glutGet(GLUT_WINDOW_BORDER_WIDTH);
\r
90 caption = glutGet(GLUT_WINDOW_HEADER_HEIGHT);
\r
91 /* returned position is top-left of client area, to get top-left of
\r
92 * of window you'll need to add the size of the border and caption
\r
93 * of the current window (can be 0).
\r
94 * Note that the window position is not necessarily positive (e.g.
\r
95 * when the window is on a monitor to the left of the primary monitor
\r
96 * or simply when maximized--try pressing the maximize button).
\r
97 * the returned size is the size of the client area
\r
99 printf("window now %dx%d, top-left of client at: (%d,%d), of window at: (%d,%d)\n",
\r
103 nPosY-border-caption);
\r
106 glClearColor(.2f,0.f,0.f,0.f);
\r
107 glClear(GL_COLOR_BUFFER_BIT);
\r
112 glutPostRedisplay();
\r
116 int main(int argc, char* argv[])
\r
118 glutInit( &argc, argv );
\r
119 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE /*| GLUT_BORDERLESS*/); // do try as well with GLUT_BORDERLESS and GLUT_CAPTIONLESS
\r
120 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
\r
122 /* The window position you request is the outer top-left of the window,
\r
123 * the client area is at a different position if the window has borders
\r
124 * and/or a title bar.
\r
126 glutInitWindowPosition(150,250);
\r
127 glutInitWindowSize(200,200);
\r
129 nWindow = glutCreateWindow("test");
\r
130 printf("main window id: %d\n", nWindow);
\r
132 glutKeyboardFunc( SampleKeyboard );
\r
133 glutDisplayFunc( Redisplay );
\r
134 glutReshapeFunc( Reshape );
\r
137 printf("glutMainLoop returned\n");
\r