Talk:OpenGL Programming/Modern OpenGL Tutorial Text Rendering 01

NOTICE: the code showed in this article is not the same that the code in the "text01_intro"
I have been trying implementing the code of the article unsuccessfully, but when I have downloaded the source code related with this one, I have found code differences in the fragment shader and in the glTexImage2D function, and applyng this differences, the demo run sucessfully.

WARNING: this method is slow
I just implemented the method below for rendering a line of text. It works, but is very slow for a runtime application.

The ft_load_char function is slow, and if using a hundred times a frame, for every char in a line of text, can make you lose about 300fps.

I read about how texture caching can speed this up, but the op did not tell us how. Also how can you cache a single texture for different chars, if only one char can be in the texture at a time?

Unless the OP can come up with a way to significantly speed this up, It is much faster to just load all the chars to a traditional sprite texture beforehand.


 * I agree. What's worse is that this page is quickly found via Google when looking for "freetype OpenGL tutorial" or similar searches. Which means that this tutorial is teaching people bad techniques. As evidenced by this question on OpenGL.org's forums.


 * Tutorials should not be teaching people the wrong way to do things, even if it's slightly easier for making the tutorial work. Korval (discuss • contribs) 20:22, 18 June 2015 (UTC)


 * I don't agree. I think the tutorial should be simple, so that people can get something working quickly.  To be fast, all the data should already be on the GPU before rendering, which isn't the case here, so it's obvious that it's just a demonstration. Unclouded (discuss • contribs) 22:42, 31 July 2022 (UTC)

Triangle winding order
Thank you very much for this tutorial, which worked perfectly once I used a VAO and set uniform variables.

Just a note that the triangle winding order is clockwise, which meant that text was not visible until I did glDisable(GL_CULL_FACE). To use CCW winding, change the order of the vertices:

problem
Hey, I had a hard time making this to work, glTex[Sub]Image2D throwing a GL_INVALID_ENUM each time I drew a char or when I created the atlas(in the next tutorial on fonts). The problem was that GL_ALPHA as a (internal)format was causing this, as well as GL_LUMINANCE or GL_INTENSITY, and the visual result was just lots of artifacts on screen. What I did to make this work is using glTexImage2D like this :

So GL_RGB as internal format and GL_RED as format (and using GL_RED too when filling the atlas in the second tutorial).

Then in the shader I used the RED component of the texture in the ALPHA component of the final color, like this :

I'm using OpenGL 3.2, with GLSL 330, and GLEW to load procedures. I did not found anyone having this problem on the web so I write it here if someone gets in the same situation. Very good tutorial nonetheless!!

--Revk (discuss • contribs) 19:36, 24 January 2012 (UTC)


 * Which graphics card do you have? Also, if you haven't used the code from this git repository, please try it out and see whether that also fails or not.
 * --Guus (discuss • contribs)


 * Hey!
 * In fact, I saw where I went wrong on this. The problem is that I use OpenGL Core Profile without backward compatibility. As of 3.0+, GL_ALPHA is not a valid format/internal_format value anymore. The only ones are GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_DEPTH_COMPONENT, GL_DEPTH_STENCIL, and a list of sized and/or compressed components, as shown on :
 * https://www.opengl.org/sdk/docs/man3/xhtml/glTexImage2D.xml
 * So I believe that for a Core Profile OpenGL application, GL_RED is the value to use for the Format, and GL_RGB for the InternalFormat. And the fragment shader must use the red component of the texture as the alpha component of its output color (as shown in my first post).
 * As for the examples on Gitorious, they work fine for me ;). But there is maybe something wrong with the glPixelStorei. It is used before the atlas filling with a size of 1, but is not put back to the original size of the unpack_alignment size. Wouldn't it be better to do? :


 * Revk (discuss • contribs) 03:57, 11 March 2012 (UTC)


 * Hi Revk,


 * I'm having trouble getting this to work.
 * Can anyone with working code post it somewhere and link to it here?
 * Thanks.
 * --69.17.174.21 (discuss) 03:54, 24 January 2015 (UTC)

No VAO is created...
First of all, thanks for this helpful tutorial. It smoothly works on Windows but I couldn't make it work on OSX (10.9 Mavericks) first, since there is no VAO created in this source code. Hope this helps other people in the future.

-Minho

I needed a VAO to be able to switch between vertex formats (glVertexAttribPointer), so totally agree!

SansSerif.ttf can not be used
Hi all, I used Visual Studio 2012 and could not run this example. When I replaced SansSerif.ttf by - for example - arial.ttf, from c:\windows\fonts it succeeds. Maybe the trouble comes from freetype 2.5.5 library, that I had to compile by myself and is perhaps "too new" for this old font file. OnkelSchuppig (discuss • contribs) 11:20, 31 January 2015 (UTC)