0

I am newbie to OpenGL and I am trying to create a simple application that contains a viewport,3d model and display some text. I never used glut window and would like to use MFC window for the above functionality. The viewport and 3d model work fine but the given text is not being displayed. I have tested glutWindow based application in which the text display works. Since I dont want to use glutwindow in my application I avoided the following lines

   glutInit(&argc, argv);
    glutInitWindowSize (window_width, window_height);
    glutInitWindowPosition (window_X_position, window_Y_position);
    glutInitDisplayMode (GLUT_RGB);
    glutCreateWindow (window_title);
    glutDisplayFunc (display);

Only using MFC and OpenGL I have to display the text.

method 1:

  /* glPushMatrix();
         glRotatef( -25.0f, 0.0f, 1.0f, 0.0f );
        glTranslatef( -2.5f, -0.7f, 0.0f );    
        lListBase( m_TextID );
        glCallLists( 20, GL_UNSIGNED_BYTE, (const GLvoid*)"welcome" ); 
         glPopMatrix();*/

method 2 :

void renderstring2d(char string[], float r, float g, float b, float x, float y)
{
    glColor3f(r, g, b);

    glRasterPos2f(x, y);
    for(unsigned int i = 0; i < strlen(string); i++)
        glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]);
}

method 3 :

void renderstring3d(char string[], float r, float g, float b, float x, float y, float z)
{
    glDisable(GL_LIGHTING);
    glColor3f(r, g, b);

    glRasterPos3f(x, y, z);
    for(unsigned int i = 0; i < strlen(string); i++)
        glutBitmapCharacter(GLUT_BITMAP_9_BY_15, string[i]);
}

I tried all of the above methods and failed. Please help me to display text in OpenGL within an MFC application.

elimad
  • 1,132
  • 1
  • 15
  • 27
kirubha
  • 13
  • 5
  • Failed means no text at all or displayed but at wrong location? What are the values being passed for the text location as `x`, `y`, `z` in your `renderstring` functions? Better post the code that calls these `renderstring` functions to figure out. – elimad Apr 23 '15 at 13:18

1 Answers1

1

You're using fixed pipeline, so you've to set up ModelView Matrix and Projection Matrix according to the coordinate system used by glutBitmapCharacter.

Look at this example: http://www.programming-techniques.com/2012/05/font-rendering-in-glut-using-bitmap.html

Mouze
  • 706
  • 5
  • 10
  • Thanks Mouze. I have applied ModelView Matrix and Projection Matrix in my code the reslut came.But it work for glRasterPos2f(x, y), How to i setup for glRasterPos3f(x, y, z) ? – kirubha Apr 23 '15 at 14:48