Skip to main content
gamedev.net
🔒 Locked

writing text

Started by wforl 0 replies 800+ views
Original Post
wforl
wforl
Im currently developing a profiler for my application so i can time draw calls. And all has worked out fine so far except for the drawing of the text, to display the profiled infomation on screen. Unfortunatly, the rendering of the text seems to be taking up the most frametime, usally around 50% of the actual frame time. Which kinda defeats the object if the profiler is taking more time than anythng else. Im using ID3DXFont for the rendering of the text. Does anyone have any ideas how i can speed this up? I use the following class for the text
#ifndef GFX_STATS_H
#define GFX_STATS_H

#include "Util.h"

class InfoText
{
public:
	InfoText(IDirect3DDevice9* dev, int fontsize);
	~InfoText();
	void display(int x, int y, D3DCOLOR col, const std::string& Text );

private:
	ID3DXFont* mFont;
	RECT R;
};


#endif // GFX_STATS_H


#include "InfoText.h"

InfoText::InfoText(IDirect3DDevice9* dev, int fontsize)
{
	D3DXFONT_DESC fontDesc;
	fontDesc.Height          = fontsize;
    fontDesc.Width           = 0;
    fontDesc.Weight          = 0;
    fontDesc.MipLevels       = 1;
    fontDesc.Italic          = false;
    fontDesc.CharSet         = DEFAULT_CHARSET;
    fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
    fontDesc.Quality         = DRAFT_QUALITY;
    fontDesc.PitchAndFamily  = FIXED_PITCH;
			 
	strcpy(fontDesc.FaceName, "Courier New");
	HR(D3DXCreateFontIndirect(dev, &fontDesc, &mFont));
}

InfoText::~InfoText()
{
	ReleaseCOM(mFont);
}

void InfoText::display(int x, int y, D3DCOLOR col, const std::string& Text )
{
	R.left = x;
	R.top = y;
	HR(mFont->DrawText(0, Text.c_str(), -1, &R, DT_NOCLIP, col));
}


which i use as:

static InfoText a(this->mD3dDevice, 14);
	static std::stringstream sstr;
	
		sstr.str("");
		sstr	<< "Pos : " << this->mCamera->GetPos().ToString() << std::endl
				<< "Triangles : " << Effect::GetRenderedTriangles() << std::endl
				<< "Vertices : " << Effect::GetRenderedVertices() << std::endl
				<< "DrawCalls : " << Effect::GetDrawCalls() << std::endl;
		sstr	<< m_ProfileInfo;
	
	a.display(0, 0, D3DCOLOR_RGBA(255, 255, 0, 225),mClock->getFPSandLapse() +  sstr.str());


the time seems to be all spent on the HR(mFont->DrawText(0, Text.c_str(), -1, &R, DT_NOCLIP, col)); call, which i timed on its on. any help would be appreciated
blueshogun96
blueshogun96
I'm not sure if this is the problem, but whenever I use ID3DXFont::DrawText, I always pass in a valid ID3DXSprite interface pointer as the first parameter. I've never used ID3DXFont without it. If you want, you can try adding one to your font handler. This is how I created mine:

		// Create a sprite interface	hr = D3DXCreateSprite( pD3DDevice, &lpSprite );	if( FAILED( hr ) )		return DXUtil_Error( "D3DCreateDeviceFunc(): Error creating sprite interface!", hr );	// Create a Direct3D compatible font	hr = D3DXCreateFont( pD3DDevice, 20, 0, FW_BOLD, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,						ANTIALIASED_QUALITY, DEFAULT_PITCH|FF_DONTCARE, "Arial", &lpFont );	if( FAILED( hr ) )		return DXUtil_Error( "D3DCreateDeviceFunc(): Error creating D3DX Font", hr );


And this is how I use it:

		Rect.Set( 0, 0, 800, 600 );		lpFont->DrawText( lpSprite, string1, -1, (RECT*) &Rect, DT_LEFT, D3DCOLOR_XRGB( 255, 255, 0 ) );


I hope this helps in one way or another :)

EDIT: If you need a profiler, may I suggest you use NVPerfHUD from NVIDIA? It's the greatest profiler I've ever used! Click here to download it. Just thought I'd offer it to you just in case you've never heard of it! :smile:

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.