Advertisement

opengl glutstrokecharacter - write text to screen

Started by October 29, 2013 01:46 PM
1 comment, last by chilun 11 years, 3 months ago

Hi;

I'm trying to write some code into my existing game project to write some text to the window.

I've modified the sample code to plug into project. The output function assigns element in the text string to an individual char in order to pass to the display function (subsequently output to the screen). It compiles, but I don't see any text written to the window. Does anyone know how I can fix this?


void output(GLfloat x, GLfloat y, char* text)
{
    glPushMatrix();
    glTranslatef(x, y, 0);
    glScalef(1/152.38, 1/152.38, 1/152.38);
    for( char* p = text; *p; p++)
    {
        glutStrokeCharacter(GLUT_STROKE_ROMAN, *p);
    }
    glPopMatrix();
}


void display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  Painter p;
  game.draw(p);
  
  //write text to screen
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glEnable(GL_BLEND);
  glEnable(GL_LINE_SMOOTH);
  glLineWidth(2.0);
  output(400,200,"hello");
  
  glutSwapBuffers();
}

The glutStrokeCharacter seemed not working in the latest versions of MS VS.

Good sample of text output in glOrtho performance: lesson21( c++ code), lesson24(c++ code).

The codes and demo of above adapted to MS VS 2010/2012 in source files to:

Concentration of all The Lessons in Common Library GLSummary in MFC

Advertisement

Thank you very much. There is an alternative using the GlutBitmapCharacter function so I will test to see if this works with my existing code instead.

This topic is closed to new replies.

Advertisement