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

The Frugal Gourmet

Fading from Texture 1 to Texture 2 (C#)

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
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