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 "../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_DEPTH_TEST );
39 glMatrixMode( GL_PROJECTION );
44 * Have an orthogonal projection matrix set
46 glOrtho( 0, glutGet( GLUT_WINDOW_WIDTH ),
47 0, glutGet( GLUT_WINDOW_HEIGHT ),
54 glMatrixMode( GL_MODELVIEW );
61 glColor3ub( 0, 0, 0 );
62 glRasterPos2i( nX, nY );
64 for( p=pszText, lines=0; *p; p++ )
69 glRasterPos2i( nX, nY-(lines*18) );
72 glutBitmapCharacter( GLUT_BITMAP_HELVETICA_18, *p );
76 * Revert to the old matrix modes
78 glMatrixMode( GL_PROJECTION );
81 glMatrixMode( GL_MODELVIEW );
85 * Restore the old OpenGL states
87 glColor4f( 1.0f, 1.0f, 1.0f, 1.0f );
88 glEnable( GL_DEPTH_TEST );
92 * This is the display routine for our sample FreeGLUT windows
94 static float g_fTime = 0.0f;
96 void SampleDisplay( void )
101 glClearColor( 0, 0.5, 1, 1 );
102 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
105 * Have the cube rotated
107 glMatrixMode( GL_MODELVIEW );
110 glRotatef( g_fTime, 0, 0, 1 );
111 glRotatef( g_fTime, 0, 1, 0 );
112 glRotatef( g_fTime, 1, 0, 0 );
117 glColor3f( 1, 1, 0 );
118 //glutWireCube( 20.0 );
119 glutWireTeapot( 20.0 );
120 //glutWireSpher( 15.0, 15, 15 );
121 //glColor3f( 0, 1, 0 );
122 //glutWireCube( 30.0 );
123 //glutSolidCone( 10, 20, 10, 2 );
126 * Don't forget about the model-view matrix
133 if( g_InGameMode == 0 )
134 PrintText( 20, 20, "Hello there cruel world!" );
136 PrintText( 20, 20, "Press ESC to leave the game mode!" );
139 * And swap this context's buffers
145 * This is a sample idle function
147 void SampleIdle( void )
151 if( g_LeaveGameMode == 1 )
160 * The reshape function
162 void SampleReshape( int nWidth, int nHeight )
164 GLfloat fAspect = (GLfloat) nHeight / (GLfloat) nWidth;
165 GLfloat fPos[ 4 ] = { 0.0f, 0.0f, 10.0f, 0.0f };
166 GLfloat fCol[ 4 ] = { 0.5f, 1.0f, 0.0f, 1.0f };
169 * Update the viewport first
171 glViewport( 0, 0, nWidth, nHeight );
174 * Then the projection matrix
176 glMatrixMode( GL_PROJECTION );
178 glFrustum( -1.0, 1.0, -fAspect, fAspect, 1.0, 80.0 );
181 * Move back the camera a bit
183 glMatrixMode( GL_MODELVIEW );
185 glTranslatef( 0.0, 0.0, -40.0f );
188 * Enable some features...
190 glEnable( GL_CULL_FACE );
191 glEnable( GL_DEPTH_TEST );
192 glEnable( GL_NORMALIZE );
195 * Set up some lighting
197 glLightfv( GL_LIGHT0, GL_POSITION, fPos );
198 glEnable( GL_LIGHTING );
199 glEnable( GL_LIGHT0 );
202 * Set up a sample material
204 glMaterialfv( GL_FRONT, GL_AMBIENT_AND_DIFFUSE, fCol );
208 * A sample keyboard callback
210 void SampleKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
212 printf( "SampleKeyboard(): keypress '%c' at (%i,%i)\n", cChar, nMouseX, nMouseY );
216 * A sample keyboard callback (for game mode window)
218 void SampleGameModeKeyboard( unsigned char cChar, int nMouseX, int nMouseY )
226 * A sample special callback
228 void SampleSpecial( int nSpecial, int nMouseX, int nMouseY )
230 printf( "SampleSpecial(): special keypress %i at (%i,%i)\n", nSpecial, nMouseX, nMouseY );
234 * A sample menu callback
236 void SampleMenu( int menuID )
239 * Just print something funny
241 printf( "SampleMenu() callback executed, menuID is %i\n", menuID );
245 * The sample's entry point
247 int main( int argc, char** argv )
249 int menuID, subMenuA, subMenuB;
251 glutInit( &argc, argv );
253 glutInitDisplayString( "stencil~2 rgb double depth>=16 samples" );
254 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
255 glutInitWindowPosition( 100, 100 );
257 subMenuA = glutCreateMenu( SampleMenu );
258 glutAddMenuEntry( "Sub menu A1 (01)", 1 );
259 glutAddMenuEntry( "Sub menu A2 (02)", 2 );
260 glutAddMenuEntry( "Sub menu A3 (03)", 3 );
262 subMenuB = glutCreateMenu( SampleMenu );
263 glutAddMenuEntry( "Sub menu B1 (04)", 4 );
264 glutAddMenuEntry( "Sub menu B2 (05)", 5 );
265 glutAddMenuEntry( "Sub menu B3 (06)", 6 );
266 glutAddSubMenu( "Going to sub menu A", subMenuA );
268 menuID = glutCreateMenu( SampleMenu );
269 glutAddMenuEntry( "Entry one", 1 );
270 glutAddMenuEntry( "Entry two", 2 );
271 glutAddMenuEntry( "Entry three", 3 );
272 glutAddMenuEntry( "Entry four", 4 );
273 glutAddMenuEntry( "Entry five", 5 );
274 glutAddSubMenu( "Enter sub menu A", subMenuA );
275 glutAddSubMenu( "Enter sub menu B", subMenuB );
277 glutCreateWindow( "Hello world!" );
278 glutDisplayFunc( SampleDisplay );
279 glutReshapeFunc( SampleReshape );
280 glutKeyboardFunc( SampleKeyboard );
281 glutSpecialFunc( SampleSpecial );
282 glutIdleFunc( SampleIdle );
283 glutAttachMenu( GLUT_LEFT_BUTTON );
285 glutInitWindowPosition( 200, 200 );
286 glutCreateWindow( "I am not Jan B." );
287 glutDisplayFunc( SampleDisplay );
288 glutReshapeFunc( SampleReshape );
289 glutKeyboardFunc( SampleKeyboard );
290 glutSpecialFunc( SampleSpecial );
291 glutIdleFunc( SampleIdle );
292 glutAttachMenu( GLUT_LEFT_BUTTON );
294 printf( "Testing game mode string parsing, don't panic!\n" );
295 glutGameModeString( "320x240:32@100" );
296 glutGameModeString( "640x480:16@72" );
297 glutGameModeString( "1024x768" );
298 glutGameModeString( ":32@120" );
299 glutGameModeString( "Toudi glupcze, Danwin bedzie moj!" );
300 glutGameModeString( "640x480:16@72" );
303 glutDisplayFunc( SampleDisplay );
304 glutReshapeFunc( SampleReshape );
305 glutKeyboardFunc( SampleGameModeKeyboard );
306 glutIdleFunc( SampleIdle );
307 glutAttachMenu( GLUT_LEFT_BUTTON );
309 printf( "current window is %ix%i+%i+%i",
310 glutGet( GLUT_WINDOW_X ), glutGet( GLUT_WINDOW_Y ),
311 glutGet( GLUT_WINDOW_WIDTH ), glutGet( GLUT_WINDOW_HEIGHT )
315 * Enter the main FreeGLUT processing loop
319 printf( "glutMainLoop() termination works fine!\n" );
322 * This is never reached in FreeGLUT. Is that good?
324 return( EXIT_SUCCESS );
327 /*** END OF FILE ***/