Jump to content
  • Advertisement
Sign in to follow this  
mystb

slow Font:DrawText ... with sprite used

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

Hello,

I've been doing a lot of code, but any of it graphic related. So this is my first approach to doing 3D graphics. I began with a blank screen (as everyone), and I'm just drawing a triangle and rotating it over time. As you'll imagine, this gives me a very fast rotating triangle, that can almost seem like a cone.
When I try to write some text on the screen I notice a huge decrease on the speed of the rotating triangle, up to the point that with 10 lines of 80 characters on screen, one full rotation takes 4 to 5 seconds.

I've read that using a sprite in the call to drawtext will speed up things, but I really don't see any improvement.

Here is the code called each frame:


void PVideo::FRAME(){
if(!callbackset)return;

#ifdef _DEBUG
if(!globals->getValue("nooutput", false)){
#endif
device->Clear();
if( !device->BeginScene())
return;
#ifdef _DEBUG
}
#endif
updateCameraPos();
device->iface->SetFVF(tri_fvf);
device->iface->SetStreamSource(0, g_list_vb, 0, sizeof(tri_vertex));

D3DXMATRIX rot_matrix, trans_matrix, world_matrix;
static float rot_triangle=0.0f;
D3DXMatrixRotationY(&rot_matrix, rot_triangle);
D3DXMatrixTranslation(&trans_matrix, -2.0f, 0,0);
D3DXMatrixMultiply(&world_matrix, &rot_matrix, &trans_matrix);
device->iface->SetTransform(D3DTS_WORLD, &world_matrix);
device->iface->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 4);
rot_triangle+=0.007f;
if(rot_triangle>D3DX_PI*2) rot_triangle-=D3DX_PI*2;

hll->ExecFunction(update_callback);

WriteText(std::string("Drawing Triangle"), std::string("Console"),0,0xffffffff,0,0,800,100);

#ifdef _DEBUG
if(!globals->getValue("nooutput", false)){
#endif
device->EndScene();
device->Present();
#ifdef _DEBUG
}
#endif
}


update_callback calls a lua function, that now just calls back WriteText C++ function 10 times.


void Fontd3d::Write(std::string &text,DWORD format, DWORD color, RECT &rect){
if(font==NULL)
return;
sprite->Begin(D3DXSPRITE_ALPHABLEND);
if(format&DT_CENTER){
font->DrawText(sprite, text.c_str(),-1, &rect,DT_VCENTER|DT_CENTER| DT_SINGLELINE|DT_CALCRECT , color);
}
font->DrawText(sprite,text.c_str(),-1, &rect, format,color);
sprite->End();
}

void Fontd3d::GetSpaceFor(std::string& text, RECT *rect){
font->DrawText(NULL, text.c_str(),-1, rect,DT_CALCRECT , 0);

}
void Fontd3d::Create(std::string& n,int size, int weight, bool italic){

name=n;
if(FAILED( D3DXCreateFont(device, size,0,weight,1,italic,DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH | FF_DONTCARE,
name.c_str(), &font)))
throw(ERR_FILL(VIDERR_FONTERROR,"error on DX creating font"));
D3DXCreateSprite(device, &sprite);
}

Share this post


Link to post
Share on other sites
Advertisement
For testing purposes, you might try putting a simple DrawText call directly in your FRAME() function instead of using some sort of callback (in case that affects things). Then gradually increase the complexity of the DrawText calls.

E.g.,

// start with..
RECT rect;
rect.left = 100; // initialize rect
rect.top = 100;

DWORD format = DT_NOCLIP;
font->DrawText(NULL,"test text",-1,&rect,format,some_color);

// then change to..
DWORD format = DT_CENTER;
font->DrawText(NULL,"test text",-1,&rect,format | DT_CALCRECT,some_color);
font->DrawText(NULL,"test text",-1,&rect,format,some_color);

// then change to..
LPD3DXSPRITE sprite;
D3DXCreateSprite(device,&sprite);
sprite->Begin(0);
font->DrawText(sprite,"test text",-1,&rect,format | DT_CALCRECT,some_color);
font->DrawText(sprite,"test text",-1,&rect,format,some_color);
sprite->End();
sprite->Release();

// etc.

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!