How OpenGL text is stored and displayed?
Archon

I'm just following a tutorial in an OpenGL book that I have on Bitmap Fonts and I need to figure out exactly what the windows and wgl functions do so I can make a .NET/Mono cross-platform alternative.

uint listbase;
listbase = glGenLists(96); //96 individual lists

HFONT font; //native windows object.

font = CreateFont(...bunch of parameters specifying the font to load); //native windows func.

SelectObject(hdc, font); //windows func... No idea what this does? Maps the font to the device context?

//handle to device context
//i'll assume that 32 = offset from first ASCII character
//96 = size of list
//the opengl list(s)
wglUseFontBitmaps(hdc, 32, 96, listbase);

I'll need to know what wglUseFontBitmaps does exactly since it's inner workings are not so obvious (to me)...

Then there is the rendering function

char *string;

glPushAttrib(GL_LIST_BIT);
  glListBase(listbase - 32); //32 offset backwards since we offset it forwards
  glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);
glPopAttrib();

Also, I'll assume that you'll need to translate the text initially for the x,y position on the screen, but what is making the text translate to the right after each character when glCallLists is called?

[edit]
For the glCallLists, does it also call glTranslatef based on the size of the text?

[edit2]
Basically, I need to know what wglUseFontBitmaps does to the display list.

Bob
Quote:

I'll need to know what wglUseFontBitmaps does exactly since it's inner workings are not so obvious (to me)...

wglUseFontBitmap() will create a set of display lists (one display list per character) that tells GL how to render that character. The exect contents of that display list are implementation-dependent and opaque to user applications. Using glDrawPixels() or glBitmap() (per glyph) is what's usually done though.

Quote:

what is making the text translate to the right after each character when glCallLists is called?

The display list contains the cursor movement code too. Display lists can encompass most GL commands, so glTranslatef/glRasterPosition can be included.

That said, if the display lists contains a call to glBitmap(), then glBitmap() has a parameter to move the raster position by some amount during that call.

Archon

Should/Are all the glyphs stored in their own textures (as in, separate IDs), or could they be put on 1 texture and use the 'source x' and 'source y'?

I might actually look into glBitmap.

[edit]
Pixmaps should work better :-X

Bob
Quote:

Should/Are all the glyphs stored in their own textures (as in, separate IDs), or could they be put on 1 texture and use the 'source x' and 'source y'?

There are no textures used.

Quote:

Pixmaps should work better

How so?

Archon
Quote:

Pixmaps should work better

Quote:

How so?

Pixmaps are better than bitmaps --> for the alpha bits?

Quote:

There are no textures used.

Are you talking about all font renderings or just the bitmap/pixmap raster graphics?

I'm now converting fonts to .tga files and loading them as textures. Is this a better idea?

Bob
Quote:

Pixmaps are better than bitmaps --> for the alpha bits?

The bitmaps in question are glBitmap() bitmaps. They are literally a map of bits. You get 2 states for every fragment that will be generated: on or off.

Secondly, pixmaps are not a part of OpenGL.

Quote:

Are you talking about all font renderings or just the bitmap/pixmap raster graphics?

I'm talking about wglUseFontBitmaps().

Quote:

I'm now converting fonts to .tga files and loading them as textures. Is this a better idea?

I don't know. What are you trying to do?

Archon
Quote:

I don't know. What are you trying to do?

Sorry, I mean that I'm converting ordinary fonts from their usual format to the Targa format (like a tileset), and then loading the image as any other texture. Just after that, I'd generate and 'make' the GL Lists (16 x 6 glyphs) which would draw the individual characters like wglUseFontBitmaps() does.

Bob

Sure, that works. Incidentally, that's how AGL processes fonts.

Archon

I almost have it working.
{"name":"screenshotna8.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/0\/8034e91a10b2d7c8adfce17c2140196c.png","w":808,"h":627,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/0\/8034e91a10b2d7c8adfce17c2140196c"}screenshotna8.png

I've still got to figure out how to determine how big each glyph is when I make the display lists...

[Retrospective edit]
And I've got to figure out how to make the transparency in the Targa file actually become transparent in the rendering.
This is actually linked to this new problem.

Another thing is, does the font look too blurry?

[edit]
OK. Here's a better screenshot.
{"name":"screenshot2hh6.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7c3875ba83bc99c0f92f5f021ea60b6e.png","w":808,"h":627,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7c3875ba83bc99c0f92f5f021ea60b6e"}screenshot2hh6.png

Thread #589140. Printed from Allegro.cc