Jump to content
  • Advertisement
Sign in to follow this  

Rendering to a texture HELP!

This topic is 5194 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, I am having major problems with finding examples or tutorials on how to render to a texture. I want to render a basic quad (which has its own texture) onto a larger quad (which has its own texure aswell). I have the basic idea of using createTexture and setRenderTarget but have no idea how to use them. Can anyone please help? Thanks

Share this post

Link to post
Share on other sites
First off, why do you want to render one quad onto another? I don't quite see the point? Are you just trying to increase the size of the texture by rendering to a larger quad? Nonetheless, I'll place a quick sample of what you need to do to make the textures.

// directx texture and surface (both required since we write to the surface not the texture)

// create texture
if( FAILED( g_pD3DDevice->CreateTexture( WIDTH, HEIGHT, 1,
D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, // D3DFMT_ is the format, we are just using regular 8-bit RGBA
D3DPOOL_DEFAULT, &m_pTexture, NULL)))
return FALSE;

// grab the surface -- we dont write directly to the texture
if(FAILED(m_pTexture->GetSurfaceLevel(0, &m_pSurface)))
return FALSE;

okay, so this is the initialization. We create both a texture and surface. They both return HRESULTs and it's usually best to error check here, which is why I have the FAILED bits, but it's not absolutely necessary.
Then to write to the texture you just need to use

D3DDevice->setRenderTarget( m_pSurface )

(or it might ask for &m_pSurface -- I can't be bothered to check about that at the moment).

Finally, and this is very important, make SURE you save the address of the screen backbuffer BEFORE you set it to anything else since otherwise you will LOSE it and you wont be able to render to the screen. Do this with

g_pD3DDevice->GetRenderTarget(0, &g_pBackBuffer);

now you must setRenderTarget( &g_pBackBuffer ) whenever you want to render to the screen again.
I hope this is a concise crash-course. Read the tutorial above for more detail, since this really is barebones, but it gives you what you need.

Share this post

Link to post
Share on other sites
Thanks FancyZero and rjackets. That's helped alot.

The reason for me texturing a smaller quad to a larger quad is because I am trying to perform effects on the smaller quad using shaders and I needed the smaller qaud rendered ON the larger one.

Also, there is another tutorial I found that does not use "off-screen rendering" like the one above.



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!