HLSL and render targets
Hi i'm trying to learn shaders right now and i've gotten to the point that I need to be able to render what I see on the screen to a texture and then reuse it. where can I find help regarding render targets because I don't understand them at all. I've actually got it rendering to a target but instead of the whole screen being written to it all I get is the stuff that was in my square in the center of my screen. I'm lost on how to use render targets and I probably haven't even created them right so if someone could please direct me to a tutorial or help me out here on how to correctly create and use a render target I would appreciate it.
P.S I am basically trying to create a simple visualization like you see in wmp so if you know of any tutorials on that i'd appreciate those too :).
Have a quick look at D3DXCreateRenderToSurface() - this makes rendering to a surface (or texture) childsplay. I use it to implement post-processed glow effects.
Hi, I am fairly new to this too but I have my rendertargets working for me. This stuff may or maynot be the best way to do it however! Declaring:
You set them up like:
Then for rendering:
Then you can use the texture to whatever you want to do. So if you want to render what you got to the screen just texture map something like:
and then remember to delete them before exiting your application. I'm using an array because I'm using render surfaces to render the scene onto a hemicube which has 5 sides.
Remember to setup any new projection matrices and cameras if you are rendering to somewhere other than to the screen.
LPD3DXRENDERTOSURFACE renderSurfaceHDR[5]; LPDIRECT3DTEXTURE9 dynamicTextureHDR[5]; LPDIRECT3DSURFACE9 textureSurfaceHDR[5];
You set them up like:
hr = D3DXCreateTexture( Device, Pixels, Pixels, mipmapLevels, D3DUSAGE_RENDERTARGET, D3DFMT_A16B16G16R16F, // D3DFMT_A16B16G16R16F D3DFMT_A8R8G8B8 D3DPOOL_DEFAULT, &dynamicTextureHDR); if( FAILED(hr) ) { MessageBox(NULL,"Failed to create a texture with the D3DUSAGE_RENDERTARGET usage flag set!", "ERROR",MB_OK|MB_ICONEXCLAMATION); exit(-1); } // Create an off-screen "render to" surface... dynamicTextureHDR->GetSurfaceLevel( 0, &textureSurfaceHDR); textureSurfaceHDR->GetDesc( &desc ); hr = D3DXCreateRenderToSurface( Device, desc.Width, desc.Height, desc.Format, TRUE, D3DFMT_D16, &renderSurfaceHDR); //[(5 * i) + j] ); if( FAILED(hr) ) { MessageBox(NULL,"Failed to create the off-screen render surface!", "ERROR",MB_OK|MB_ICONEXCLAMATION); exit(-1); }
Then for rendering:
renderSurfaceHDR[j]->BeginScene(textureSurfaceHDR[j], NULL); Device->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f), 1.0f, 0); // render scene renderSurfaceHDR[j]->EndScene(0);
Then you can use the texture to whatever you want to do. So if you want to render what you got to the screen just texture map something like:
Device->SetTexture(0, dynamicTextureHDR[0]);
and then remember to delete them before exiting your application. I'm using an array because I'm using render surfaces to render the scene onto a hemicube which has 5 sides.
Remember to setup any new projection matrices and cameras if you are rendering to somewhere other than to the screen.
Thanks a bunch. yeah right now all I am really trying to do is take a screenshot so the camera isn't an issue right now. well thanks a bunch i'll try that and hopefully get this working
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement