Archived

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

JonW

DrawPrimitive () and SetRenderTarget ()

Recommended Posts

Hey... I''m try to draw a primitive onto a texture using SetRenderTarget (), like the follow pseudocode: ddsd.ddsCaps = VIDEOMEMORY | TEXTURE | 3DDEVICE; ddsd.dwWidth = 256; ddsd.dwHeight = 256; CreateSurface (ddsd, texture); BeginScene (); Clear (0); SetRenderTarget (texture); VERTEX vertices[4]; vertices[0].x = 0; vertices[0].y = 0; vertices[0].color = d3drgb (0, 1, 0); vertices[1].x = 256; vertices[1].y = 0; vertices[1].color = d3drgb (1, 0, 0); vertices[2].x = 0; vertices[2].y = 256; vertices[2].color = d3drgb (1, 0, 0); vertices[3].x = 256; vertices[3].y = 256; vertices[3].color = d3drgb (1, 0, 0); DrawPrimitive (vertices, 4); EndScene (); The problem with this is that the primitive renders, but there is another small primitive that is rendered in the corner of the big one and looks exactly the same (sort of like a picture-in-picture). I tried it with a diamond primitive and a triangle also and this always happens. Am I doing something wrong? Or is my hardware screwing it up? Thanks!

Share this post


Link to post
Share on other sites
Me again!

I was just looking over some websites, and it looks like they all set the viewport to the texture''s dimensions. Is this the cause of the problem?

Share this post


Link to post
Share on other sites
ZBuffer.

You should create and set a ZBuffer and associate it with SetRenderTarget. If you don''t need it then make sure you turn it off using ZWRITEENABLE and ZBUFFERENABLE render states. Also, make sure you restore the original ZBuffer pointer when going back to primary buffer using GetDepthStencilBuffer before changing anything.

You can get some more info about this in Direc3D SDK documentation, with exemples and all the stuff.

______________________________
Oooh, you found the horadric cube!

Share this post


Link to post
Share on other sites
I am not using the z buffer. I tried turning off ZWRITEENABLE, ZENABLE, and ZVISIBLE, and it didn''t make any difference. I''m assuming that I don''t have to restore the orginal ZBuffer pointer when going back to primary buffer if I''m not using it. Is there anything else I have to do to turn it off? Or maybe something else could be causing it?

If it helps, I have my viewports minZ set to 0.0 and maxZ set to 1.0, and the primitive is drawn at 0.5.

Share this post


Link to post
Share on other sites
Direct3D doesn''t care about the fact you don''t need it. It will disassociate it anyway and screw everything up. Believe me, you need to save and restore the pointer.

d3dDevice->GetRenderTarget(&oldColor);
d3dDevice->GetDepthStencil(&oldDepth);
d3dDevice->SetRenderTarget(newSurface,oldDepth);
d3dDevice->BeginScene();
...
d3dDevice->EndScene();
d3dDevice->SetRenderTarget(oldColor,oldDepth);

oldColor->Release(); // GetRenderTarget called AddRef
oldDepth->Release(); // GetDepthStencil called AddRef



______________________________
Oooh, you found the horadric cube!

Share this post


Link to post
Share on other sites