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);
106 if (win == mainwin) {
107 shapesPrintf (2, 3, "Move The mounse into different windows");
108 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]);
118 key(unsigned char key, int x, int y)
121 int win = glutGetWindow();
127 case 'q': glutLeaveMainLoop () ; break;
131 if (strlen(s)+1>MAXSTR) {
143 static void special (int key, int x, int y)
157 int win = glutGetWindow();
158 printf("Win: %d, state: %d\n",win,state);
161 /* Program entry point */
164 main(int argc, char *argv[])
166 int winmax,sw1,sw2,i;
168 glutInitWindowSize(640,480);
169 glutInitWindowPosition(40,40);
170 glutInit(&argc, argv);
171 glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
173 glutCreateWindow("OpenGLUT Sub Windows");
175 glutReshapeFunc(resize);
176 glutDisplayFunc(display);
177 glutKeyboardFunc(key);
178 glutSpecialFunc(special);
179 glutEntryFunc(entry);
181 glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;
183 glClearColor(1,1,1,1);
185 mainwin = glutGetWindow();
188 sw1=glutCreateSubWindow(mainwin,4,240,314,236);
189 glutReshapeFunc(resize);
190 glutDisplayFunc(display);
191 glutKeyboardFunc(key);
192 glutSpecialFunc(special);
193 glutEntryFunc(entry);
194 glClearColor(0.7f,0.7f,0.7f,1);
195 winmax = sw1 > winmax ? sw1 : winmax;
197 sw2=glutCreateSubWindow(mainwin,328,240,314,236);
198 glutReshapeFunc(resize);
199 glutDisplayFunc(display);
200 glutKeyboardFunc(key);
201 glutSpecialFunc(special);
202 glutEntryFunc(entry);
203 glClearColor(0.7f,0.7f,0.7f,1);
204 winmax = sw2 > winmax ? sw2 : winmax;
206 strings = malloc(sizeof(char *)*(winmax+1));
207 for (i=0;i<winmax+1;i++) {
208 strings[i] = malloc(sizeof(char)*MAXSTR+1);
215 /* DUMP MEMORY LEAK INFORMATION */
216 _CrtDumpMemoryLeaks () ;