LWJGL Forum
Programming => Lightweight Java Gaming Library => Topic started by: Oflor on March 30, 2012, 06:51:38
-
Hi there.
Could someone tell me how to render text in OpenGL? We don't want to use any other libs like slick.
We have found one example but we can't get it to work with our own rendering code. It just doesn't draw anything.
This is our gl-init code:
private void glInit()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, w, h, 0, 1, -1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glEnable(GL_LINE_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glClearColor(0.0f, 0.0f, 0.1f, 1.0f);
buildFont();
}
And we run this before any renderings:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Actually, we are new to OpenGL. Thanks, Oflor.
-
OpenGL has no built in mechanism for drawing fonts or text, so you'll have to create your own. The most common approach is to usually use Bitmap Fonts similar to how the Slick Util (http://www.lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Introduction) library does it.