Advertisement

fonts & textures in OpenGL

Started by January 22, 2002 10:16 AM
38 comments, last by Spooky 22 years, 6 months ago
I think I''ve got a way for doing what you want : use lighting.

You have to enable lighting, and disable color material. Then you set your material to be emissive, this color being the color you want the text to be.
And set all the other material colors (specular, ambient, diffuse) to black.
I think it might work.
Otherwise, that means the bitmap forces the color.

Try this. If it still doesn''t work, I have another idea
I''ve just realized you didn''t disable lighting.
You gotta disable lighting, or else any call to glColor is useless !! (unless color material is activated, but I don''t think it is done correctly).
Advertisement
I did not disable lighting because I don''t use lighting. I never enable it in my code.
However I put the line glDisable(GL_LIGHTING) before that fragment and it still doesn''t work.
I didn''t use lights yet but I will try the method from your previous post. It will just take me a little more time (I am learning OpenGL and still have to learn about lights).
Thank you for your help.
If you want fast and easy, but limited, coloration, try masking the colors :

glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE); /* enable red, and disable everything else */
glPrint("My Red Text"); /* draw red text */
glColorMask(GL_FALSE, GL_FALSE, GL_TRUE, GL_FALSE); /* enable blue, and disable everything else */
glPrint("My Blue Text"); /* draw blue text */
glColorMask(GL_TRUE, GL_TRUE, GL_FALSE, GL_FALSE); /* enable red and green, and disable everything else */
glPrint("My Yellow Text"); /* draw yellow text (because red+green=yellow) */
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); /* don''t forget to reset the mask to their initial states */


IF THIS DOESN''T WORK, THERE IS A SERIOUS PROBLEM

It is limited because you can only draw black, white, red, green, blue, cyan, yellow and magenta strings.
Well it''s not really what I wanted but it is something at least.

MILLLION THANX TO YOU.

If anybody knows a solution to myu problem please let me know.

Does it work ?
If yes, then congrats.

I don''t like this method, though.

Indeed, NeHe''s tutorial #13 works fine on my computer (and the colors change with a simple call to glColor), so if the tutorial works fine for you, there is a way of making your program work fine too.

Could you please write down the states you enabled/disabled when the text is about to be displayed ?

btw, did NeHe''s tutorial work fine for you ?
Advertisement
Yes it both worked (the color masking ang the tutorial #13)

All I use in my code is GL_TEXTURE_2D and GL_DEPTH_TEST.
I enable this when I init GL and nothing else.
But I disable theese both before I print the string, so nothing is enabled then...
The problem is as I said that when I reset the color to white after printing my string then my string is white, too. Even if I set the color to green prior to printing the string.
When I don''t reset the color to white all the textures become green.
There's only thing I can see that could make it goes wrong : texturing might not be enabled while the fonts are being built, eg :
glDisable(GL_TEXTURE_2D);
BuildFont();
glEnable(GL_TEXTURE_2D);

Or else I'm sorry but I would need some piece of code to take a look at it.

Edited by - vincoof on January 22, 2002 1:05:25 PM
I have tried it too. I loaded the bitmap with texture mapping turned off and it didn''t work. I loaded it withj textures turned on and it didn''t work either.

Well this is really strange.

I modified the code from lesson #13:
I disabled texture mapping.
changed the color
print the text
change the color to white
enable texture mapping.

and the color of the string still changes randomly as it should.
I really don''t understand why doesn''t the same work in my code.
It seems someone up there doesn''t like me. :-(
If you want, I''ll take a look at your code. Zip it up and either email it to me or post a link.

Jason

This topic is closed to new replies.

Advertisement