Skip to main content
GameDev.net gamedev.net
🔒 Locked

Problems rendering text to textures

Started by GambitSnax May 4, 2006 at 1:42 AM 6 replies 600+ views
Original Post
GambitSnax
GambitSnax
I was previously using the directx 8 function calls regarding text display (no sprite objects) to render some text to a texture and then apply that texture to an object. It was working fine. I recently updated it to use the directx 9 text rendering function which incorporates sprites when rendering text, and text generation on my textures stopped working. I can get text to display fine straight to the frame buffer (using the new directx 9 calls), but when I try to render to a texture, no text seems to be displayed. My general process for rendering text to textures is as follows -

// set the render target
g_pD3DDevice->SetRenderTarget(0, g_pTextureSurface);

// clear the target to a particular colour
g_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, STARTNODECOLOUR, 1.0f, 0 );

// render the text out to the object
g_pD3DDevice->BeginScene();
renderTextureText(nodeToUpdate);
g_pD3DDevice->EndScene();

// renderTextureText section --
g_pD3DXTextureSprite->Begin(D3DXSPRITE_ALPHABLEND);
// render my text using a few of these calls
g_pD3DXTextureFont->DrawTextA(g_pD3DXTextureSprite, pTextTotal, -1, ▭, DT_LEFT, D3DCOLOR_XRGB(200, 200, 200));

g_pD3DXTextureSprite->End();

Any ideas? Any help would be appreciated. Cheers.
MTclip
MTclip
LPD3DXSPRITE::Begin() & ::End() must be in between IDirect3DDevice9::BecginScene() & EndScene()...

// set the render targetg_pD3DDevice->SetRenderTarget(0, g_pTextureSurface);// clear the target to a particular colourg_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET, STARTNODECOLOUR, 1.0f, 0 );// render the text out to the objectg_pD3DDevice->BeginScene();renderTextureText(nodeToUpdate);// renderTextureText section --g_pD3DXTextureSprite->Begin(D3DXSPRITE_ALPHABLEND);// render my text using a few of these callsg_pD3DXTextureFont->DrawTextA(g_pD3DXTextureSprite, pTextTotal, -1, ▭, DT_LEFT, D3DCOLOR_XRGB(200, 200, 200));g_pD3DXTextureSprite->End();// move this down hereg_pD3DDevice->EndScene();



GambitSnax
GambitSnax
Ahhh yes, sorry I mustn't of posted my code in an easy to read manner.
The renderTextureText call is a method which is detailed below it
(under the // renderTextureText section).

So it calls g_pD3DDevice->BeginScene then calls renderTextureText (where all the text rendering is done) and then calls g_pD3DDevice->EndScene. If you know what I mean...
DXnut
DXnut
All of the SDK sample programs use sprites to draw the text on the screen (like the yellow text you see for FPS and such). That would be a good place to start.
--------------------------Most of what I know came from Frank D. Luna's DirectX books
GambitSnax
GambitSnax
I'm not having trouble rendering text using sprites in general, I can get text to display to the screen, the problem occurs when I'm trying to render text using sprites to a texture, and then apply that texture to an object. I would think it works the same way, but for some reason the text on my generated texture does not appear.

My question is then, is there something special I have to do when rendering text to a texture?
GambitSnax
GambitSnax
Anyone had any thoughts on this question?
Aiursrage2k
Aiursrage2k
I wrote a marquee class doing something very similar. Your code looks okay, the only thing I can think of is that you are not clearing the zbuffer.

	IDirect3DSurface9 *backUpSurface;	D3DVIEWPORT9 backUpViewPort;	IDirect3DSurface9 *surface;	devicePtr->GetRenderTarget(0,&backUpSurface);	devicePtr->GetViewport(&backUpViewPort);	m_renderTarget->GetSurfaceLevel(0,&surface);	//set the renderTarget to the renderTexture	devicePtr->SetRenderTarget(0,surface);	//change the viewport	devicePtr->SetViewport(&m_viewport);			//clear the rendertarget to black	devicePtr->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 			D3DCOLOR_XRGB(0,0,0), 1.0, 0);		devicePtr->BeginScene();m_fontPtr->DrawText(NULL,(LPCSTR)text, -1, &rct, DT_LEFT|DT_CALCRECT|DT_NOCLIP,     0xffffff);	devicePtr->EndScene();		devicePtr->SetRenderTarget(0,backUpSurface);	devicePtr->SetViewport(&backUpViewPort);	//release the surfaces	backUpSurface->Release();	surface->Release();
Insufficent Information: we need more infromationhttp://staff.samods.org/aiursrage2k/
GambitSnax
GambitSnax
I tried adding the D3DCLEAR_ZBUFFER options as well but still no success.

Seeing that the text render to texture was working fine before i switched to the directx9 calls text calls(using sprites etc.), it makes me think that the problem is isolated to these new calls. I'm just confused however that I can use there new calls and render straight to the screen fine. But when I use these new calls with my old code (which worked perfectly with the old calls) no text gets displayed in the texture. This is really starting to drive me insane. Is there something special I should know about rendering with sprities? I tried turning them off completely but even my text that was rendering to the screen didn't show up then.

Any help would be greatly appreciated. Cheers.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.