I found a rather strange bug this morning and I wrote a small test code to reproduce it:
I am creating a quad with two alpha enabled textures on it. In normal use, the quad is displayed and the textures are blended correctly.
But if I use a totally unrelated 2D command (in my case draw2DRectangle) then the second texture of the quad is not displayed.
The code is the following:
Code: Select all
int main(int argc,char** argv)
{
IrrlichtDevice *device = createDevice( video::EDT_OPENGL,dimension2du(800,600),32,false,false,true);
IVideoDriver* driver = device->getVideoDriver();
ISceneManager* smgr = device->getSceneManager();
SMesh* pMesh = new SMesh();
SMeshBuffer *pBuffer = new SMeshBuffer();
pMesh->addMeshBuffer(pBuffer);
pBuffer->drop();
int nVertices = 4;
pBuffer->Vertices.reallocate(nVertices);
pBuffer->Vertices.set_used(nVertices);
pBuffer->Vertices[0] = S3DVertex2TCoords(-1,1,0, 0,0,1, video::SColor(255,255,255,255), 0,0,0,0);
pBuffer->Vertices[1] = S3DVertex2TCoords(1,1,0, 0,0,1, video::SColor(255,255,255,255), 1,0, 1,0);
pBuffer->Vertices[2] = S3DVertex2TCoords(1,-1,0, 0,0,1, video::SColor(255,255,255,255), 1,1,1,1);
pBuffer->Vertices[3] = S3DVertex2TCoords(-1,-1,0, 0,0,1, video::SColor(255,255,255,255), 0,1,0,1);
pBuffer->Indices.reallocate(6);
pBuffer->Indices.set_used(6);
pBuffer->Indices[0]=0;
pBuffer->Indices[1]=1;
pBuffer->Indices[2]=2;
pBuffer->Indices[3]=0;
pBuffer->Indices[4]=2;
pBuffer->Indices[5]=3;
ISceneNode *node = smgr->addMeshSceneNode(pMesh);
node->setMaterialFlag(EMF_LIGHTING, false);
video::IImage* tImg1 = driver->createImage(ECF_A8R8G8B8, core::dimension2du(128,128));
video::IImage* tImg2 = driver->createImage(ECF_A8R8G8B8, core::dimension2du(128,128));
tImg1->fill(SColor(255,255,0,0));
tImg2->fill(SColor(128,255,255,255));
ITexture *texture1 = driver->addTexture("texture1", tImg1);
ITexture *texture2 = driver->addTexture("texture2", tImg2);
tImg1->drop();
tImg2->drop();
node->setMaterialTexture(0, texture1);
node->setMaterialTexture(1, texture2);
node->setMaterialType(E_MATERIAL_TYPE::EMT_TRANSPARENT_ALPHA_CHANNEL);
smgr->addCameraSceneNode(0, vector3df(0,0,-4), vector3df(0,0,1));
int i=0;
while(device->run())
{
driver->beginScene(true, true, SColor(255,255,255,255));
smgr->drawAll();
if(i>50)
{
driver->draw2DRectangle(video::SColor(255,0,0,0),core::rect<s32>(0,0,50,50));
}
driver->endScene();
i++;
i = i % 100;
}
device->drop();
return 0;
}
I did check the code and I guess the problem is here:
Code: Select all
void COpenGLDriver::setRenderStates2DMode(bool alpha, bool texture, bool alphaChannel)
{
if (CurrentRenderMode != ERM_2D || Transformation3DChanged)
{
// unset last 3d material
if (CurrentRenderMode == ERM_3D)
{
if (static_cast<u32>(LastMaterial.MaterialType) < MaterialRenderers.size())
MaterialRenderers[LastMaterial.MaterialType].Renderer->OnUnsetMaterial();
}
Thanks.