Original Post
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: http://www.two-kings.de/tutorials/dxgraphics/dxgraphics16.html 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: at EScene.cpp: Texture is being created with: 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...
scene->beginRenderToTexture(renderTex, EColor(0, 255, 255, 0));
skull->draw();
scene->endRenderToTexture();
scene->begin(EColor(50, 50, 200, 0));
renderTex->applyTexture();
cube->draw();
skull->draw();
scene->end();
bool EScene::beginRenderToTexture(ETexture* tex, EColor backgroundColor)
{
IDirect3DDevice9* device = this->window->getVideoDevice()->getVideoDriver();
if (!tex->isRenderTarget())
return false;
LPDIRECT3DSURFACE9 pRenderSurface = NULL;
tex->getLowLevelTexture()->GetSurfaceLevel(0, &pRenderSurface);
device->GetRenderTarget(0, &this->pBackBuffer);
device->SetRenderTarget(0, pRenderSurface);
this->begin(backgroundColor);
return true;
}
//End render to texture using active camera
void EScene::endRenderToTexture()
{
IDirect3DDevice9* device = this->window->getVideoDevice()->getVideoDriver();
device->EndScene();
device->SetRenderTarget(0, this->pBackBuffer);
device->SetTransform(D3DTS_PROJECTION, &this->cameras[this->activeCamera]->getProjectionMatrix());
}
if (renderTarget)
Usage |= D3DUSAGE_RENDERTARGET;
this->device->CreateTexture((UINT)width, (UINT)height, 1, Usage, D3DFMT_R5G6B5, D3DPOOL_DEFAULT, &this->texture, NULL);