Archived

This topic is now archived and is closed to further replies.

Arch@on

TextureMapped Font Problem - lesson 17

Recommended Posts

Arch@on    100
I started doing fonts and got around TextureMapped2d fonts, more specifically lesson 17. Now I load my font from a 8bit tga that I converted from nehe''s font. I have the texture loaded in memory and I have built the display list, however I can''t figure out how to make it visible correct. For some reason OpenGL hates me and doesn''t show it transparent, and if it does it won''t show on white background and so on. I have tried using different blendfuncs, but it just doesn''t work. What the hell am I doing wrong. Code is exactly the same as in NeHe''s, except that I use 8-bit targa. I used paintshop pro to convert it.

Share this post


Link to post
Share on other sites
desertcube    514
Since your loading an 8-bit, there may not be an alpha channel. This may be the problem. You may have to set the alpha channel when loading it, like in his bmp tutorial. I may be completly wrong though, but it''s worth checking.

Share this post


Link to post
Share on other sites
James Trotter    432
You should create an alpha channel for the image and use alpha testing..

glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.5f);

Now any pixel with an alpha of less than 0.5 will be transparent.

Share this post


Link to post
Share on other sites
Arch@on    100
I''m not much of a man when it comes down to graphical programs. How do I create the alpha channel? With quick look through PSP 8.0 I could not see any way to do this. Is this palette transparency?

Share this post


Link to post
Share on other sites
Arch@on    100
I figured out how to set the alpha, I made the background as alpha so it won''t be rendered. However it didn''t change anything



glEnable(GL_ALPHA_TEST);
glAlphaFunc(GL_GREATER, 0.0f);


glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texID);

glDepthMask(GL_FALSE);
//glEnable(GL_BLEND); // For transparent background

//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);


glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadMatrixf(ortho);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
glTranslated(x, y, 0); // Position The Text (0,0 - Top Left)


// Note: the 128 below refers to the font texture containing 2 font sets.

// Use 0 for the first set, or 128 for the second set.

glListBase(base-32+(128*set));

glColor4f(font.red, font.green, font.blue, font.alpha); // Set text colour.


glCallLists(strlen(string), GL_UNSIGNED_BYTE, string); // Write The Text To The Screen


glMatrixMode(GL_PROJECTION);
glPopMatrix(); // Restore old Projection Matrix

glMatrixMode(GL_MODELVIEW);
glPopMatrix();

//glDisable(GL_BLEND);

glDepthMask(GL_TRUE);
glDisable(GL_TEXTURE_2D);

glDisable(GL_ALPHA_TEST);

Share this post


Link to post
Share on other sites
BlackSheep    100
In the code above, you''ve commented out the lines that enable and set the blending functions. Is that a mistake?W

When I ripped NeHe''s code for doing transparent text, I found the only way I could get it to work was if all four channels were identical (r,g,b & a): 255 where the text is, 0 where its transparent. I then did a tiny blur to soften the edges. I also force the alpha channel to 1 in glColor4f(). Doesn''t really make logical sense, but it works fine. I''m in the process of re-writing it, as a 32bit TGA is overkill for a simple monochrome font. Oh well.

Share this post


Link to post
Share on other sites
Arch@on    100
Exactly, I can get it somehow transparent with 8-bit TGA, however the text is mildly transparent too and when on white background its completely transparent.

Share this post


Link to post
Share on other sites