Issue with multi-texture and freetype?

Discuss programming topics that involve the OpenGL API.
Post Reply
Feared
Posts: 95
Joined: Fri Jun 11, 2010 11:58 pm
Location: Wylie, TX

Issue with multi-texture and freetype?

Post by Feared »

I believe I am having an issue with freetype and multi-texturing. If you look at the bottom left above the sbar in the image I provide you will see some garbage. It's correctly loading the font but the textures seem to smash together.
Can anyone explain this? I'm new to OpenGL and I'm trying to add a proper font renderer to Quake. :) Thank you very much.

Image
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

many engines have a -nomtex, if you think its multitexture, try that.
Normally, multitexture is only active for as long as its used. Traditionally the function that switched it on is the one that is meant to switch it off.

And yes, those look like hud images. Are you sure you switched textures correctly? If you're using Draw_Pic, you will need to make sure you generate the correct glpics.

If you want an average font to be readable, it needs to be at least 12 pixels high (instead of 8), you need to support variable-width chars correctly, and you need to align your font and texture coords to the screen pixels correctly. Failure with any of those will result in ugly unreadable bluryness, depending on the font. Don't just convert font to conchar-grid on load, unless you like laughing.

For further reading, FTE contains support for freetype2 already, note that it uses vertex arrays and its rendering backend.
Downsider
Posts: 621
Joined: Tue Sep 16, 2008 1:35 am

Post by Downsider »

GL_CLAMP vs GL_REPEAT? Try setting one of those after using freetype. Might be the issue.
mh
Posts: 2292
Joined: Sat Jan 12, 2008 1:38 am

Post by mh »

I doubt if there's a specific problem with freetype and multitexturing. All freetype does is create a font bitmap that you then convert to a texture using normal OpenGL calls, so for my money what's happening is that you have the extra texture unit(s) still active and/or enabled.

For debugging purposes, stick this block of code before you do any text drawing:

Code: Select all

glActiveTexture (GL_TEXTURE3);
glDisable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE2);
glDisable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE1);
glDisable (GL_TEXTURE_2D);
glActiveTexture (GL_TEXTURE0);
glEnable (GL_TEXTURE_2D);
That'll confirm it quickly enough. Then you need to find out where the correct place in your code to do this is, so run your engine with GLIntercept and log your GL calls, then check the log to get a better handle for what's going on.
We had the power, we had the space, we had a sense of time and place
We knew the words, we knew the score, we knew what we were fighting for
Feared
Posts: 95
Joined: Fri Jun 11, 2010 11:58 pm
Location: Wylie, TX

Post by Feared »

Spike wrote:many engines have a -nomtex, if you think its multitexture, try that.
Normally, multitexture is only active for as long as its used. Traditionally the function that switched it on is the one that is meant to switch it off.

And yes, those look like hud images. Are you sure you switched textures correctly? If you're using Draw_Pic, you will need to make sure you generate the correct glpics.

If you want an average font to be readable, it needs to be at least 12 pixels high (instead of 8), you need to support variable-width chars correctly, and you need to align your font and texture coords to the screen pixels correctly. Failure with any of those will result in ugly unreadable bluryness, depending on the font. Don't just convert font to conchar-grid on load, unless you like laughing.

For further reading, FTE contains support for freetype2 already, note that it uses vertex arrays and its rendering backend.
Alright so it isn't multi-texturing. I ran under -nomtex mode (which the engine supports) and no avail.
I am not using Draw_Pic, I am doing that my self. Thank you for the tips by the way, I prepared for most of this already thankfully. :)
mh wrote:I doubt if there's a specific problem with freetype and multitexturing. All freetype does is create a font bitmap that you then convert to a texture using normal OpenGL calls, so for my money what's happening is that you have the extra texture unit(s) still active and/or enabled.

For debugging purposes, stick this block of code before you do any text drawing: [snip]
That'll confirm it quickly enough. Then you need to find out where the correct place in your code to do this is, so run your engine with GLIntercept and log your GL calls, then check the log to get a better handle for what's going on.
I do what you say and it crashes on the first glDisable so I modified it to the following

Code: Select all

GL_SelectTexture(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
GL_SelectTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
This seems to run but does not fix anything, it is doing the same thing correct? Also, I am printing in SCR_UpdateScreen which should be just fine.
Downsider wrote:GL_CLAMP vs GL_REPEAT? Try setting one of those after using freetype. Might be the issue.
I don't believe I am using GL_CLAMP anywhere. GL_REPEAT is only used twice and I've tried changing that to no avail. I don't believe this is the issue, though as it certainly doesn't seem to look it. Thank you for the help so far guys. I'm still smashing my tits against code to try and figure this out.
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

you're using GL_Bind throughout, and not glBindTexture (even for texture creation)?
Feared
Posts: 95
Joined: Fri Jun 11, 2010 11:58 pm
Location: Wylie, TX

Post by Feared »

Spike wrote:you're using GL_Bind throughout, and not glBindTexture (even for texture creation)?
Funny that you say that. I've tried using glBindTexture and GL_Bind.
When I use GL_Bind rather than glBindTexture I get this instead of the above. Hmmm, this makes me think.

Image
(It changes depending on what's on screen now)
Spike
Posts: 2914
Joined: Fri Nov 05, 2004 3:12 am
Location: UK
Contact:

Post by Spike »

GL_Bind has an internal cache. if you use glBindTexture directly other than through GL_Bind, you break that internal cache, and everything goes kaboom, or at least doesn't switch textures properly as you would expect it to.
Feared
Posts: 95
Joined: Fri Jun 11, 2010 11:58 pm
Location: Wylie, TX

Post by Feared »

Spike wrote:GL_Bind has an internal cache. if you use glBindTexture directly other than through GL_Bind, you break that internal cache, and everything goes kaboom, or at least doesn't switch textures properly as you would expect it to.
This is definitely a binding issue. I'll look through the freetype texture code. Many thanks! I'll return later with a new shiny fixed image. :)
Post Reply