using GLSL to create new GL primitives

Hello,

I have a framework that is portable between Mac, Windows and Linux, potentially to OpenGL ES platforms as well, based on SDL. I’m interested in making high speed fonts available in full 3d. I have used FTGL, a very cool library that (somewhat inefficiently, with virtual calls letter by letter) would draw letters as either flat polygons, extruded 3d shapes, and other options. I want to build in a set of convenience functions for a higher speed version.

Let’s just consider one case, generating polygons out of freetype fonts, and rendering them as text in 3d space.

If a glyph were just a single polygon, then I could do a simple array draw primitive in OpenGL, and use VBO so that the polygons could be pre-loaded on the card. But glyphs can have a variable number of polygons.

If I upload a buffer of polygons, and a buffer of indices into those polygons, can I pass a string to a GLSL routine, and have it render the appropriate polygons? Excuse my ignorance, but the little shader code I’ve seen looks nothing like that.

in pseudo code, it would look like this:

void drawText(string text) {
for (each letter of string) {
int starti = glyphindex[string[i]];
int endi = glyphindex[string[i]+1];
drawPolygons(glypharray, starti, endi)
glTranslatef(glyphwwidth[string[i]], 0, 0);
}
}

Needless to say, in order to support platforms without GLSL, the object library will do this in ordinary OpenGL as well, slower.

GLSL does not provide support for strings. You may be able to use a uniform array of ints though. If you want to introduce “new primitive types,” you can look into geometry shaders but creating too much geometry in the shader can really hurt performance, at least on GeForce 8.

A while back, I wrote a blog about using a vertex shader to avoid looping over each character on the CPU when rendering text. It may be of interest to you: Rendering Text Fast.

Patrick

I fail to see how this has anything to do with glsl. You cannot pass string data to shaders (vertex or fragment (or geometry)). Even if it were supported, it probably would be better to do this kind of logic on program side and not on glsl side.

The pseudo code looks correct, if you are going to do a simple single-line text renderer. (text rendering has lots of interesting little features, intriguing video about a font renderer: http://arstechnica.com/web/news/2009/11/…tm_campaign=rss )

The fundamental question here is whether there is any support in GLSL for creating vertices, as opposed to transforming them.

If points can be created, then the only other question is how to get character data to video RAM. This seems to me to be trivial. A VBO with an array of bytes, or shorts, represents the characters.
If there is a slicker way of passing a one-time string to the graphics card, great.

If I want to represent multiple lines, then a list of indices is also required.

You can create vertices / primitives using a geometry shader.
However, I don’t see clearly how you are going to create letter shapes in it.

Why do you want to do this? Drawing polygon-based characters with a single glMultiDrawElements call will be much higher performance than what you’re suggesting. And doing it with just textures will be higher performance still.

Chapter 25 of da GPU Gems 3 (free online) lays out a method for rendering antialiased vector art on the GPU. And with the stencil buffer based triangulation technique they hint at this looks to be a shoo-in for rendering high quality 2D text in a general 3D setting.