Question

My current renderer draws forms by the position and color of their vertices. It can't handle textures yet.

struct Form
{
    unsigned int Positions, Colors, Elements, Program;
};

Now I want to implement the capability of textures. Since there won't be forms without texture but colors in the final game I want to replace the color feature instead of developing a alongside feature.

So the renderer has to draw forms by the position and texture coordinate of their vertices now.

struct Form
{
    unsigned int Positions, Coordinates, Elements, Texture, Program;
};

So far, so good. But without the ability to render without texture my application can't draw forms if their image file doesn't exist or can't be loaded for some reason. Therefore I want to implement a fallback to a given solid color (say pink) if the image file can't be loaded.

How can I realize this fallback without completely developing two alongside features? Is there a common approach? I wish that this could be done in a shader. Or maybe I could send a pink texture to the video card and then treat all forms as equal. Sadly I have no idea how to implement that or if is even possible.

Was it helpful?

Solution 2

If you sample from a texture unit to which no texture is bound, the samples retrieved always come out white; it is not an error to sample from a texture without a complete texture bound. You can hence use that white to modulate it with the fallback color.

OTHER TIPS

I've solved this problem by creating a dummy checker texture procedurally and assigning it to any object which does not have any valid texture. It is not based on vertex color or mesh color, but works. And no shader changes required, only a few lines of code for checking null textures.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top