Render an Mesh into an Texture

Started by
4 comments, last by arbell 17 years, 4 months ago
I have some complex objects in my Environment(say complex tree)......when the user moves far away fom the object.....i doesnt want to render that object,instead i am planning to Render that complex object into an Texture and render the texture and display it.........i have no idea how to proceed....so can anyone suggest me how to proceed.....
Advertisement
the keywords your looking for is "Imposter"

An imposter is when you render a mesh to a texture to save bandwidth.
the keywords your looking for is "Imposter"

An imposter is when you render a mesh to a texture to save bandwidth.
Well things you need to do is :
- Create texture
- Fetch the textures surface
- Set this surface as rendering target when you need to render your things to texture, remember to take a copy of the old renderer target.
- Then set the old renderer target back.
- Render a fullscreen quad with this texture in to the right place (at background).
- Render the rest of your scene as it is.
Sincerely,Arto RuotsalainenDawn Bringer 3D - Tips & Tricks
To render to a texture you'd want to do something like the following:

LPDIRECT3DSURFACE9 lpD3DsOrig;
m_lpD3DDevice->GetRenderTarget(0, &lpD3DsOrig); // Save the original render target
m_lpD3DDevice->SetRenderTarget(0, lpD3DsRenderTarget); // Set renderer to our surface
// Render your mesh
m_lpD3DDevice->SetRenderTarget(0, lpD3DsOrig); // Restore the original render target

Decide what texture you wish to use (one way is to run your program, take a screenshot of your mesh, and use that). Once you've got your image, remember to specify the transparent part of the image for loading purposes, either by specifying alpha within the image, or using one colour and then specifying that colour as the colour key when loading.

Then create a quad, set the texture/image to it, and use the billbaord technique so the quad is always facing the camera. With the transparent parts of the texture specified, it looks pretty good. Create a quad for every mesh that gets to far away from the camera, and you should have a result.

You can then use some kind of alpha blending to fade the texture in/out for an extra effect as it gets even further away from the camera.

If you want the texture to animate, then you should be able to use the same method, but with extra textures obviously.

This topic is closed to new replies.

Advertisement