Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

The Frugal Gourmet

Fading from Texture 1 to Texture 2 (C#)

This topic is 5219 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

I'm attempting to fade texture 2 in as I fade out texture 1. I've been able to do this in the multitexturing utility, but for some reason my code does not achieve this effect (it just gets lighter until it becomes completely white). Any help would be appreciated.
private void BlendTextures()
	RenderToSurface rts = new RenderToSurface(_device, _textureSize, _textureSize, Format.A8R8G8B8, true, DepthFormat.D16);

	Surface surfaceCombined;

	VertexBuffer vb = GraphicsUtility.CreateTransformedQuad(Pool.Managed, _textureSize, Color.White, _device, new Point3D(0.0f, 0.0f, 1.0f));
	surfaceCombined = _textureCombined.GetSurfaceLevel(0);

	Viewport vp = new Viewport();
	vp.Width = _textureSize;
	vp.Height = _textureSize;
	vp.MaxZ = 1.0f;

	rts.BeginScene(surfaceCombined, vp);

	_device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Transparent, 1.0f, 0);

	_device.SetStreamSource(0, vb, 0);
	_device.RenderState.AlphaBlendEnable = true;
	_device.RenderState.AlphaTestEnable = false;
	_device.RenderState.TextureFactor = Color.FromArgb(_alphaBlendFactor, Color.White).ToArgb(); // the _alphablendfactor increases every frame...

	_device.RenderState.SourceBlend = Blend.SourceAlpha;
	_device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
	_device.TextureState[0].ColorOperation = TextureOperation.Modulate;
	_device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;

	_device.TextureState[1].ColorOperation = TextureOperation.BlendFactorAlpha;
	_device.TextureState[1].ColorArgument1 = TextureArgument.TextureColor;

	_device.SetTexture(0, _texture);
	_device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);

	_device.SetTexture(1, _texture2);
	_device.DrawPrimitives(PrimitiveType.TriangleFan, 0, 2);


[edited by - The Frugal Gourmet on April 4, 2004 6:45:56 PM]

Share this post

Link to post
Share on other sites
BTW, if anyone has any other tips on how to take one texture and fade it out while taking another texture and fading it in I would really appreciate it.

In this case, I can''t seem to get the multitexturing to work they way I expect after determining the states from the MFCTex application in the SDK.

But, any other tips, code, etc. on multitexturing & fading would be appreciated as well.

Share this post

Link to post
Share on other sites
two quads, one texture each. One quad set alpha value from 1.0 to 0.0, and the other quad set alpha value from 0.0 to 1.0.

Share this post

Link to post
Share on other sites
Right, but I want to slowly fade the textures over time. What's the best way to do that?

The alpha values are determined from the texture information, am I right? So, how do I set states to achieve a crossfade like what I described?

[edited by - The Frugal Gourmet on April 4, 2004 8:50:04 PM]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!