Reputation: 2839
I managed to draw text in opengl using glutBitmapCharacters. Now i wanna draw a title but it has to have a bigger size. How do i do that? Here is the code for my drawtext function:
void drawText(const char *text,int length , int x , int y)
{
glMatrixMode(GL_PROJECTION);
double *matrix = new double[16];
glGetDoublev(GL_PROJECTION_MATRIX,matrix);
glLoadIdentity();
glOrtho(0,800,0,600,-5,5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glPushMatrix();
glLoadIdentity();
glRasterPos2i(x,y);
for ( int i = 0 ; i < length ; i++)
glutBitmapCharacter(GLUT_BITMAP_9_BY_15,(int)text[i]);
delete matrix;
}
Upvotes: 1
Views: 3658
Reputation: 39370
As an addition to @NicolBolas answer, you can always scale raw bitmap data (just like imaging programs, e.g. Photoshop, can), though the results, especially regarding fonts, might not always be satisfactory. Scaling by a natural number will always be pixel-perfect, though.
To use such scaling, you will need to render your fonts to texture. You can then render them as textured quads to screen, and use built-in OpenGL scaling.
Please note that I'm not recommending this approach. If you need more sophisticated features, perhaps a bigger and more featured library, like freetype-gl
, would be appropriate.
Upvotes: 1
Reputation: 473174
glutBitmapCharacter
uses glBitmap
under the hood. So you cannot change the text size; it will be the exact pixel size of the text.
If you want text who's size can be changed, you need to use the "Stroke" character functions (such as glutStrokeCharacter
). These draw actual triangles and such, who's size can be adjusted via matrix scale operations (glScale
).
Upvotes: 2