Skip to main content
gamedev.net
🔒 Locked

RenderTarget

Started by Guimo 1 reply 1.4k views
Original Post
Guimo
Guimo
I'm using D3DXRenderToSurface functions and would like to do it but whithout using D3DX. I'm creating a Texture with RENDERTARGET usage. Now, how do I tell the device that I want to use that texture? And how do I go back to screen rendering? Luck! Guimo
circlesoft
circlesoft
You can easily do this with IDirect3DDevice::GetRenderTarget() and IDirect3DDevice::SetRenderTarget(). Actually, the D3DX interface is just a wrapper around these calls.

The following sample code renders the scene to a cubemap:
    // Get the current rendertarget, keep it for later    LPDIRECT3DSURFACE9 RTOld = NULL;    VERIFY( d3dDevice->GetRenderTarget( 0, &RTOld ) );    // Iterate through each cube face    for( int nFace = 0; nFace < 6; ++nFace )    {        LPDIRECT3DSURFACE9 pSurf;	// Obtain the surface of the cubemap        VERIFY( d3dCubeMap->GetCubeMapSurface( (D3DCUBEMAP_FACES)nFace, 0, &pSurf ) );	// Set the rendertarget to the cubemap's surface        VERIFY( d3dDevice->SetRenderTarget( 0, pSurf ) );        SafeRelease( pSurf );	// Build the viewing matrix for this particular face        D3DXMATRIXA16 mView = GetCubeMapViewMatrix( nFace );        D3DXMatrixMultiply( &mView, &mViewDir, &mView );	// Clear the device        VERIFY( d3dDevice->Clear( 0L, NULL, D3DCLEAR_ZBUFFER, 0x000000ff, 1.0f, 0L ) );        // Begin the scene        if( SUCCEEDED( d3dDevice->BeginScene() ) )        {	    // Re-render the world again	    RenderWorld();            // End the scene.            d3dDevice->EndScene();        }   }        // Restore the old render target   VERIFY( d3dDevice->SetRenderTarget( 0, RTOld ) );
Guimo
Guimo
Thanks! I'll try this code.
Luck!
Guimo

Topic Locked

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

Sign in to reply to this topic.