Jump to content
  • Advertisement
Sign in to follow this  
ryt

rendering to texture

This topic is 4860 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 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?

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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 method
texture = new Texture(renderer.Device, 128, 128, 1, Usage.RenderTarget, Format.X8R8G8B8, Pool.Default);
surface = texture.GetSurfaceLevel(0);

//Render to texture method
private 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 texture
public 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.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!