4 * Hey! This was the original file where freeglut development started. Just
5 * note what I have written here at the time. And see the creation date :)
7 * : This is a wrapper. I still have to figure out
8 * : how to build shared libraries under *nix :)
10 * Copyright (c) 1999 by Pawel W. Olszta
11 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
12 * Creation date: czw gru 2 11:58:41 CET 1999
22 #include <GL/freeglut.h>
24 int g_LeaveGameMode = 0;
26 int g_mainwin, g_sw1, g_sw2;
29 * Call this function to have some text drawn at given coordinates
31 void PrintText( int nX, int nY, char* pszText )
37 * Prepare the OpenGL state
39 glDisable( GL_LIGHTING );
40 glDisable( GL_DEPTH_TEST );
41 glMatrixMode( GL_PROJECTION );
46 * Have an orthogonal projection matrix set
48 glOrtho( 0, glutGet( GLUT_WINDOW_WIDTH ),
49 0, glutGet( GLUT_WINDOW_HEIGHT ),
56 glMatrixMode( GL_MODELVIEW );
63 glColor3ub( 0, 0, 0 );
64 glRasterPos2i( nX, nY );
66 for( p=pszText, lines=0; *p; p++ )
71 glRasterPos2i( nX, nY-(lines*18) );
74 glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *p );
78 * Revert to the old matrix modes
80 glMatrixMode( GL_PROJECTION );
83 glMatrixMode( GL_MODELVIEW );
87 * Restore the old OpenGL states
89 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
90 glEnable( GL_DEPTH_TEST );
91 glEnable( GL_LIGHTING );
95 * This is the display routine for our sample FreeGLUT windows
97 static float g_fTime = 0.0f;
99 void SampleDisplay( void )
101 int win = glutGetWindow();
108 glClearColor(0.7f,0.7f,0.7f,1);
109 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
110 glutPostWindowRedisplay(g_mainwin);
117 glClearColor(0.3f,0.3f,0.3f,1);
118 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
119 glutPostWindowRedisplay(g_mainwin);
126 glClearColor( 0, 0.5, 1, 1 );
127 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
130 * Have the cube rotated
132 glMatrixMode( GL_MODELVIEW );
135 glRotatef( g_fTime, 0, 0, 1 );
136 glRotatef( g_fTime, 0, 1, 0 );
137 glRotatef( g_fTime, 1, 0, 0 );
142 glColor3f( 1, 1, 0 );
143 /* glutWireCube( 20.0 ); */
144 glutWireTeapot( 20.0 );
145 /* glutWireSpher( 15.0, 15, 15 ); */
146 /* glColor3f( 0, 1, 0 ); */
147 /* glutWireCube( 30.0 ); */
148 /* glutSolidCone( 10, 20, 10, 2 ); */
151 * Don't forget about the model-view matrix
158 if( g_InGameMode == 0 )
159 PrintText( 20, 20, "Hello there cruel world!" );
161 PrintText( 20, 20, "Press ESC to leave the game mode!" );
165 * And swap this context's buffers
168 glutPostWindowRedisplay(win);
172 * This is a sample idle function
174 void SampleIdle( void )
178 if( g_LeaveGameMode == 1 )
180 glutLeaveGameMode( );
186 void SampleEntry(int state)
188 int window = glutGetWindow () ;
189 printf ( "Window %d Entry Callback: %d\n", window, state ) ;
190 glutPostRedisplay () ;
194 * The reshape function
196 void SampleReshape( int nWidth, int nHeight )
198 GLfloat fAspect = (GLfloat) nHeight / (GLfloat) nWidth;
199 GLfloat fPos[ 4 ] = { 0.0f, 0.0f, 10.0f, 0.0f };
200 GLfloat fCol[ 4 ] = { 0.5f, 1.0f, 0.0f, 1.0f };
203 * Update the viewport first
205 glViewport( 0, 0, nWidth, nHeight );
208 * Then the projection matrix
210 glMatrixMode( GL_PROJECTION );
212 glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 );
215 * Move back the camera a bit
217 glMatrixMode( GL_MODELVIEW );
219 glTranslatef( 0.0, 0.0, -40.0f );
222 * Enable some features...
224 glEnable( GL_CULL_FACE );
225 glEnable( GL_DEPTH_TEST );
226 glEnable( GL_NORMALIZE );
229 * Set up some lighting
231 glLightfv( GL_LIGHT0, GL_POSITION, fPos );
232 glEnable( GL_LIGHTING );
233 glEnable( GL_LIGHT0 );
236 * Set up a sample material
238 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fCol );
242 * A sample keyboard callback
244 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
246 printf( "SampleKeyboard(): keypress '%c' at (%i,%i)\n",
247 cChar, nMouseX, nMouseY );
251 * A sample keyboard callback (for game mode window)
253 void SampleGameModeKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
261 * A sample special callback
263 void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
265 printf( "SampleSpecial(): special keypress %i at (%i,%i)\n",
266 nSpecial, nMouseX, nMouseY );
270 * A sample menu callback
272 void SampleMenu( int menuID )
275 * Just print something funny
277 printf( "SampleMenu() callback executed, menuID is %i\n", menuID );
281 * The sample's entry point
283 int main( int argc, char** argv )
285 int menuID, subMenuA, subMenuB;
287 glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
288 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
289 glutInitWindowPosition( 100, 100 );
291 glutInit( &argc, argv );
293 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
295 subMenuA = glutCreateMenu( SampleMenu );
296 glutAddMenuEntry( "Sub menu A1 (01)", 1 );
297 glutAddMenuEntry( "Sub menu A2 (02)", 2 );
298 glutAddMenuEntry( "Sub menu A3 (03)", 3 );
300 subMenuB = glutCreateMenu( SampleMenu );
301 glutAddMenuEntry( "Sub menu B1 (04)", 4 );
302 glutAddMenuEntry( "Sub menu B2 (05)", 5 );
303 glutAddMenuEntry( "Sub menu B3 (06)", 6 );
304 glutAddSubMenu( "Going to sub menu A", subMenuA );
306 menuID = glutCreateMenu( SampleMenu );
307 glutAddMenuEntry( "Entry one", 1 );
308 glutAddMenuEntry( "Entry two", 2 );
309 glutAddMenuEntry( "Entry three", 3 );
310 glutAddMenuEntry( "Entry four", 4 );
311 glutAddMenuEntry( "Entry five", 5 );
312 glutAddSubMenu( "Enter sub menu A", subMenuA );
313 glutAddSubMenu( "Enter sub menu B", subMenuB );
315 glutCreateWindow( "Hello world!" );
316 glutDisplayFunc( SampleDisplay );
317 glutReshapeFunc( SampleReshape );
318 glutKeyboardFunc( SampleKeyboard );
319 glutSpecialFunc( SampleSpecial );
320 glutIdleFunc( SampleIdle );
321 glutEntryFunc( SampleEntry );
322 glutAttachMenu( GLUT_LEFT_BUTTON );
324 glutInitWindowPosition( 200, 200 );
325 g_mainwin = glutCreateWindow( "I am not Jan B." );
326 glutDisplayFunc( SampleDisplay );
327 glutReshapeFunc( SampleReshape );
328 glutKeyboardFunc( SampleKeyboard );
329 glutSpecialFunc( SampleSpecial );
330 glutIdleFunc( SampleIdle );
331 glutAttachMenu( GLUT_LEFT_BUTTON );
332 glutSetMenu(subMenuA);
333 glutAttachMenu( GLUT_RIGHT_BUTTON );
335 g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
336 glutDisplayFunc( SampleDisplay );
337 glutSetMenu(subMenuB);
338 glutAttachMenu( GLUT_LEFT_BUTTON);
340 g_sw2=glutCreateSubWindow(g_sw1,50,0,50,50);
341 glutDisplayFunc( SampleDisplay );
343 glutAttachMenu( GLUT_RIGHT_BUTTON );
345 printf( "Testing game mode string parsing, don't panic!\n" );
346 glutGameModeString( "320x240:32@100" );
347 glutGameModeString( "640x480:16@72" );
348 glutGameModeString( "1024x768" );
349 glutGameModeString( ":32@120" );
350 glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );
352 glutGameModeString( "640x480:37@300" ); /* this one should fail */
355 glutGameModeString( "800x600" ); /* this one is likely to succeed */
358 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
360 glutDisplayFunc( SampleDisplay );
361 glutReshapeFunc( SampleReshape );
362 glutKeyboardFunc( SampleGameModeKeyboard );
363 glutIdleFunc( SampleIdle );
365 printf( "current window is %ix%i at (%i,%i)\n",
366 glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
367 glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y )
371 * Enter the main FreeGLUT processing loop
375 printf( "glutMainLoop() termination works fine!\n" );
378 * This is never reached in FreeGLUT. Is that good?
383 /*** END OF FILE ***/