Render Text to Texture [MDX]

Started by
5 comments, last by jad_salloum 18 years ago
hi guys can anybody post the code for rendering text to texture . thanks alot
Advertisement
//sry about text formatting
//create yer texture

hr = m_pd3dDevice->CreateTexture ( (int)( m_pd3dsdBackBuffer->Width * m_fRenderTargetRatio ), // Width
(int)( m_pd3dsdBackBuffer->Height * m_fRenderTargetRatio ), // Height
1, // MipMap levels
D3DUSAGE_RENDERTARGET, // Usage
m_pd3dsdBackBuffer->Format, // Format
D3DPOOL_DEFAULT, // Pool
&m_pTextureRenderTarget, // Word to receive pointer
NULL );



// get surface

LPDIRECT3DSURFACE9 pTextureSurface;
m_pRenderTargetTexture->GetSurfaceLevel ( 0, &pTextureSurface );

//set target to texture

m_pd3dDevice->SetRenderTarget ( 0, pTextureSurface );

//draw your text.

//set target back

m_pd3dDevice->SetRenderTarget ( 0, pBackBuffer );



-programmer_tom
You might need to use the MeasureString method of Font to determine the resultant texture size...
but only if yer using the garbage font class.
thanks for ur help guys but i don't know c++ and i think that i don't need to create a texture so here is what i did and it is giving me error on device.SetRenderTarget(0,surf); help plzzz

			Surface backbuffer = device.GetBackBuffer(0, 0, BackBufferType.Mono);			Surface surf = _TArrayButtomBoard.GetSurfaceLevel(0);//	MyTexture=new Texture(device,200,200,1,Usage.RenderTarget,Format.A8B8G8R8,Pool.Default);	    	device.SetRenderTarget(0,surf);			gameFont.DrawText(null, "CameraYPoz = " + CameraYPoz.ToString(), new Rectangle(45,100,0,0), DrawTextFormat.NoClip, Color.WhiteSmoke);					device.SetRenderTarget(0,backbuffer);			    	DrawVB(device , VB , _TArrayButtomBoard , -10 , 32 , 0.0f , -10 , -30.5f ,0,0,0);
Why don't you draw text onto a bitmap and use that as a texture.

How to calculate baselines etc.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/usingGDIPlus/usingtextandfonts/obtainingfontmetrics.asp

I have also created a tokenizer and parser so I can use base HTML support.
It will calculate if the word fits on a graphics object or it needs to be drawn on the nextline.

Working tags:
Font
- Family
- Size
- Color
Paragraph
- Align
- Left
- Center
- Right
Bold
Italic
Breakline

Greetz,

Cloudius
thank God it worked , the render to texture worked finally , i didn't thought that it is that easy :)

[Edited by - jad_salloum on April 1, 2006 5:31:44 AM]

This topic is closed to new replies.

Advertisement