I’m trying out glfont, a tool which renders characters in openGL by mapping character textures onto gl quads. I haven’t learned about textures yet, so I’m just following the example code as closely as possible. Code is on the faq page here: http://students.cs.byu.edu/~bfish/glfontfaq.php
The problem I’m having is I’m getting solid strips instead of text. This problem is mentioned in the faq, and it claims you need to enable texture mapping and alpha blending, with:
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
and lastly to try playing around with glScale. I did all three, and I’m still getting solid strips.
Here’s the whole program:
#include "stdafx.h"
#include "glfont.h"
#include <glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
GLFONT arial_r_12; // global font object
void init(void)
{
glClearColor (0.0, 0.0, 0.0, 1.0);
glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT);
glFontBegin(&arial_r_12);
glTranslatef(30, 30, 0);
glScalef(8.0,8.0,0.0);
glFontTextOut("HELLO WORLD!!!", 5, 5, 0);
glFontEnd();
glutSwapBuffers();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
glOrtho(0, 640, 0, 480, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int _tmain(int argc, char** argv)
{
if (!glFontCreate(&arial_r_12, "C:\\Program Files\\glFont\\Arial_r_20.glf", 0))
{
return 0;
}
glutInit(&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize (640, 480);
glutInitWindowPosition (100, 100);
glutCreateWindow (argv[0]);
init ();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
glFontDestroy(&arial_r_12);
return 0;
}