Jump to content
  • Advertisement
Sign in to follow this  
Tispe

[DX9 ]DrawText function

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

Hi again

When I use the DrawText function where the position of the text is dynamic, it jitters around. I think it is caused by that RECT have longs and cannot be drawn "between screen pixels". Drawing sprites work becuase the D3DXVECTOR3 center is made of floats.

I hope I don't have to render text to a surface and draw it as a sprite.

How do I smoothly change the position of a text?

Share this post


Link to post
Share on other sites
Advertisement
Hidden
Ok, I found this code in another tread:


void dxText::drawText(std::string text, int x, int y, int width, int height){
RECT font_rect = {0,0,width,height}; //sets the size of our font surface rect

SetRect(&font_rect,x,y,width,height);

double rotation = 3.14159265;

D3DXVECTOR2 spriteCentre = D3DXVECTOR2(width/2,height/2);

D3DXVECTOR2 trans=D3DXVECTOR2(50,50);

D3DXMATRIX mat;
D3DXVECTOR2 scaling(1.0,1.0);
D3DXMatrixTransformation2D(&mat,&spriteCentre,0.0,&scaling,&spriteCentre,rotation,&trans);

g_font_sprite->SetTransform(&mat);

g_font_sprite-&g

Share this post


Link to post
Ok, I found this code in another tread:


void dxText::drawText(std::string text, int x, int y, int width, int height){
RECT font_rect = {0,0,width,height}; //sets the size of our font surface rect

SetRect(&font_rect,x,y,width,height);

double rotation = 3.14159265;

D3DXVECTOR2 spriteCentre = D3DXVECTOR2(width/2,height/2);

D3DXVECTOR2 trans=D3DXVECTOR2(50,50);

D3DXMATRIX mat;
D3DXVECTOR2 scaling(1.0,1.0);
D3DXMatrixTransformation2D(&mat,&spriteCentre,0.0,&scaling,&spriteCentre,rotation,&trans);

g_font_sprite->SetTransform(&mat);

g_font_sprite->Begin(D3DXSPRITE_ALPHABLEND);

g_font->DrawText(g_font_sprite, //pSprite
text.c_str(), //pString
-1, //Count
&font_rect, //pRect
DT_LEFT|DT_NOCLIP,//Format,
0xFF0000FF); //Color (white)
g_font_sprite->End();
}


It seems that passing the sprite interface to DrawText, it can take advantage of the transforms set previously.

Is this the prefered method of moving sprites and text around on the screen, instead of specifying it explicitly in the RECT? I guess g_font_sprite->SetTransform can be used when drawing the sprites also, instead of using absolute position in the Sprite->Draw function.

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!