I have a opencv mat and a StaticModel loaded from a file which I converted a collada to mdl. StaticModel loads good with it’s original texture. but I want to change it dynamically.
assert(!cvWraper.mat.empty());
// I get the model
StaticModel *staticModel = mNode->GetComponent<StaticModel>();
assert(staticModel != nullptr);
// then I get the texture from it's material
Texture *textureBase = staticModel->GetMaterial(0)->GetTexture(TU_DIFFUSE);
assert(textureBase != nullptr);
Texture2D *texture = dynamic_cast<Texture2D*>(textureBase);
assert(texture != nullptr);
bool success = true;
// And I update the texture
if(texture->GetWidth() != cvWraper.mat.cols ||
texture->GetHeight() != cvWraper.mat.rows ||
texture->GetFormat() != GL_RGBA) {
texture->SetNumLevels(0);
success = texture->SetSize(cvWraper.mat.cols, cvWraper.mat.rows, GL_RGBA, TEXTURE_DYNAMIC);
assert(success);
}
success = texture->SetData(0, 0, 0, cvWraper.mat.cols, cvWraper.mat.rows, cvWraper.mat.data);
After the update I see no changes. Am I missing something? Is there a “Texture did update” function? I’m using OpenGL. If I force calling SetSize function above then I see black where the texture is supposed to be. Texture contains alpha components.
Thank you.