--- /dev/null
+/*! \file subwin.c
+ \ingroup demos
+
+ This program is a test harness for the subwindows
+ in OpenGLUT. Based Originally on shape.c demo.
+
+ \author Written by Evan Felix February 2011
+
+ \author Portions Copyright (C) 2004, the OpenGLUT project contributors. <br>
+ OpenGLUT branched from freeglut in February, 2004.
+
+ \image html openglut_subwin.png OpenGLUT Sub Window Demonstration
+ \include demos/subwin/subwin.c
+*/
+
+#include <GL/freeglut.h>
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#ifdef _MSC_VER
+/* DUMP MEMORY LEAKS */
+#include <crtdbg.h>
+#endif
+
+#define MAXSTR 16
+char **strings;
+int mainwin;
+
+
+/*!
+ Does printf()-like work using freeglut/OpenGLUT
+ glutBitmapString(). Uses a fixed font. Prints
+ at the indicated row/column position.
+
+ Limitation: Cannot address pixels.
+ Limitation: Renders in screen coords, not model coords.
+*/
+static void shapesPrintf (int row, int col, const char *fmt, ...)
+{
+ static char buf[256];
+ int viewport[4];
+ void *font = GLUT_BITMAP_9_BY_15;
+ va_list args;
+
+ va_start(args, fmt);
+#if defined(WIN32) && !defined(__CYGWIN__)
+ (void) _vsnprintf (buf, sizeof(buf), fmt, args);
+#else
+ (void) vsnprintf (buf, sizeof(buf), fmt, args);
+#endif
+ va_end(args);
+
+ glGetIntegerv(GL_VIEWPORT,viewport);
+
+ glPushMatrix();
+ glLoadIdentity();
+
+ glMatrixMode(GL_PROJECTION);
+ glPushMatrix();
+ glLoadIdentity();
+
+ glOrtho(0,viewport[2],0,viewport[3],-1,1);
+
+ glRasterPos2i
+ (
+ glutBitmapWidth(font, ' ') * col,
+ - glutBitmapHeight(font) * (row+2) + viewport[3]
+ );
+ glutBitmapString (font, (unsigned char*)buf);
+
+ glPopMatrix();
+ glMatrixMode(GL_MODELVIEW);
+ glPopMatrix();
+}
+
+/* GLUT callback Handlers */
+
+static void
+resize(int width, int height)
+{
+
+ glViewport(0, 0, width, height);
+
+ glMatrixMode(GL_PROJECTION);
+ glLoadIdentity();
+ //gluOrtho2D(0, width, 0, height);
+
+ glMatrixMode(GL_MODELVIEW);
+ glLoadIdentity() ;
+}
+
+static void display(void)
+{
+
+ int win = glutGetWindow();
+
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glColor3d(1,0,0);
+
+ glDisable(GL_LIGHTING);
+ glColor3d(0.1,0.1,0.4);
+
+ if (win == mainwin) {
+ shapesPrintf (2, 3, "Move The mounse into different windows");
+ shapesPrintf (3, 3, "pressing keys will add to the string");
+ }
+ shapesPrintf (5, 3, "Window: %d", win);
+ shapesPrintf (6, 3, "String: %s", strings[win]);
+
+ glutSwapBuffers();
+}
+
+
+static void
+key(unsigned char key, int x, int y)
+{
+ char *s,str[2];
+ int win = glutGetWindow();
+
+ switch (key)
+ {
+ case 27 :
+ case 'Q':
+ case 'q': glutLeaveMainLoop () ; break;
+
+ default:
+ s=strings[win];
+ if (strlen(s)+1>MAXSTR) {
+ s[0]=0;
+ }
+ str[0]=key;
+ str[1]=0;
+ strcat(s,str);
+ break;
+ }
+
+ glutPostRedisplay();
+}
+
+static void special (int key, int x, int y)
+{
+ switch (key)
+ {
+ default:
+ break;
+ }
+ glutPostRedisplay();
+}
+
+
+static void
+entry(int state)
+{
+ int win = glutGetWindow();
+ printf("Win: %d, state: %d\n",win,state);
+}
+
+/* Program entry point */
+
+int
+main(int argc, char *argv[])
+{
+ int winmax,sw1,sw2,i;
+
+ glutInitWindowSize(640,480);
+ glutInitWindowPosition(40,40);
+ glutInit(&argc, argv);
+ glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE);
+
+ glutCreateWindow("OpenGLUT Sub Windows");
+
+ glutReshapeFunc(resize);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(key);
+ glutSpecialFunc(special);
+ glutEntryFunc(entry);
+
+ glutSetOption ( GLUT_ACTION_ON_WINDOW_CLOSE, GLUT_ACTION_CONTINUE_EXECUTION ) ;
+
+ glClearColor(1,1,1,1);
+
+ mainwin = glutGetWindow();
+ winmax=mainwin;
+
+ sw1=glutCreateSubWindow(mainwin,4,240,314,236);
+ glutReshapeFunc(resize);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(key);
+ glutSpecialFunc(special);
+ glutEntryFunc(entry);
+ glClearColor(0.7,0.7,0.7,1);
+ winmax = sw1 > winmax ? sw1 : winmax;
+
+ sw2=glutCreateSubWindow(mainwin,328,240,314,236);
+ glutReshapeFunc(resize);
+ glutDisplayFunc(display);
+ glutKeyboardFunc(key);
+ glutSpecialFunc(special);
+ glutEntryFunc(entry);
+ glClearColor(0.7,0.7,0.7,1);
+ winmax = sw2 > winmax ? sw2 : winmax;
+
+ strings = malloc(sizeof(char *)*(winmax+1));
+ for (i=0;i<winmax+1;i++) {
+ strings[i] = malloc(sizeof(char)*MAXSTR+1);
+ strings[i][0]=0;
+ }
+
+ glutMainLoop();
+
+#ifdef _MSC_VER
+ /* DUMP MEMORY LEAK INFORMATION */
+ _CrtDumpMemoryLeaks () ;
+#endif
+
+ return EXIT_SUCCESS;
+}
--- /dev/null
+# Microsoft Developer Studio Project File - Name="subwin" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=subwin - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "subwin.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "subwin.mak" CFG="subwin - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "subwin - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "subwin - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "subwin - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /I "../../../include" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386 /libpath:"../../../Release"
+
+!ELSEIF "$(CFG)" == "subwin - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /I "../../../include" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept /libpath:"../../../Debug"
+
+!ENDIF
+
+# Begin Target
+
+# Name "subwin - Win32 Release"
+# Name "subwin - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\subwin.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project