4 This program is a test harness for the subwindows
5 in OpenGLUT. Based Originally on shape.c demo.
7 \author Written by Evan Felix February 2011
9 \author Portions Copyright (C) 2004, the OpenGLUT project contributors. <br>
10 OpenGLUT branched from freeglut in February, 2004.
12 \image html openglut_subwin.png OpenGLUT Sub Window Demonstration
13 \include demos/subwin/subwin.c
16 #include <GL/freeglut.h>
23 /* DUMP MEMORY LEAKS */
33 Does printf()-like work using freeglut/OpenGLUT
34 glutBitmapString(). Uses a fixed font. Prints
35 at the indicated row/column position.
37 Limitation: Cannot address pixels.
38 Limitation: Renders in screen coords, not model coords.
40 static void shapesPrintf (int row, int col, const char *fmt, ...)
44 void *font = GLUT_BITMAP_9_BY_15;
48 #if defined(WIN32) && !defined(__CYGWIN__)
49 (void) _vsnprintf (buf, sizeof(buf), fmt, args);
51 (void) vsnprintf (buf, sizeof(buf), fmt, args);
55 glGetIntegerv(GL_VIEWPORT,viewport);
60 glMatrixMode(GL_PROJECTION);
64 glOrtho(0,viewport[2],0,viewport[3],-1,1);
68 glutBitmapWidth(font, ' ') * col,
69 - glutBitmapHeight(font) * (row+2) + viewport[3]
71 glutBitmapString (font, (unsigned char*)buf);
74 glMatrixMode(GL_MODELVIEW);
78 /* GLUT callback Handlers */
81 resize(int width, int height)
84 glViewport(0, 0, width, height);
86 glMatrixMode(GL_PROJECTION);
88 /*gluOrtho2D(0, width, 0, height);*/
90 glMatrixMode(GL_MODELVIEW);
94 static void display(void)
97 int win = glutGetWindow();
99 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
103 glDisable(GL_LIGHTING);
104 glColor3d(0.1,0.1,0.4);
108 shapesPrintf (2, 3, "Move The mouse into different windows");
109 shapesPrintf (3, 3, "pressing keys will add to the string");
110 shapesPrintf (5, 3, "Window: %d", win);
111 shapesPrintf (6, 3, "String: %s", strings[win]);
115 shapesPrintf (1, 3, "Window: %d", win);
116 shapesPrintf (2, 3, "String: %s", strings[win]);
\r
124 key(unsigned char key, int x, int y)
127 int win = glutGetWindow();
133 case 'q': glutLeaveMainLoop () ; break;
137 if (strlen(s)+1>MAXSTR) {
149 static void special (int key, int x, int y)
163 int win = glutGetWindow();
164 printf("Win: %d, state: %d\n",win,state);
167 /* Program entry point */
170 main(int argc, char *argv[])
172 int winmax,sw1,sw2,sw2sw,i;
174 glutInitWindowSize(640,480);
175 glutInitWindowPosition(40,40);
176 glutInit(&argc, argv);
177 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
179 glutCreateWindow("FreeGLUT Sub Windows");
181 glutReshapeFunc(resize);
182 glutDisplayFunc(display);
183 glutKeyboardFunc(key);
184 glutSpecialFunc(special);
185 glutEntryFunc(entry);
187 glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;
189 glClearColor(1,1,1,1);
191 mainwin = glutGetWindow();
194 sw1=glutCreateSubWindow(mainwin,4,240,314,236);
195 glutReshapeFunc(resize);
196 glutDisplayFunc(display);
197 glutKeyboardFunc(key);
198 glutSpecialFunc(special);
199 glutEntryFunc(entry);
200 glClearColor(0.7f,0.7f,0.7f,1);
201 winmax = sw1 > winmax ? sw1 : winmax;
203 sw2=glutCreateSubWindow(mainwin,322,240,314,236);
204 glutReshapeFunc(resize);
205 glutDisplayFunc(display);
206 glutKeyboardFunc(key);
207 glutSpecialFunc(special);
208 glutEntryFunc(entry);
209 glClearColor(0.7f,0.7f,0.7f,1);
210 winmax = sw2 > winmax ? sw2 : winmax;
212 sw2sw=glutCreateSubWindow(sw2,10,128,294,98);
213 glutReshapeFunc(resize);
214 glutDisplayFunc(display);
215 glutKeyboardFunc(key);
216 glutSpecialFunc(special);
217 glutEntryFunc(entry);
218 glClearColor(0.4f,0.4f,0.4f,1);
219 winmax = sw2sw > winmax ? sw2sw : winmax;
221 strings = malloc(sizeof(char *)*(winmax+1));
222 for (i=0;i<winmax+1;i++) {
223 strings[i] = malloc(sizeof(char)*MAXSTR+1);
230 /* DUMP MEMORY LEAK INFORMATION */
231 _CrtDumpMemoryLeaks () ;