modifying texture color at runtime

Started by
4 comments, last by mattnewport 19 years, 6 months ago
Hi all, How to modify / change the color of texture at runtime? Is it done by looping through each pixel? Is this way not too slow? That's all. Thanks for your attention.
Advertisement
thats one way to do it. another way is you can modulate the texture color with the color of the vertices.
[size=2]aliak.net
I believe you can also do it by making a texture stage that modulates texture colour with a constant. I don't have the DirectX help handy because I'm not at home - so you'll have to find the commands for yourself.
The Trouble With Robots - www.digitalchestnut.com/trouble
Thanks for the replies.

My specific question is this: How to change a particular color into another color? For example, how to change all blue pixels into red?

What texture operation I should perform?

Thanks a lot.
>> Is it done by looping through each pixel?

Does anybody know how to modify a single pixel in DirectX? Do I have to modify the texture memory directly in or is there a function to help me?
Quote:Original post by jammyt
>> Is it done by looping through each pixel?

Does anybody know how to modify a single pixel in DirectX? Do I have to modify the texture memory directly in or is there a function to help me?

Take a look at the D3DXFillTexture functions: D3DXFillTexture() takes a texture and a function pointer to a callback function which is called for every texel in the texture with the texture coordinates, the size of the texel and an arbitrary block of user data. You can write the texel as a float4 vector value and D3D handles all the format conversion for you. D3DXFillTextureTX() is similar only it lets you write the callback function in HLSL which is quite neat - this is also used in the Effects framework to let you procedurally generate textures from an HLSL function in the Effects file.

These functions aren't really intended to be used every frame - they're fine for initialising a texture but if you're wanting to modify a texture every frame you're probably better off just locking the texture and writing to it yourself.

Game Programming Blog: www.mattnewport.com/blog

This topic is closed to new replies.

Advertisement