Jump to content
  • Advertisement
Sign in to follow this  
Maxim Skachkov

[MDX] Blend to zero predefined color on textured object

This topic is 4442 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I need to place the signs near the roads. I have the images of all the signs. The signs may differ by their form. I need the fast productive method to modeling signs and i think that it's a hard way to calculate geometry and uv-coords for each sign-form (e.g. rounded triangle or more complex forms). Also I think that easier not to use alpha channel for each sign image. Instead I want to texture a rectangle-form with a sign image. To visualize needed sign-form I intend to blend predefined border texture color to zero. How can i blend to zero predefined color on textured object? From morning I write the code, than blend all textured rectangle:

ADevice.TextureState[0].AlphaOperation = TextureOperation.SelectArg1;
ADevice.TextureState[0].AlphaArgument1 = TextureArgument.TFactor;

ADevice.RenderState.SourceBlend = Blend.SourceAlpha;
ADevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;
ADevice.RenderState.TextureFactor = System.Drawing.Color.FromArgb( 100, System.Drawing.Color.White).ToArgb() ;


ADevice.RenderState.AlphaBlendEnable = true;

ADevice.DrawPrimitives();		

ADevice.RenderState.AlphaBlendEnable = false;


Hope hearing from you soon!

Share this post


Link to post
Share on other sites
Advertisement
You stated that you didn't want to use the alpha channel of the image, and at first I thought you meant that because you didn't want to perform alpha blending. However, you code is alpha blending (which you must do). It would indeed be easier to just save alpha to the texture.

Do you want to blend TO 0 as in a gradient blend, or do you want all one color to be set to 0 alpha? The second can be done when you load the texture. Your code is using TFactor which will apply the alpha value to the whole sign. You just need to use the alpha values from the texture. When you call LoadTextureFromFileEx(...), you can provide the color to replace with an alpha value of 0. Then, set your render states to use the texture alpha value. Then enable alpha blending, and render.

EDIT: I just re-read and understood what you're looking for. You want the rounded corners of a sign. I just removed some code I put in. See my comments above.

Chris

Share this post


Link to post
Share on other sites
Thx, Supernat02!

I want one color to be set to 0 alpha.
LoadTextureFromFileEx(...) forward me to overload of TextureLoader.FromFile() method with colorKey parameter [MDX9].

The code:



texture = TextureLoader.FromFile( ADevice, @".\Textures\leftTurn2.bmp", D3DX.Default,D3DX.Default,D3DX.Default,0,
Format.A8R8G8B8, Pool.Managed,Filter.Triangle|Filter.Mirror, Filter.Triangle|Filter.Mirror,
System.Drawing.Color.FromArgb(255,0,255).ToArgb() );


ADevice.RenderState.SourceBlend = Blend.SourceAlpha;
ADevice.RenderState.DestinationBlend = Blend.InvSourceAlpha;
ADevice.RenderState.AlphaBlendEnable = true;

ADevice.DrawPrimitives(PrimitiveType.TriangleStrip, 0, 2);

ADevice.RenderState.AlphaBlendEnable = false;




Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!