View Full Version : Render 3D Text in Core Profile

06-29-2014, 10:03 PM
I can't seem to find a modern (core profile) way to print 3D text (translate, rotate).

FreeType surely is not: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01
FreeType Uses GL_APLHA in glTexImage2D(GL_TEXTURE_2D, 0, GL_APLHA , w, h, 0, GL_APLHA , GL_UNSIGNED_BYTE, data);

FTGL surely is not. Here is an example from their tutorial
glMaterialfv(GL_FRONT, GL_AMBIENT, front_ambient);
glColorMaterial(GL_FRONT, GL_DIFFUSE);
glTranslatef(0.0, 0.0, 20.0);
glRotatef(n / 1.11, 0.0, 1.0, 0.0);
glRotatef(n / 2.23, 1.0, 0.0, 0.0);
glRotatef(n / 3.17, 0.0, 0.0, 1.0);
glTranslatef(-260.0, -0.2, 0.0);
glColor3f(1.0, 1.0, 1.0);
font[fontindex]->Render("Hello FTGL!");

The 3D text on this forum is not for core: http://www.opengl.org/archives/resources/features/fontsurvey/

How can I draw 3d text in the core profile?

06-29-2014, 11:24 PM
The simplest way is to put the text on a texture and then render this texture to somewhere. All the other libraries are probably doing the same thing.
The only difficulty is to get your text on the texture if you dont know the text in advance. Usually you have all glyphs for your font already on a lookup-texture and then you simply blit it. But there is also ways to have the OS write text on a texture for you. How you do this depends on the programming language you use though.

With Java, for example, you can create a BufferedImage and render text to it with AWT or Swing and then create a texture out of your BufferedImage.

Agent D
06-30-2014, 02:28 AM
FreeType and FTGL are 3rd party libraries for font rasterization.

You will have to use either 3rd party libraries or your own solution as font rasterization is way beyond the scope of OpenGL(R).

I don't really understand your assertion that "FreeType Uses GL_APLHA". FreeType has no connection to OpenGL(R) whatsoever.

Using FreeType for font rasterization myself, I would actually reccomend it.

If you want something like that old Windows(R) 3D text screen saver, you can extract the glyph outlines using FreeType, extrude them
along the third dimension and upload the generate vertex buffer.

If you want to render 2D text somewhere in your scene, there are two possible ways I can think of:

use the FreeType rasterizer and copy the glyphs to an alpha only texture one by one. A fragment shader samples the alpha channel from the alpha texture and the color from somewhere else
If you already have something like a canvas object that renders to a texture, use the FreeType rasterizer to draw glyphs to that buffer
if you only want to display simple ASCII text, you could generate an alpha only texture with all ASCII characters (either using FreeType or offline using some tool). The text string is stored in another single channel texture with nearest neighbour sampling. The fragment shader use the text string texture values to sample the apropriate glyph images from the glyph texture.

07-01-2014, 04:29 AM
Your logo makes me laugh! :biggrin-new:
Cornix & Agent D thanks for the replies. Indeed I am trying to put text on a texture and render it...

I have read and tried to apply FreeType and can't get letters to show up; I check for OpenGLerrors and there are none but all I see on the screen where letters should be are black boxes. With the code below, I used another texture and it works so my error lies somewhere within FreeType usage....

"I don't really understand your assertion that "FreeType Uses GL_APLHA" ": I was trying to say that here (http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01v ) they have this: glTexImage2D(
GL_ALPHA,//This enum is no longer supported....I'm studying GL_R8 & GL_RED to work around
GL_ALPHA,//This enum is no longer supported....I'm studying GL_R8 & GL_RED to work around

Since GL_ALPHA is no longer supported, FreeType cannot be modern and that it may not work in OpenGL Core Profile.... Sorry for the confusion. I am glad to hear you are using it and therefore there is hope!

I'll study. Thanks again!