Jump to content

  • Log In with Google      Sign In   
  • Create Account


Drawing text causes incorrect geometry rendering


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
10 replies to this topic

#1 blackLightG   Members   -  Reputation: 106

Like
0Likes
Like

Posted 02 December 2012 - 02:04 AM

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.

Attached Thumbnails

  • text.PNG
  • notext.PNG


Sponsor:

#2 Bacterius   Crossbones+   -  Reputation: 7037

Like
1Likes
Like

Posted 02 December 2012 - 04:50 AM

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?

"The best comment is a deleted comment."


#3 blackLightG   Members   -  Reputation: 106

Like
0Likes
Like

Posted 02 December 2012 - 05:37 AM

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]

#4 blackLightG   Members   -  Reputation: 106

Like
0Likes
Like

Posted 02 December 2012 - 05:39 AM

The actual loop:
[source lang="cpp"]renderer.beginRender();//text.render();for(int i = 0; i < 10; ++i){ cube[i].update(t, D3DXVECTOR3(0, i * 2, i * 3), D3DXVECTOR3(0, 1, 0), D3DXVECTOR3(1, 1, 1)); mat.setWorldViewProjection(cube[i].getWorld(), cam.getView(), cam.getProjection()); cube[i].render(renderer.g_pd3dDevice, mat.getTechnique());}renderer.endRender();[/source]

#5 kauna   Crossbones+   -  Reputation: 1899

Like
0Likes
Like

Posted 02 December 2012 - 06:59 AM

Maybe you need to set textures to NULL or to the texture used by the cube before rendering the cubes?

Cheers!

#6 blackLightG   Members   -  Reputation: 106

Like
0Likes
Like

Posted 02 December 2012 - 07:05 AM

There are no textures used here, the cubes have vertex colours which are interpolated in the shader

#7 kauna   Crossbones+   -  Reputation: 1899

Like
0Likes
Like

Posted 02 December 2012 - 09:22 AM

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, 02 December 2012 - 12:00 PM.


#8 Erik Rufelt   Crossbones+   -  Reputation: 2828

Like
2Likes
Like

Posted 02 December 2012 - 09:31 AM

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, 02 December 2012 - 09:33 AM.


#9 smasherprog   Members   -  Reputation: 420

Like
1Likes
Like

Posted 02 December 2012 - 11:10 AM

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, 02 December 2012 - 11:12 AM.

Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#10 ankhd   Members   -  Reputation: 935

Like
0Likes
Like

Posted 03 December 2012 - 06:20 AM

no the font messes with the states

#11 blackLightG   Members   -  Reputation: 106

Like
0Likes
Like

Posted 03 December 2012 - 09:44 AM

smasherprog's idea of using D3DX10_SPRITE_SAVE_STATE worked but now it appears to ignore the z-buffer test. I used
[source lang="cpp"]ID3DX10Sprite *ppSprite;D3DX10CreateSprite(g_pd3dDevice, 512, &ppSprite);ppSprite->Begin(D3DX10_SPRITE_SAVE_STATE);// text renderingppSprite->End();[/source]

I'm just going to reset the depth-buffer. I found a useful article here: http://hide1713.wordpress.com/2009/07/06/directx-10-drawtext-disable-depth-buffer-heres-how-to-fix-it/

Attached Thumbnails

  • text3.PNG





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS