From: Nigel S. <ni...@ni...> - 2004-05-22 21:31:47
|
Of interest to the freeglut list, we revisited the glutBitmapString implementation over on the OpenGLUT list. This stemmed from a glPushMatrix of the projection matrix. We were able to eliminate the matrix state management and glRasterPos call by using glBitmap for the \n handling. This also has the advantage of eliminating the potential pipeline stall related to the use of glGet() Regards, Nigel Stewart ------------ Subject: Re: [OpenGLUT-devel] "freeglujt" Changes Date: Thu, 13 May 2004 20:58:19 -0400 From: Nigel Stewart <ni...@ni...> ... So, it doesn't seem to be necessary for glutBitmapString to be doing any modelview or projection matrix manipulation, it is merely drawing an arrangement of bitmaps at the current raster position, if the valid bit is true to start with. >> Removing glGet calls from glutBitmapString >> should be possible - and ought to be the goal. >> >> Scanning the string for \n may also be a good >> idea. Here is the version of glutBitmapString I am experimenting with. There is nothing here that should stall the pipeline... And we've eliminated some problematic cruft along the way! void OGAPIENTRY glutBitmapString( void *fontID, const unsigned char *string ) { int c; int numchar = strlen( ( char * )string ); SOG_Font *font = oghFontByID( fontID ); float x; if( !font ) return; glPushClientAttrib( GL_CLIENT_PIXEL_STORE_BIT ); glPixelStorei( GL_UNPACK_SWAP_BYTES, GL_FALSE ); glPixelStorei( GL_UNPACK_LSB_FIRST, GL_FALSE ); glPixelStorei( GL_UNPACK_ROW_LENGTH, 0 ); glPixelStorei( GL_UNPACK_SKIP_ROWS, 0 ); glPixelStorei( GL_UNPACK_SKIP_PIXELS, 0 ); glPixelStorei( GL_UNPACK_ALIGNMENT, 1 ); /* * Step through the string, drawing each character. * A newline will simply translate the next character's insertion * point back to the start of the line and down one line. */ x = 0.0f; for( c = 0; c < numchar; c++ ) if( string[c] == '\n' ) { glBitmap(0,0,0,0,-x,(float) -font->Height,NULL); x = 0.0f; } else /* Not an EOL, draw the bitmap character */ { const GLubyte* face = font->Characters[ string[ c ] ]; glBitmap( face[ 0 ], font->Height, font->xorig, font->yorig, ( float )( face[ 0 ] ), 0.0, ( face + 1 ) ); x += ( float )( face[ 0 ] ); } glPopClientAttrib( ); } |