# OpenGL Primary Color vs. Diffuse (irrelevant title)

This topic is 4349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Now, I was tinkering around today trying to get my font stuff caught up with Evil Steve (who, funnily enough is using D3D for his rendering). What we both did is load the fonts white onto a pure-alpha texture, so that we could color them on the fly with diffuse colors. Coming from D3D (years ago), diffuse colors are the color components defined per-vertex. Apparently this is not the case with OpenGL, which defines diffuse per-material. My dilemma is - is there anyway to emulate the behavior of blending together the primary color with the texture fragment such that it would behave as if it were the diffuse? (Aside from writing a shader, which would be... ugh.) The Red Book suggested using GL_COMBINE with various ... stuffs, and the one that was the closest was GL_INTERPOLATE. It interpolated by a weighted value. Which, I mean, was close, but not what I wanted. Basically, I need a way to color my fonts which can be batched with everything else that's being rendered (everything is drawn in 1 call; though this could be changed, I rely on drawing order to sort stuff right now, so batching per-material is not possible. I'd have to break that 1 call into an ungodly number of calls to change materials). Ugh, I suck at explanations. I guess, uhh, what I need is like -
Color Fragment | Texture Fragment | Desired Output
(r,g,b)             (1,1,1)            (r,g,b)
(1,1,1)             (r,g,b)            (r,g,b)
(rf,gf,bf)          (rs,gs,bs)         actually... I have no idea. 
Auuguhhh I know this isn't going to work. Time to approach from a different perspective, I think.
Color Fragment | Texture Fragment | Desired Output
(rf,gf,bf)          (rs,gs,bs,0)       (rf,gf,bf)
(rf,gf,bf)          (rs,gs,bs,1)       (rs,gs,bs)
Hurr, from that we can induce that the formula that I need is - Cf*(1-As)+Cs*As ...and my Red Book is packed in the car since I'm leaving for next semester tommorrow. ARGH. Any ideas on this one guys? :S

##### Share on other sites
Quote:
 Coming from D3D (years ago), diffuse colors are the color components defined per-vertex. Apparently this is not the case with OpenGL, which defines diffuse per-material.

If you look at D3D9, it's pretty similar to OpenGL in how this works. The diffuse color comes from the material, but when you enable COLOR_MATERIAL and set ColorMaterial to AMBIENT_AND_DIFFUSE, you typically get what you want.

When it comes to the combiners, the interpolation function you want is, likely, DECAL. Note that vertex lighting comes in the diffuse color, so if your object is lit, the alpha=1 parts of the texture will be un-lit.

You don't need the red book, btw, the OpenGL specification PDF is available online (on OpenGL.org), and explains everything in great detail. I use no other reference for the non-extension stuff.

##### Share on other sites
Hrm, I was tinkering around with some GUI code, and for some reason the font stuff is magically working the way I wanted it too. I'm not sure exactly what happened.... but yeah.

Thanks :)

##### Share on other sites
Excuse me if this is horribly naive, but what is wrong with gl_color3f? Are you trying to batch multi-colored text into a single VB? I would consider the different colors the same as different textures, and as such they couldn't be batched.

Of course, I'm blitting my fonts with SDL and using a "software shader" to colorize them. So, I'm clearly not concerned about speed.

1. 1
Rutin
21
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 13
• 38
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631715
• Total Posts
3001868
×