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?
[DX9 ]DrawText function
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
Ok, I found this code in another tread:
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement