Advertisement Jump to content
Sign in to follow this  

Render to Texture

This topic is 3836 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've been trying to create a render-to-texture effect within my game engine, but I can't seem to get it working. I've been following this tutorial from two kings: However, the whole code stops working when I chand the pyramids by a sphere object (although it is the same size and in the same position as the pyramid). The code I'm using is the following: at main.cpp:
scene->beginRenderToTexture(renderTex, EColor(0, 255, 255, 0));

scene->begin(EColor(50, 50, 200, 0));

at EScene.cpp:
bool EScene::beginRenderToTexture(ETexture* tex, EColor backgroundColor)
	IDirect3DDevice9* device = this->window->getVideoDevice()->getVideoDriver();	

	if (!tex->isRenderTarget())
		return false;

	tex->getLowLevelTexture()->GetSurfaceLevel(0, &pRenderSurface);
	device->GetRenderTarget(0, &this->pBackBuffer);
	device->SetRenderTarget(0, pRenderSurface); 

	return true;

//End render to texture using active camera
void EScene::endRenderToTexture()
IDirect3DDevice9* device = this->window->getVideoDevice()->getVideoDriver();
device->SetRenderTarget(0, this->pBackBuffer);
device->SetTransform(D3DTS_PROJECTION, &this->cameras[this->activeCamera]->getProjectionMatrix());

Texture is being created with:
if (renderTarget)

this->device->CreateTexture((UINT)width, (UINT)height, 1, Usage, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &this->texture, NULL);

The render texture is being filled with the clear color I specify, but the objects in the scene do not appear to be rendered to it. Any idea why? What am I doing wrong in here? =X Thanks...

Share this post

Link to post
Share on other sites
Things you might try:

Render the object to the back buffer instead of the render target, just to simplify the problem. I assume that the problem has nothing to do with the render target.

Use PIX to see the device state and the how the sphere is transformed.

Share this post

Link to post
Share on other sites
Thanks for your reply,

Everything in the code was correct and you were completely right! After your suggestion, I tried PIX and saw the render texture after rendering to it and before being applied and it was correct. The only thing that was missing were the texture coords of the cube mesh. For some reason the importer forgot that they existed and clamped the texture... Never thought of that...

Thanks again! :D

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!