Skip to main content
gamedev.net
🔒 Locked

rendering to texture

Started by ryt 1 reply 450+ views
Original Post
ryt
ryt
i rendered a triangle to a texture and then displayed theat texture. it works ok but i get a red triangle, and i have set it to be white, what could be the problem?
Xpyder
Xpyder
Check the following link:
http://www.pieterg.com/Tutorials/tutorial7.php

It has a tutorial on Render to Texture, you may be able to compare Pieter's source to your own.
JUST-CODE-IT.NETManaged DirectX & C# TutorialsForumsArticlesLinksSamples
Armadon
Armadon
If you are using lights make sure you have the correct material set.
Make sure that when you rendered the triangle that the correct vertex format was set. Recheck all your state settings such as textures are set correctly, you are clearing the surface before rendering to it.

Example C#
//Create some variables for the render to texture methodtexture = new Texture(renderer.Device, 128, 128, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);surface = texture.GetSurfaceLevel(0);//Render to texture methodprivate void RenderToTexture(){	Surface oldRenderTarget = renderer.Device.GetRenderTarget(0);	renderer.Device.SetRenderTarget(0, surface);	renderer.Device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.Black.ToArgb(), 1.0f, 0);	renderer.Device.BeginScene();	renderer.Device.Material = material;	renderer.Device.Transform.World = matWorld;	cube.DrawSubset(0);	renderer.Device.EndScene();	renderer.Device.SetRenderTarget(0, oldRenderTarget);}//Call the Render method and Render to texture first.//The Sprite will then render our rendered-to-texture texturepublic void Render(){	RenderToTexture();	renderer.BeginRender(Color.Black);	renderer.Device.Material = material;	renderer.Device.Transform.World = matWorld;	cube.DrawSubset(0);	using(Sprite s = new Sprite(renderer.Device))	{		s.Begin(SpriteFlags.None);		s.Draw(texture, new Rectangle(0, 0, 128, 128), new Vector3(0.0f, 0.0f, 0.0f), new Vector3(0.0f, 0.0f, 0.0f), Color.White);		s.End();	}	renderer.EndRender();}


I hope this helps.
Take care.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.