Jump to content
  • Advertisement
Sign in to follow this  
blackLightG

Drawing text causes incorrect geometry rendering

This topic is 2142 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

I have been trying to add text to my application using ID3DX10Font and D3DX10CreateFont but every time I say DrawText my other geometry stops rendering correctly. I have attached images of output window with text and with text disabled. I use this code to initialize:
[source lang="cpp"]g_pFont = nullptr;

HRESULT hr = D3DX10CreateFont(g_pd3dDevice,
35, // the font height
0, // the font width
FW_BOLD, // the weight of the font
1, // number of mip levels
FALSE, // this is not an italic font
DEFAULT_CHARSET, // default character set
OUT_DEFAULT_PRECIS, // default size mapping
DEFAULT_QUALITY, // default quality mapping
DEFAULT_PITCH | FF_DONTCARE, // default pitch
L"Helvetica", // use Helvetica as the basis for this font
&g_pFont); // the output

// make sure the font was created correctly
if (FAILED(hr))
{
return hr;
}
return S_OK;[/source]

and to draw:
[source lang="cpp"]HRESULT hr = g_pFont->DrawText( NULL,
TEXT("This is a test string"),
-1,
&rc,
DT_LEFT,
D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );[/source]

Any help appreciated.

Share this post


Link to post
Share on other sites
Advertisement
It looks like the DrawText method is trashing your projection matrix, and perhaps modifying your fill mode and other stuff? How are you drawing your squares?

Share this post


Link to post
Share on other sites
Actually they are cubes. I update the transform matrix, set the effect file variables and then I draw the cubes. This is done in a loop.

[source lang="cpp"]D3DXMatrixTranslation( &g_World, translate.x, translate.y, translate.z );
.
.
.
g_pWorldVariable->SetMatrix( g_World );
g_pViewVariable->SetMatrix( g_View );
g_pProjectionVariable->SetMatrix( g_Projection );
.
.
.
D3D10_TECHNIQUE_DESC techDesc;
g_pTechnique->GetDesc( &techDesc );
for( UINT p = 0; p < techDesc.Passes; ++p )
{
g_pTechnique->GetPassByIndex( p )->Apply( 0 );
g_pd3dDevice->DrawIndexed( 36, 0, 0 ); // 36 vertices needed for 12 triangles in a triangle list
}[/source]

Share this post


Link to post
Share on other sites
The actual loop:
[source lang="cpp"]renderer.beginRender();
//text.render();

for(int i = 0; i < 10; ++i)
{
cube.update(t, D3DXVECTOR3(0, i * 2, i * 3), D3DXVECTOR3(0, 1, 0), D3DXVECTOR3(1, 1, 1));
mat.setWorldViewProjection(cube.getWorld(), cam.getView(), cam.getProjection());
cube.render(renderer.g_pd3dDevice, mat.getTechnique());
}

renderer.endRender();[/source]

Share this post


Link to post
Share on other sites
Maybe you need to set textures to NULL or to the texture used by the cube before rendering the cubes?

Cheers!

Share this post


Link to post
Share on other sites
But your font engine uses textures ... does that ring a bell?

Cheers!

[edit] sorry I was in a hurry, I realized just after that of course the font engine changes other states too than the textures etc. Edited by kauna

Share this post


Link to post
Share on other sites
The text-rendering will change every render-state known to man. Move any setup you have before your render-loop or before the text-rendering and do everything just before rendering your cubes. That includes anything you do in any init() function that you expect to remain the same since you never change it. The font will change it.
That includes setting the geometry-shader to NULL if you don't use it. Edited by Erik Rufelt

Share this post


Link to post
Share on other sites
Like Erik said, the drawing function changes states, so you can use the

ID3DX10Sprite::begin(D3DX10_SPRITE_SAVE_STATE);
draw text inside here
ID3DX10Sprite::end();

This will make sure your states are changed back to what they were before the draw text call. Edited by smasherprog

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!