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;
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, 0.5, 1, 1 );
118 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
121 * Have the cube rotated
123 glMatrixMode( GL_MODELVIEW );
126 glRotatef( g_fTime, 0, 0, 1 );
127 glRotatef( g_fTime, 0, 1, 0 );
128 glRotatef( g_fTime, 1, 0, 0 );
133 glColor3f( 1, 1, 0 );
134 /* glutWireCube( 20.0 ); */
135 glutWireTeapot( 20.0 );
136 /* glutWireSpher( 15.0, 15, 15 ); */
137 /* glColor3f( 0, 1, 0 ); */
138 /* glutWireCube( 30.0 ); */
139 /* glutSolidCone( 10, 20, 10, 2 ); */
142 * Don't forget about the model-view matrix
149 if( g_InGameMode == 0 )
150 PrintText( 20, 20, "Hello there cruel world!" );
152 PrintText( 20, 20, "Press ESC to leave the game mode!" );
156 * And swap this context's buffers
159 glutPostWindowRedisplay(win);
163 * This is a sample idle function
165 void SampleIdle( void )
169 if( g_LeaveGameMode == 1 )
171 glutLeaveGameMode( );
177 void SampleEntry(int state)
179 int window = glutGetWindow () ;
180 printf ( "Window %d Entry Callback: %d\n", window, state ) ;
181 glutPostRedisplay () ;
185 * The reshape function
187 void SampleReshape( int nWidth, int nHeight )
189 GLfloat fAspect = (GLfloat) nHeight / (GLfloat) nWidth;
190 GLfloat fPos[ 4 ] = { 0.0f, 0.0f, 10.0f, 0.0f };
191 GLfloat fCol[ 4 ] = { 0.5f, 1.0f, 0.0f, 1.0f };
194 * Update the viewport first
196 glViewport( 0, 0, nWidth, nHeight );
199 * Then the projection matrix
201 glMatrixMode( GL_PROJECTION );
203 glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 );
206 * Move back the camera a bit
208 glMatrixMode( GL_MODELVIEW );
210 glTranslatef( 0.0, 0.0, -40.0f );
213 * Enable some features...
215 glEnable( GL_CULL_FACE );
216 glEnable( GL_DEPTH_TEST );
217 glEnable( GL_NORMALIZE );
220 * Set up some lighting
222 glLightfv( GL_LIGHT0, GL_POSITION, fPos );
223 glEnable( GL_LIGHTING );
224 glEnable( GL_LIGHT0 );
227 * Set up a sample material
229 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fCol );
233 * A sample keyboard callback
235 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
237 printf( "SampleKeyboard(): keypress '%c' at (%i,%i)\n",
238 cChar, nMouseX, nMouseY );
242 * A sample keyboard callback (for game mode window)
244 void SampleGameModeKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
252 * A sample special callback
254 void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
256 printf( "SampleSpecial(): special keypress %i at (%i,%i)\n",
257 nSpecial, nMouseX, nMouseY );
261 * A sample menu callback
263 void SampleMenu( int menuID )
266 * Just print something funny
268 printf( "SampleMenu() callback executed, menuID is %i\n", menuID );
272 * The sample's entry point
274 int main( int argc, char** argv )
276 int menuID, subMenuA, subMenuB;
278 glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
279 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
280 glutInitWindowPosition( 100, 100 );
282 glutInit( &argc, argv );
284 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
286 subMenuA = glutCreateMenu( SampleMenu );
287 glutAddMenuEntry( "Sub menu A1 (01)", 1 );
288 glutAddMenuEntry( "Sub menu A2 (02)", 2 );
289 glutAddMenuEntry( "Sub menu A3 (03)", 3 );
291 subMenuB = glutCreateMenu( SampleMenu );
292 glutAddMenuEntry( "Sub menu B1 (04)", 4 );
293 glutAddMenuEntry( "Sub menu B2 (05)", 5 );
294 glutAddMenuEntry( "Sub menu B3 (06)", 6 );
295 glutAddSubMenu( "Going to sub menu A", subMenuA );
297 menuID = glutCreateMenu( SampleMenu );
298 glutAddMenuEntry( "Entry one", 1 );
299 glutAddMenuEntry( "Entry two", 2 );
300 glutAddMenuEntry( "Entry three", 3 );
301 glutAddMenuEntry( "Entry four", 4 );
302 glutAddMenuEntry( "Entry five", 5 );
303 glutAddSubMenu( "Enter sub menu A", subMenuA );
304 glutAddSubMenu( "Enter sub menu B", subMenuB );
306 glutCreateWindow( "Hello world!" );
307 glutDisplayFunc( SampleDisplay );
308 glutReshapeFunc( SampleReshape );
309 glutKeyboardFunc( SampleKeyboard );
310 glutSpecialFunc( SampleSpecial );
311 glutIdleFunc( SampleIdle );
312 glutEntryFunc( SampleEntry );
313 glutAttachMenu( GLUT_LEFT_BUTTON );
315 glutInitWindowPosition( 200, 200 );
316 g_mainwin = glutCreateWindow( "I am not Jan B." );
317 glutDisplayFunc( SampleDisplay );
318 glutReshapeFunc( SampleReshape );
319 glutKeyboardFunc( SampleKeyboard );
320 glutSpecialFunc( SampleSpecial );
321 glutIdleFunc( SampleIdle );
322 glutAttachMenu( GLUT_LEFT_BUTTON );
323 glutSetMenu(subMenuA);
324 glutAttachMenu( GLUT_RIGHT_BUTTON);
326 g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
327 glutDisplayFunc( SampleDisplay );
328 glutSetMenu(subMenuB);
329 glutAttachMenu( GLUT_LEFT_BUTTON);
331 printf( "Testing game mode string parsing, don't panic!\n" );
332 glutGameModeString( "320x240:32@100" );
333 glutGameModeString( "640x480:16@72" );
334 glutGameModeString( "1024x768" );
335 glutGameModeString( ":32@120" );
336 glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );
338 glutGameModeString( "640x480:37@300" ); /* this one should fail */
341 glutGameModeString( "800x600" ); /* this one is likely to succeed */
344 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
346 glutDisplayFunc( SampleDisplay );
347 glutReshapeFunc( SampleReshape );
348 glutKeyboardFunc( SampleGameModeKeyboard );
349 glutIdleFunc( SampleIdle );
351 printf( "current window is %ix%i at (%i,%i)\n",
352 glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
353 glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y )
357 * Enter the main FreeGLUT processing loop
361 printf( "glutMainLoop() termination works fine!\n" );
364 * This is never reached in FreeGLUT. Is that good?
369 /*** END OF FILE ***/