OpenGL Texture Color Override

waslap
waslap used Ask the Experts™
on
In order to render fonts in opengl, I render a set of textures at startup each containing a separate glyph render white on black. my problem is that i want font colors also. of course i cannot render a set of textures in each conceivable color i would want to have text in. my question is, how can i achieve the capability to render my font textures in a different color than from what they are drawn in the textures e.g. my textures are white but i want to draw text in red. what opengl texture parameters do i need to set to achieve this.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can try the Material-setting and/or light-settings for the polygon with the mapped Texture(s).

Commented:
yes, set the materials/lights to be reflective, and then shine a red light on your texture.

or a blue one, or whatever.

-john

Author

Commented:
shining a colored light onto it will affect surrounding elements as well. i merely want the text elements in red.
Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

>> shining a colored light onto it will affect surrounding elements as well

No, only if you explicitely do so. You can define this light only to affect that Texture.
>> yes, set the materials/lights to be reflective, and then shine a red light on your texture.
>> or a blue one, or whatever.

that's what i said john .. ;)

Author

Commented:
can someone please provide a snippet showing how one would make a light illuminating only a specific quad ?
You can Enable/Disable specific lights before you render those quads:
This code assumes, that light 0-2 are for the rest of the scene, and light 3 is for the Text.

//switch off light 0-1
glDisable(GL_LIGHT0);
glDisable(GL_LIGHT1);
glDisable(GL_LIGHT2);
// switch on the Text-Light
glEnable(GL_LIGHT3);

... render your text here

// switch off the text light
glDisable(GL_LIGHT3);
// switch on normal scene lights
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHT2);


thats it ..
you could even use light 3 for the rest of the scene too, then you would have to change the light-settings for that light before you render the text, and restore the light-settings after your text was rendered
Here is a tutorial about OpenGL lighting. It covers the issue better than we could do here:

http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=07

Commented:
ike,

I agree, that's what you said.

Like I said, "Yes"..

I was hoping to make it clearer for him to understand.

-john

Commented:
ike,

I agree, that's what you said.

Like I said, "Yes"..

I was hoping to make it clearer for him to understand.

-john

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial