[MDX] Texture from Color

Started by
7 comments, last by Dave Hunt 18 years ago
Is there a simple way of creating a Direct3D.Texture by specifying a ColorValue? Would I first have to create a Drawing.Bitmap, and then create the texture using that stream? Or is there an easier way?
Advertisement
Any tips? :S
I don't quite follow, do you want to create a texture that just consists of one colour? If so, why? Just use vertex colour.
If you absolutely must, you'll almost certainly have to create a 1x1 texture, lock it, put one pixel into it, then unlock it.
You can simply do this by locking the texture and writing the color information to it in the appropriate color format. The format you write has to match the format you used to create the texture, so for an A8R8G8B8 texture you can use this code:

// lock textureint[,] data = (int[,])frameTexture.LockRectangle( typeof(int), 0, LockFlags.None, width, height );for (int v = 0; v < height; v++){	for (int u = 0; u < width; u++)	{							// set color data on texture		data[v,u] = unchecked((int)0xffff0000); // red, you can use Color.ToARGB() to obtain this	}}// unlock textureframeTexture.UnlockRectangle(0);



@Steve:

As for why you would want to use these textures over vertex color, I've found it to be a good thing for HLSL shaders and multi subset meshes. I had some meshes with subsets that either used material diffuse color or a texture. By using a texture for all subsets (even when they're only a single color) you'll only need to use the texture for the final color, saving you at least a multiplication and at best an if statement in the pixel shader.
Rim van Wersch [ MDXInfo ] [ XNAInfo ] [ YouTube ] - Do yourself a favor and bookmark this excellent free online D3D/shader book!
Quote:Original post by remigius
As for why you would want to use these textures over vertex color, I've found it to be a good thing for HLSL shaders and multi subset meshes. I had some meshes with subsets that either used material diffuse color or a texture. By using a texture for all subsets (even when they're only a single color) you'll only need to use the texture for the final color, saving you at least a multiplication and at best an if statement in the pixel shader.
Ah, I always forget about pixel shaders [smile]
Thanks for the replies,

Im not using the vertex color since Im creating a 2D application using sprites :P, but thanks for that info as well.

Quote:Original post by phb5000
Thanks for the replies,

Im not using the vertex color since Im creating a 2D application using sprites :P, but thanks for that info as well.


That's not a reason not to use vertex colors. You can get some nifty effects by altering the vertex color of your sprites.
How would I manipulate the verticies of a sprite?
I never knew that sprites consisted of verticies.
An MDX Sprite is stored internally as a textured quad or pair of triangles. You'll notice that the Draw() and Draw2D() methods include a color parameter. This parameter will modulate the vertex colors by the specified value. Normally, you would specify Color.White for this value and get the original texture colors. However, you can specify other colors to get nifty effects like fading, shades of red to indicate damage levels, etc.

This topic is closed to new replies.

Advertisement