Operating System: Linux
Render System: OpenGL3+
After getting my meshes to render in the correct order with Unlit and transparency, I've hit another issue. Sorry for being so bad at graphics programming...
Anyway, the issue is that I want to scale a mesh, that I've built using pixel size, to fit another size. But when the scale factor (I use the same for both X and Y) is under 1.0 the texture becomes transparent all of a sudden (the texture has an alpha channel but all pixels are fully opaque) so I have no idea why that happens:
The logo in the center should not be visible.
Then when I increase the window size so that the scale is over 1.0 the transparency suddenly fixes itself:
This is my code for doing the scaling (width and height are the window size to fit the mesh to):
Code: Select all
DLLEXPORT void WidgetWithStandardResources::SetAllocatedSize(int width, int height)
{
if(!Node)
return;
if(width == NaturalWidth && height == NaturalHeight) {
Node->setScale(1, 1, 1);
return;
}
const float scaleWidth = width / static_cast<float>(NaturalWidth);
const float scaleHeight = height / static_cast<float>(NaturalHeight);
const auto scale = std::min(scaleWidth, scaleHeight);
const int widthDifference = width - NaturalWidth * scale;
const int heightDifference = height - NaturalHeight * scale;
Node->setScale(scale, scale, 1);
Node->setPosition(X + widthDifference / 2, -(Y + heightDifference / 2), 0);
}
At least I confirmed with RenderDoc that the texture correctly has 255 as alpha. There's also no errors in the Ogre log.
If I disable the transparency on the blendblock then it works correctly, but I've linked that to checking if the texture has an alpha channel, so I don't want to use this approach and add a separate flag for overriding the alpha channel from the texture. I also tried to set the bounds to be bigger on the mesh and scaling up in the Z direction, but those had no effect. Any help with this is greatly appreciated.