Jump to content
  • Advertisement
Sign in to follow this  

trouble with rendertarget...

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

Hi there, I have created a rendertarget and can't seem to get anything to render to it. It's real quirky. It worked before I upgraded to the 9800gx2 and Vista Ultimate. Is that the prob? Or am I just not checking for a cap properly. -Devin

Share this post

Link to post
Share on other sites
Hi devronious. Please tell us what version of directx you are using... it would really help. Since youre talking about 9800gx2, I assume that you have directx 10, but a confirmation would be nice.

Anyway, please post some code of what you are doing so that we can help you... it's kinda hard to tell what's wrong without the code.

Share this post

Link to post
Share on other sites

Thanks, I'm using MDX2.0 or DirectX9 managed.

Here's how I create the render target:

[source lang=c#]
this.renderTarget = new Microsoft.DirectX.Direct3D.Texture(

Then I draw textures to it via:

[source lang=c#]
/// <summary>
/// Draws the members that need to be updated onto the collage.
/// </summary>
public void DrawOld()
if (this.updatesInQue)

Device dev = this.initializer.Device;

#region Setup Device

#region Store Variables

bool Lighting = dev.RenderState.Lighting;
bool ZBufferEnable = dev.RenderState.ZBufferEnable;
Blend SourceBlend = dev.RenderState.SourceBlend;
Blend DestinationBlend = dev.RenderState.DestinationBlend;
bool AlphaBlendEnable = dev.RenderState.AlphaBlendEnable;
Cull cull = dev.RenderState.CullMode;
ShadeMode shade = dev.RenderState.ShadeMode;
Microsoft.DirectX.Matrix w = dev.Transform.World;
Microsoft.DirectX.Matrix v = dev.Transform.View;
Microsoft.DirectX.Matrix p = dev.Transform.Projection;
Surface rt = dev.GetRenderTarget(0);
Microsoft.DirectX.Direct3D.Texture tex = dev.GetTexture(0);


#region Set Device Variables

dev.RenderState.Lighting = false;
dev.RenderState.ZBufferEnable = false;
dev.RenderState.SourceBlend = Blend.SourceAlpha;
dev.RenderState.DestinationBlend = Blend.InvSourceAlpha;
dev.RenderState.AlphaBlendEnable = false;
dev.RenderState.CullMode = Cull.None;
dev.RenderState.ShadeMode = ShadeMode.Flat;

dev.Transform.World = Microsoft.DirectX.Matrix.Identity;
dev.Transform.View = Microsoft.DirectX.Matrix.Identity;
dev.Transform.Projection = Microsoft.DirectX.Matrix.OrthoOffCenterLH(
0, this.width, this.height, 0, 0, 1);

//Material mat = new Material();
//mat.Ambient = Color.DarkGray;
//mat.Diffuse = Color.White;
//mat.Specular = Color.White;
//dev.Material = mat;



dev.Indices = this.iBuffer;
dev.SetStreamSource(0, this.vBuffer, 0);
dev.VertexFormat = CustomVertex.TransformedTextured.Format;

Surface rts = this.renderTarget.GetSurfaceLevel(0);
dev.SetRenderTarget(0, rts);

Size s = new Size(rts.Description.Width, rts.Description.Height);

//Color bg = Color.Transparent;
Color bg = Color.Black;

if (this.clearRequired)
dev.Clear(ClearFlags.Target, bg, 1f, 0);
this.clearRequired = false;

int count = 0;
foreach (ICollageMember mem in this.members)
if (mem.UpdateRequired && !(mem.Engine.Usage == TextureEngineUsage.RenderTarget))
Microsoft.DirectX.Direct3D.Texture tx = mem.Engine.GenerateTexture();

SurfaceDescription nsd = tx.GetLevelDescription(0);
Size nsz = new Size(nsd.Width, nsd.Height);

if (this.doOnce)
TextureLoader.Save("c:\\Transfers\\" + mem.Engine.Name + ".jpg", ImageFileFormat.Jpg, tx);
dev.SetTexture(0, tx);
count * 6,
mem.UpdateRequired = false;

if (this.doOnce)
TextureLoader.Save("c:\\Transfers\\RenderTarget.jpg", ImageFileFormat.Jpg, this.renderTarget);
this.doOnce = false;

dev.Transform.World = w;
dev.Transform.View = v;
dev.Transform.Projection = p;
dev.SetTexture(0, tex);
dev.SetRenderTarget(0, rt);
if (tex != null) tex.Dispose();
if (rt != null) rt.Dispose();
if (rts != null) rts.Dispose();
this.updatesInQue = false;

#region End

dev.RenderState.Lighting = Lighting;
dev.RenderState.ZBufferEnable = ZBufferEnable;
dev.RenderState.SourceBlend = SourceBlend;
dev.RenderState.DestinationBlend = DestinationBlend;
dev.RenderState.AlphaBlendEnable = AlphaBlendEnable;
dev.RenderState.CullMode = cull;
dev.RenderState.ShadeMode = shade;




I checked the vertex and index data and its all good. I found that it draws sometimes and not others depending on the size of the back buffer. Maybe its a format issue?

Share this post

Link to post
Share on other sites
A failure that like is usually because the Z buffer isn't large enough. When your backbuffer is small, it can use your existing Z buffer. When the RT is larger, the Z buffer isn't big enough.

Enable the debug runtimes. It would have told you exactly what was wrong.

Get and store the Z buffer the device has when create (and reset).
Use CreateDepthStencilSurface to make a Z buffer that matches your render target.
Use SetDepthStencilSurface to choose a Z buffer depending on whether you're drawing to your RT texture or the back buffer.
On DeviceLost, ensure you set the old Z buffer as active, and release the new one. Reset, then grab the device Z surface again, and recreate your custom Z surface.

Share this post

Link to post
Share on other sites
Sorry, devronious, I can't help with MDX cause I have no experiance with it.

However, it seems that in your code you have dev.RenderState.ZBufferEnable = false; Could it be that this is causing the problem?

Also, check the return value of this.renderTarget = new Microsoft.DirectX.Direct3D.Texture. Perhaps you are not creating the render target at all.

Another thing to check would be to run through in debug mode and see if DrawIndexedPrimitives is actually called. You have some wierd code before that may be blocking the call.

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!