Problem Rendering Mesh to Surface

Started by
2 comments, last by jollyjeffers 18 years, 4 months ago
Hello, I want to render a mesh to surface (for something like a Status display of the actual viewd Spaceship) What I'am doing is the following:

IDirect3DSurface9* surface_;
DXUTGetD3DDevice()->CreateOffscreenPlainSurface( 200, 150, D3DFMT_X8R8G8B8, 
		D3DPOOL_DEFAULT, &surface_, NULL );
RECT DstRect;
		
DstRect.left = 0;
DstRect.top = 0;
DstRect.right = 200;
DstRect.bottom = 150;
DXUTGetD3DDevice()->ColorFill( surface_, &DstRect, D3DCOLOR_XRGB(0, 0, 30) );
DXUTGetD3DDevice()->SetRenderTarget( 0, surface_ );

// rendering of the mesh

DstRect.left = 400;
DstRect.top = 400;
DstRect.right = 600;
DstRect.bottom = 550;				

					
IDirect3DSurface9* backBuffer = NULL;

if( !FAILED( DXUTGetD3DDevice()->GetBackBuffer( 0, 0, D3DBACKBUFFER_TYPE_MONO, &backBuffer ) ) )
{

  DXUTGetD3DDevice()->StretchRect( surface_, NULL, backBuffer, &DstRect, D3DTEXF_NONE );
}

It works aso far as I see the surface and also my mesh, but my mesh is not placed on the surface, so what do I wrong? Thanks a lot!
Advertisement
The surface you render to needs to have come from a texture you created with the D3DUSAGE_RENDERTARGET flag. Check out this article, it goes through all the stages of render to texture.

Alan
"There will come a time when you believe everything is finished. That will be the beginning." -Louis L'Amour
No, I don't want to render to a texture...
all I want is a second surface, exactly like the backbuffer, to which I can render
and then, when done copy the content of this surface to the backbuffer for displaying, just like my code shows you.

A texture seems much to complicated for this, as I than need a vertexbuffer to draw this texture...
There is a good reason for using textures - performance. Whilst it may not be a problem, and isn't always the case, rendering a texture to the screen is a lot quicker than copying a surface to the backbuffer.

Also, it's not clear from the documentation - but you might want to use IDirect3DDevice9::CreateRenderTarget() as it implicitely specifies D3DUSAGE_RENDERTARGET. Your later call to SetRenderTarget() will fail without it:
Quote:The new render-target surface must have at least D3DUSAGE_RENDERTARGET specified.


You can also eliminate the ColorFill() operation - Set the render target first, then use a regular Clear() operation.

Finally, have you run the application against the debug runtimes? it's possible you aren't getting any output due to an error...

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

This topic is closed to new replies.

Advertisement