Color is lost when setting color before setting texture to material

Hi Experts,

I am writing a SVF file. My model has diffuse color and texture. When I set the color to material first; then set the texture to the same material, the color is overridden.

The codes look like that:

        // Load texture from file
        SUTextureRef tex = SU_INVALID;
        SU_CALL(SUTextureCreateFromFile(&tex, "SU_Logo_Color.png", 1.0, 1.0));

        // Create material
        SUMaterialRef mat = SU_INVALID;
        SU_CALL(SUMaterialCreate(&mat));

        // Set color first
        SUColor color;
        color.red = static_cast<SUByte>(255);
        color.green = static_cast<SUByte>(0);
        color.blue = static_cast<SUByte>(255);
        SUMaterialSetColor(mat, &color);

        // Then set texture
        SU_CALL(SUMaterialSetTexture(mat, tex));

        SUMaterialSetType(mat, SUMaterialType_ColorizedTexture);

If I set the texture first and then set color, the color can be kept. Is it as designed?

In SketchUp application, if you assign a color to body and then assign a texture (with transparency); the color is still kept.

@DanRathbun @tt_su

The issue in my first post is talking the color lost issue and the texture is kept when the order of setting color and texture is changed.

Thomas’s post “How does colorised texture work” is talking how the color is applied to texture when colorized type is set.

There are different issues, right?

I do believe this is what your code snippet above did …

SUMaterialSetType(mat, SUMaterialType_ColorizedTexture);

My main advice is to do what actually works.

There may be issues …

@xqtyler If you feel there is another issue, please log in the issue tracker with code snippet and test model file.