Multiply Blending Problem
You'll have to use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if you're using the stuff from crash landing because it premultiplies the alpha on load. It's not much of a problem to work around really, but I wish they didn't force it. Blending still works fine for me, but you'll need to multiply all color values times the alpha you wish to use, like:
glColor4f(red * alpha, green * alpha, blue * alpha, alpha)
glColor4f(red * alpha, green * alpha, blue * alpha, alpha)
Quartz simply uses premultiplied alpha a lot, which I believe is a left over performance hack, as pre-multiplied blending is faster in software.
AnotherJake Wrote:You'll have to use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); if you're using the stuff from crash landing because it premultiplies the alpha on load. It's not much of a problem to work around really, but I wish they didn't force it. Blending still works fine for me, but you'll need to multiply all color values times the alpha you wish to use, like:
glColor4f(red * alpha, green * alpha, blue * alpha, alpha)
So, I use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA), and multiply all the colours by the alpha channel value? (They're textured quads)
When I use glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA) I seem to lose the ability to set the alpha and colour of vertecis (e.g., draw a textured quad at half opacity). I haven't tried it in conjunction with the above though. I'll give it a go on Monday then get back to you with the results. Cheers
You can still adjust both the alpha and color of vertices, they just have to be premultiplied as well.
Instead of glColor4f(r, g, b, a) you need to use glColor4f(r*a, g*a, b*a, a).
Does that make sense?
Instead of glColor4f(r, g, b, a) you need to use glColor4f(r*a, g*a, b*a, a).
Does that make sense?
Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Skorche Wrote:You can still adjust both the alpha and color of vertices, they just have to be premultiplied as well.
Instead of glColor4f(r, g, b, a) you need to use glColor4f(r*a, g*a, b*a, a).
Does that make sense?
It does make sense, cheers, but I can't try it out until monday, cos the mac is there.
It doesn't explain why, when I put the graphics into the lander demo, they look correct, even when I use;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
It works! I don't understand why, but it works! You guys are LIFESAVERS, This is the single most awesome thread on the internets.
For the benefit of someone else who might stumble across the same problem, this is the change I made...
float fOpacity = m_dwOpacity;// / 255.0f;
float temp = fOpacity / 255.0; //Get a normalised version of the opacity
GLubyte fRed = m_fRed * temp;// multiply each colour by normalised opacity
GLubyte fGreen = m_fGreen * temp;;// multiply each colour by normalised opacity
GLubyte fBlue = m_fBlue * temp;// multiply each colour by normalised opacity
GLubyte colors[] = {fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity};
glColorPointer(4,GL_UNSIGNED_BYTE,0,colors);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
For the benefit of someone else who might stumble across the same problem, this is the change I made...
float fOpacity = m_dwOpacity;// / 255.0f;
float temp = fOpacity / 255.0; //Get a normalised version of the opacity
GLubyte fRed = m_fRed * temp;// multiply each colour by normalised opacity
GLubyte fGreen = m_fGreen * temp;;// multiply each colour by normalised opacity
GLubyte fBlue = m_fBlue * temp;// multiply each colour by normalised opacity
GLubyte colors[] = {fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity, fRed, fGreen, fBlue, fOpacity};
glColorPointer(4,GL_UNSIGNED_BYTE,0,colors);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| pbuffer blending problem on macmin g4 | madjerry | 4 | 3,279 |
Nov 27, 2009 03:14 AM Last Post: madjerry |
|
| general blending versus texture blending questions | WhatMeWorry | 2 | 4,310 |
Dec 7, 2006 02:43 PM Last Post: arekkusu |
|

