现在的位置: 首页 > 综合 > 正文

ID3DXFont

2018年10月07日 ⁄ 综合 ⁄ 共 1113字 ⁄ 字号 评论关闭

 

//Step1 定义
#include <iostream>
ID3DXFont *pFont = NULL;
DWORD FrameCnt = 0;
float TimeElapsed = 0;
float FPS = 0;
char FPSString[9] = {0};


bool Setup()
{
	//Step3 创建字体
	D3DXFONT_DESC desc; //不能ZeroMemory 否则会出错

	desc.CharSet = DEFAULT_CHARSET;
	strcpy(desc.FaceName,"宋体");
	desc.Height = 32;
	desc.Italic = true;
	desc.MipLevels = 1;
	desc.OutputPrecision = OUT_DEFAULT_PRECIS;
	desc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
	desc.Quality = 5;
	desc.Weight = 800;
	desc.Width = 0;

	if(FAILED(D3DXCreateFontIndirect(Device,&desc,&pFont)))
	{
		::MessageBox(NULL,"D3DXCreateFontIndirect Failed",NULL,0);
		return false;
	}

	return true;
}

void Cleanup()
{
	//Step2 释放
	d3d::Release<ID3DXFont*>(pFont);
	d3d::Release<IDirect3DDevice9*>(Device);
}

bool Display(float timeDelta)
{
	if(Device)
	{
		FrameCnt++;

		TimeElapsed += timeDelta;
		if(TimeElapsed >= 1.0f)
		{
			FPS = (float)FrameCnt / TimeElapsed;

			sprintf(FPSString,"%f",FPS);
			FPSString[8] = '\0';

			TimeElapsed = 0.f;
			FrameCnt = 0;
		}

		Device->Clear(0,NULL,D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER,0xffffffff,1.0f,0);
        Device->BeginScene();

		//Step4  绘制
		RECT  rect = {0, 0, Width, Height};
		pFont->DrawText(NULL,FPSString,-1,&rect,DT_TOP|DT_LEFT,0xff000000);

		Device->EndScene();
		Device->Present(NULL,NULL,NULL,NULL);
	}

	return true;
}

抱歉!评论已关闭.