I just looked at this and the problem is fixed in IrrSpintz, but here's the changed that were necessary for this change. ( Note, IrrSpintz code being copied and pasted in would not work, you must make the changes below. IrrSpintz keeps better track of renderStates between 2D and 3D modes and Materials, so much less renderState changes are needed when setting 2D mode. So, here's the code changes :
All of these code changes are in COpenGLDriver.cpp
In all of the draw2DImage functions, change the change the call to setRenderStates2DMode to pass true for the first arg. So change -
Code: Select all
if (useAlphaChannelOfTexture)
setRenderStates2DMode(false, true, true);
else
setRenderStates2DMode(false, true, false);
to
Code: Select all
if (useAlphaChannelOfTexture)
setRenderStates2DMode(true, true, true);
else
setRenderStates2DMode(true, true, false);
And then, in the setRenderStates2DMode function, change the function to this :
Code: Select all
//! sets the needed renderstates
void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
{
if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
{
// unset last 3d material
if (CurrentRenderMode == ERM_3D && Material.MaterialType >= 0 &&
Material.MaterialType < (s32)MaterialRenderers.size())
MaterialRenderers[Material.MaterialType].Renderer->OnUnsetMaterial();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
Transformation3DChanged = false;
glDisable(GL_DEPTH_TEST);
glDisable(GL_FOG);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glDisable(GL_LIGHTING);
if (MultiTextureExtension)
{
extGlActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
extGlActiveTextureARB(GL_TEXTURE0_ARB);
}
glEnable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDisable(GL_ALPHA_TEST);
glCullFace(GL_BACK);
}
if (texture)
{
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (alphaChannel)
{
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT);
}
else
{
if (alpha)
{
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
}
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
}
}
}
else
{
if (alpha)
{
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_ALPHA_TEST);
}
else
{
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glDisable(GL_BLEND);
glDisable(GL_ALPHA_TEST);
}
}
CurrentRenderMode = ERM_2D;
}
The logic change in the setRenderStates2DMode function becomes this -
- If there is a texture and alphaChannel is true then use the texture as the source of alpha with the calls :
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_TEXTURE);
- If there is no texture and alpha is true then use the vertex color as the alpha source with the calls :
glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA_EXT, GL_REPLACE);
glTexEnvf(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_EXT, GL_PRIMARY_COLOR_EXT);
And we enable blend and set the proper BlendFunc
- Finally, at this point, we don't use alpha values, so disable alpha blend all together and ignore alpha values that are present.
I've tested this, with this change only applied to SVN Irrlicht rev 165, and it works for me.
I guess this should be moved to the Bug Reports forum.