1

I've been trying to render text using glutBitmapCharacter().

This is what I've got so far as a 2D text rendering function:

void drawString(int x, int y, char* string) {
int i, len;

glDisable(GL_TEXTURE);
glDisable(GL_TEXTURE_2D);
glDisable(GL_LIGHTING);

glColor3f(1.0f, 0.0f, 0.0f);
glRasterPos2i(x, y);

for (i = 0, len = strlen(string); i < len; i++) {
    glutBitmapCharacter(GLUT_BITMAP_HELVETICA_18, (int)string[i]);
}
glEnable(GL_TEXTURE);
glEnable(GL_TEXTURE_2D);
glEnable(GL_LIGHTING);
}

In the scene rendering function, I make this call:

drawString(0, 0, "TESTING");

These are the only x and y values in which any text will be displayed, in which case "TESTING" appears in the middle of the screen with "TE" in red (the colour I want) and "STING" in black.

All the code for dealing with this function that I've seen has been using earlier versions of openGL and deprecated code, so I'm not sure what to do.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Tagc
  • 99
  • 11

1 Answers1

5

The above is definitely not openGL 4 compliant code.

Refer to the OpenGL 4 Reference manual and you will seethat glColor, glRasterPos don't even exist there (they are deprecated .. I believe even back in openGL 3)

In order to learn how to use openGL with the modern way that is not using the fixed functionality I would recommend this tutorial

So basically the answer is that without glRasterPos I believe that this function can't work in openGL 4. (or 3 for that matter)

For a feasible method refer to this answer

Community
  • 1
  • 1
Lefteris
  • 3,196
  • 5
  • 31
  • 52
  • Forward-only vs compatibility is a runtime per-context option, and won't prevent code from compiling. – Ben Voigt Feb 12 '12 at 05:36
  • Yes you are right Ben, did not mean to say compile. Thanks for the heads-up – Lefteris Feb 12 '12 at 05:40
  • If his problem was using *removed* features (deprecation and removal are *two different things*), then his code wouldn't display any text at all. But that's not what he's seeing. He's able to get text to display, but it's broken. Also, it's hard to create a 4.0 core context by accident; in all cases, it requires special-case code. – Nicol Bolas Feb 12 '12 at 05:52
  • Nicol you do have a point. So maybe the OP actually does not have a 4.0 core context but is working with the default context in which case his question should be stated in a different manner – Lefteris Feb 12 '12 at 05:54
  • Thanks for the responses, I'll see what I can do with FTGL tomorrow. – Tagc Feb 12 '12 at 06:14