Displaying Fonts?

Hello,

I am having a problem with display text on my GLUT screen. creating the font is just fine, thanks to nexusone, but the problem comes in when I display it and nothing shows up.

Code for text:

void Text( int x, int y, char *st ) {
int l, i;

l=strlen( st );
glRasterPos3i( x, y, 1);
for( i=0; i < l; i++) {
glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, st[i] );
}
}

Thanks to nexusone!!!

Code for displaying:

void display( void ) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();

glColor3f( 1.0, 1.0, 1.0 );
Text( 1, 1, “GLUT Screen” );

glBegin( GL_POLYGON );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -2.5f, -0.8f, 0.5f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 2.5f, -0.8f, 0.5f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 2.5f, 0.8f, 0.5f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -2.5f, 0.8f, 0.5f );
glEnd();

glPopMatrix();

glutSwapBuffers();
}

Code for Cameras:

void reshape( int w, int h ) {
if( h == 0 )
h = 1;

float ratio = 1.0 * w / h;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glViewport( 0, 0, w, h );

gluPerspective( 25, ratio, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, -1.0, 0.0f, 1.0f, 0.0f );
}

  • VC6-OGL

[This message has been edited by VC6-OGL (edited 12-16-2002).]

[This message has been edited by VC6-OGL (edited 12-16-2002).]

Here’s the full code:

#include <windows.h>
#include <gl/glut.h>
#include <stdio.h>

void Text( int x, int y, char *st ) {
int l, i;

l=strlen( st );
glRasterPos3i( x, y, 1);
for( i=0; i < l; i++) {
glutBitmapCharacter( GLUT_BITMAP_TIMES_ROMAN_24, st[i] );
}
}

void init( void ) {
glEnable( GL_TEXTURE_2D );
glClearColor( 0.0, 0.0, 0.0, 0.0 );
glShadeModel( GL_SMOOTH );
glEnable( GL_DEPTH_TEST );
}

void reshape( int w, int h ) {
if( h == 0 )
h = 1;

float ratio = 1.0 * w / h;

glMatrixMode( GL_PROJECTION );
glLoadIdentity();

glViewport( 0, 0, w, h );

gluPerspective( 25, ratio, 1, 1000 );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt( 0.0, 0.0, 5.0, 0.0, 0.0, -1.0, 0.0f, 1.0f, 0.0f );
}

void display( void ) {
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

glPushMatrix();

glColor3f( 1.0, 1.0, 1.0 );
Text( 1, 1, “GLUT Screen” );

glBegin( GL_POLYGON );
glTexCoord2f( 0.0f, 0.0f ); glVertex3f( -2.5f, -0.8f, 0.5f );
glTexCoord2f( 1.0f, 0.0f ); glVertex3f( 2.5f, -0.8f, 0.5f );
glTexCoord2f( 1.0f, 1.0f ); glVertex3f( 2.5f, 0.8f, 0.5f );
glTexCoord2f( 0.0f, 1.0f ); glVertex3f( -2.5f, 0.8f, 0.5f );
glEnd();

glPopMatrix();

glutSwapBuffers();
}

void keyboard( unsigned char key, int x, int y ) {
switch ( key ) {
case 27:
exit( 0 );
break;
}
}

void main( int argc, char **argv ) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA );
glutEnterGameMode();
init();
glutDisplayFunc( display );
glutIdleFunc( display );
glutReshapeFunc( reshape );
glutKeyboardFunc( keyboard );

glutMainLoop();
}

  • VC6-OGL

Does anybody know what’s wrong with the program.

  • VC6-OGL

Are you sure the raster position is actually on the screen?

I think it is.

You need to confirm the raster position is valid.
glGetBooleanv(GL_CURRENT_RASTER_POSITION_VALID, &bsomebooleanvariable);

I’ll try it.

  • VC6-OGL