Reputation: 99
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.
Upvotes: 1
Views: 2048
Reputation: 3256
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
Upvotes: 5