Fallback to a solid color if texture cannot be loaded

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.

Answers


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.


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.


Need Your Help

Not receiving any push notification in iPhone

ios iphone objective-c push-notification apple-push-notifications

I have made a sample PushTest app for Push Notification using this tutorial.

Apache doesn't show filesize/duration during downloading .dmg in browser?

apache filesize

I have a .dmg on my website for a Mac Software, but when i try to download this (even in different browsers), it doesn't show me the duration or the filesize. Could this be something i need to conf...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.