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;
28 * Call this function to have some text drawn at given coordinates
30 void PrintText( int nX, int nY, char* pszText )
36 * Prepare the OpenGL state
38 glDisable( GL_LIGHTING );
39 glDisable( GL_DEPTH_TEST );
40 glMatrixMode( GL_PROJECTION );
45 * Have an orthogonal projection matrix set
47 glOrtho( 0, glutGet( GLUT_WINDOW_WIDTH ),
48 0, glutGet( GLUT_WINDOW_HEIGHT ),
55 glMatrixMode( GL_MODELVIEW );
62 glColor3ub( 0, 0, 0 );
63 glRasterPos2i( nX, nY );
65 for( p=pszText, lines=0; *p; p++ )
70 glRasterPos2i( nX, nY-(lines*18) );
73 glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *p );
77 * Revert to the old matrix modes
79 glMatrixMode( GL_PROJECTION );
82 glMatrixMode( GL_MODELVIEW );
86 * Restore the old OpenGL states
88 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
89 glEnable( GL_DEPTH_TEST );
90 glEnable( GL_LIGHTING );
94 * This is the display routine for our sample FreeGLUT windows
96 static float g_fTime = 0.0f;
98 void SampleDisplay( void )
103 glClearColor( 0, 0.5, 1, 1 );
104 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
107 * Have the cube rotated
109 glMatrixMode( GL_MODELVIEW );
112 glRotatef( g_fTime, 0, 0, 1 );
113 glRotatef( g_fTime, 0, 1, 0 );
114 glRotatef( g_fTime, 1, 0, 0 );
119 glColor3f( 1, 1, 0 );
120 /* glutWireCube( 20.0 ); */
121 glutWireTeapot( 20.0 );
122 /* glutWireSpher( 15.0, 15, 15 ); */
123 /* glColor3f( 0, 1, 0 ); */
124 /* glutWireCube( 30.0 ); */
125 /* glutSolidCone( 10, 20, 10, 2 ); */
128 * Don't forget about the model-view matrix
135 if( g_InGameMode == 0 )
136 PrintText( 20, 20, "Hello there cruel world!" );
138 PrintText( 20, 20, "Press ESC to leave the game mode!" );
141 * And swap this context's buffers
147 * This is a sample idle function
149 void SampleIdle( void )
153 if( g_LeaveGameMode == 1 )
155 glutLeaveGameMode( );
162 * The reshape function
164 void SampleReshape( int nWidth, int nHeight )
166 GLfloat fAspect = (GLfloat) nHeight / (GLfloat) nWidth;
167 GLfloat fPos[ 4 ] = { 0.0f, 0.0f, 10.0f, 0.0f };
168 GLfloat fCol[ 4 ] = { 0.5f, 1.0f, 0.0f, 1.0f };
171 * Update the viewport first
173 glViewport( 0, 0, nWidth, nHeight );
176 * Then the projection matrix
178 glMatrixMode( GL_PROJECTION );
180 glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 );
183 * Move back the camera a bit
185 glMatrixMode( GL_MODELVIEW );
187 glTranslatef( 0.0, 0.0, -40.0f );
190 * Enable some features...
192 glEnable( GL_CULL_FACE );
193 glEnable( GL_DEPTH_TEST );
194 glEnable( GL_NORMALIZE );
197 * Set up some lighting
199 glLightfv( GL_LIGHT0, GL_POSITION, fPos );
200 glEnable( GL_LIGHTING );
201 glEnable( GL_LIGHT0 );
204 * Set up a sample material
206 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fCol );
210 * A sample keyboard callback
212 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
214 printf( "SampleKeyboard(): keypress '%c' at (%i,%i)\n",
215 cChar, nMouseX, nMouseY );
219 * A sample keyboard callback (for game mode window)
221 void SampleGameModeKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
229 * A sample special callback
231 void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
233 printf( "SampleSpecial(): special keypress %i at (%i,%i)\n",
234 nSpecial, nMouseX, nMouseY );
238 * A sample menu callback
240 void SampleMenu( int menuID )
243 * Just print something funny
245 printf( "SampleMenu() callback executed, menuID is %i\n", menuID );
249 * The sample's entry point
251 int main( int argc, char** argv )
253 int menuID, subMenuA, subMenuB;
255 glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
256 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
257 glutInitWindowPosition( 100, 100 );
259 glutInit( &argc, argv );
261 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
263 subMenuA = glutCreateMenu( SampleMenu );
264 glutAddMenuEntry( "Sub menu A1 (01)", 1 );
265 glutAddMenuEntry( "Sub menu A2 (02)", 2 );
266 glutAddMenuEntry( "Sub menu A3 (03)", 3 );
268 subMenuB = glutCreateMenu( SampleMenu );
269 glutAddMenuEntry( "Sub menu B1 (04)", 4 );
270 glutAddMenuEntry( "Sub menu B2 (05)", 5 );
271 glutAddMenuEntry( "Sub menu B3 (06)", 6 );
272 glutAddSubMenu( "Going to sub menu A", subMenuA );
274 menuID = glutCreateMenu( SampleMenu );
275 glutAddMenuEntry( "Entry one", 1 );
276 glutAddMenuEntry( "Entry two", 2 );
277 glutAddMenuEntry( "Entry three", 3 );
278 glutAddMenuEntry( "Entry four", 4 );
279 glutAddMenuEntry( "Entry five", 5 );
280 glutAddSubMenu( "Enter sub menu A", subMenuA );
281 glutAddSubMenu( "Enter sub menu B", subMenuB );
283 glutCreateWindow( "Hello world!" );
284 glutDisplayFunc( SampleDisplay );
285 glutReshapeFunc( SampleReshape );
286 glutKeyboardFunc( SampleKeyboard );
287 glutSpecialFunc( SampleSpecial );
288 glutIdleFunc( SampleIdle );
289 glutAttachMenu( GLUT_LEFT_BUTTON );
291 glutInitWindowPosition( 200, 200 );
292 glutCreateWindow( "I am not Jan B." );
293 glutDisplayFunc( SampleDisplay );
294 glutReshapeFunc( SampleReshape );
295 glutKeyboardFunc( SampleKeyboard );
296 glutSpecialFunc( SampleSpecial );
297 glutIdleFunc( SampleIdle );
298 glutAttachMenu( GLUT_LEFT_BUTTON );
300 printf( "Testing game mode string parsing, don't panic!\n" );
301 glutGameModeString( "320x240:32@100" );
302 glutGameModeString( "640x480:16@72" );
303 glutGameModeString( "1024x768" );
304 glutGameModeString( ":32@120" );
305 glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );
307 glutGameModeString( "640x480:37@300" ); /* this one should fail */
310 glutGameModeString( "800x600" ); /* this one is likely to succeed */
313 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
315 glutDisplayFunc( SampleDisplay );
316 glutReshapeFunc( SampleReshape );
317 glutKeyboardFunc( SampleGameModeKeyboard );
318 glutIdleFunc( SampleIdle );
319 glutAttachMenu( GLUT_LEFT_BUTTON );
321 printf( "current window is %ix%i at (%i,%i)\n",
322 glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
323 glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y )
327 * Enter the main FreeGLUT processing loop
331 printf( "glutMainLoop() termination works fine!\n" );
334 * This is never reached in FreeGLUT. Is that good?
339 /*** END OF FILE ***/