Results 1 to 7 of 7

Thread: Displaying Fonts?

  1. #1
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    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).]

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Displaying Fonts?

    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

  3. #3
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Displaying Fonts?

    Does anybody know what's wrong with the program.

    - VC6-OGL

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    2,978

    Re: Displaying Fonts?

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

  5. #5
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Displaying Fonts?

    I think it is.

  6. #6
    Member Contributor
    Join Date
    Aug 2002
    Location
    Brooklyn, NY, USA
    Posts
    53

    Re: Displaying Fonts?

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

  7. #7
    Senior Member Regular Contributor
    Join Date
    Nov 2002
    Location
    USA
    Posts
    254

    Re: Displaying Fonts?

    I'll try it.

    - VC6-OGL

Similar Threads

  1. Fonts
    By Sangee in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-21-2006, 09:38 AM
  2. bitmap fonts vs texture fonts
    By ehsan2004 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-31-2005, 03:24 AM
  3. Fonts
    By Andrew Polar in forum OpenGL: Windows
    Replies: 2
    Last Post: 03-26-2005, 12:34 PM
  4. Fonts
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-19-2005, 05:52 AM
  5. fonts
    By nickn in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-16-2001, 09:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean