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( );
178 * The reshape function
180 void SampleReshape( int nWidth, int nHeight )
182 GLfloat fAspect = (GLfloat) nHeight / (GLfloat) nWidth;
183 GLfloat fPos[ 4 ] = { 0.0f, 0.0f, 10.0f, 0.0f };
184 GLfloat fCol[ 4 ] = { 0.5f, 1.0f, 0.0f, 1.0f };
187 * Update the viewport first
189 glViewport( 0, 0, nWidth, nHeight );
192 * Then the projection matrix
194 glMatrixMode( GL_PROJECTION );
196 glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 );
199 * Move back the camera a bit
201 glMatrixMode( GL_MODELVIEW );
203 glTranslatef( 0.0, 0.0, -40.0f );
206 * Enable some features...
208 glEnable( GL_CULL_FACE );
209 glEnable( GL_DEPTH_TEST );
210 glEnable( GL_NORMALIZE );
213 * Set up some lighting
215 glLightfv( GL_LIGHT0, GL_POSITION, fPos );
216 glEnable( GL_LIGHTING );
217 glEnable( GL_LIGHT0 );
220 * Set up a sample material
222 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fCol );
226 * A sample keyboard callback
228 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
230 printf( "SampleKeyboard(): keypress '%c' at (%i,%i)\n",
231 cChar, nMouseX, nMouseY );
235 * A sample keyboard callback (for game mode window)
237 void SampleGameModeKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
245 * A sample special callback
247 void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
249 printf( "SampleSpecial(): special keypress %i at (%i,%i)\n",
250 nSpecial, nMouseX, nMouseY );
254 * A sample menu callback
256 void SampleMenu( int menuID )
259 * Just print something funny
261 printf( "SampleMenu() callback executed, menuID is %i\n", menuID );
265 * The sample's entry point
267 int main( int argc, char** argv )
269 int menuID, subMenuA, subMenuB;
271 glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
272 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
273 glutInitWindowPosition( 100, 100 );
275 glutInit( &argc, argv );
277 glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_GLUTMAINLOOP_RETURNS);
279 subMenuA = glutCreateMenu( SampleMenu );
280 glutAddMenuEntry( "Sub menu A1 (01)", 1 );
281 glutAddMenuEntry( "Sub menu A2 (02)", 2 );
282 glutAddMenuEntry( "Sub menu A3 (03)", 3 );
284 subMenuB = glutCreateMenu( SampleMenu );
285 glutAddMenuEntry( "Sub menu B1 (04)", 4 );
286 glutAddMenuEntry( "Sub menu B2 (05)", 5 );
287 glutAddMenuEntry( "Sub menu B3 (06)", 6 );
288 glutAddSubMenu( "Going to sub menu A", subMenuA );
290 menuID = glutCreateMenu( SampleMenu );
291 glutAddMenuEntry( "Entry one", 1 );
292 glutAddMenuEntry( "Entry two", 2 );
293 glutAddMenuEntry( "Entry three", 3 );
294 glutAddMenuEntry( "Entry four", 4 );
295 glutAddMenuEntry( "Entry five", 5 );
296 glutAddSubMenu( "Enter sub menu A", subMenuA );
297 glutAddSubMenu( "Enter sub menu B", subMenuB );
299 glutCreateWindow( "Hello world!" );
300 glutDisplayFunc( SampleDisplay );
301 glutReshapeFunc( SampleReshape );
302 glutKeyboardFunc( SampleKeyboard );
303 glutSpecialFunc( SampleSpecial );
304 glutIdleFunc( SampleIdle );
305 glutAttachMenu( GLUT_LEFT_BUTTON );
307 glutInitWindowPosition( 200, 200 );
308 g_mainwin = glutCreateWindow( "I am not Jan B." );
309 glutDisplayFunc( SampleDisplay );
310 glutReshapeFunc( SampleReshape );
311 glutKeyboardFunc( SampleKeyboard );
312 glutSpecialFunc( SampleSpecial );
313 glutIdleFunc( SampleIdle );
314 glutAttachMenu( GLUT_LEFT_BUTTON );
315 glutSetMenu(subMenuA);
316 glutAttachMenu( GLUT_RIGHT_BUTTON);
318 g_sw1=glutCreateSubWindow(g_mainwin,200,0,100,100);
319 glutDisplayFunc( SampleDisplay );
320 glutSetMenu(subMenuB);
321 glutAttachMenu( GLUT_LEFT_BUTTON);
323 printf( "Testing game mode string parsing, don't panic!\n" );
324 glutGameModeString( "320x240:32@100" );
325 glutGameModeString( "640x480:16@72" );
326 glutGameModeString( "1024x768" );
327 glutGameModeString( ":32@120" );
328 glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );
330 glutGameModeString( "640x480:37@300" ); /* this one should fail */
333 glutGameModeString( "800x600" ); /* this one is likely to succeed */
336 if (glutGameModeGet(GLUT_GAME_MODE_ACTIVE))
338 glutDisplayFunc( SampleDisplay );
339 glutReshapeFunc( SampleReshape );
340 glutKeyboardFunc( SampleGameModeKeyboard );
341 glutIdleFunc( SampleIdle );
343 printf( "current window is %ix%i at (%i,%i)\n",
344 glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT ),
345 glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y )
349 * Enter the main FreeGLUT processing loop
353 printf( "glutMainLoop() termination works fine!\n" );
356 * This is never reached in FreeGLUT. Is that good?
361 /*** END OF FILE ***/