Jump to content

View more

Image of the Day

The night is still, but the invasion brings chaos. #screenshotsaturday #hanako #indiegame #gameart #ue4 #samurai https://t.co/cgILXuokoS
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

[DX9 ]DrawText function

4: Adsense

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
1 reply to this topic

#1 Tispe   Members   

1468
Like
0Likes
Like

Posted 09 December 2011 - 05:38 AM

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?

#2 Tispe   Members   

1468
Like
1Likes
Like

Posted 10 December 2011 - 05:37 AM

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.




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.