当前位置: 首页>>代码示例>>C++>>正文


C++ LPD3DXFONT::DrawText方法代码示例

本文整理汇总了C++中LPD3DXFONT::DrawText方法的典型用法代码示例。如果您正苦于以下问题:C++ LPD3DXFONT::DrawText方法的具体用法?C++ LPD3DXFONT::DrawText怎么用?C++ LPD3DXFONT::DrawText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPD3DXFONT的用法示例。


在下文中一共展示了LPD3DXFONT::DrawText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: DrawString

    void DrawString(int x, int y, DWORD color, const char *fmt, ...)
    {
		RECT FontPos = { x, y, x + 120, y + 16 };
		char buf[1024] = {'\0'};
		va_list va_alist;

		va_start(va_alist, fmt);
		vsprintf(buf, fmt, va_alist);
		va_end(va_alist);

		g_pFont->DrawText(NULL, buf, -1, &FontPos, DT_NOCLIP, color);
    }
开发者ID:emist,项目名称:D3DTextureLoggerClient,代码行数:12,代码来源:SampleLogger.cpp

示例2: Direct3DRender

void Direct3DRender(HWND hwnd)
{
	gPD3DDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
	gPD3DDevice->BeginScene();
	
	InputUpdate();
	MatrixSet();

	RECT formatRect;
	GetClientRect(hwnd, &formatRect);

	for (int i = 0; i < gDwNumMtrl; i++)
	{
		gPD3DDevice->SetMaterial(&gPMaterial[i]);
		gPD3DDevice->SetTexture(0, gPTexture[i]);
		gPCharacter->DrawSubset(i);
	}

	int strLen = swprintf_s(gStrFPS, _T("FPS: %f"), 123.45f);
	gPTextFPSFont->DrawTextW(nullptr, gStrFPS, strLen, &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_XRGB(0, 239, 136));	
	strLen = sizeof(gStrAdapterDesc);
	gPTextAdapterFont->DrawTextW(nullptr, gStrAdapterDesc, -1, &formatRect, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(23, 23, 236));

	formatRect.top = 30;
	static wchar_t strInfo[256] = { 0 };
	swprintf_s(strInfo, -1, L"模型坐标: (%.2f, %.2f, %.2f)", gMatWorld._41, gMatWorld._42, gMatWorld._43);
	gPTextHelperFont->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135, 239, 136, 255));

	formatRect.top = WINDOW_HEIGHT * 2 / 3;
	gPTextInfoFont->DrawTextW(nullptr, _T("控制说明:"), -1, &formatRect, DT_NOCLIP|DT_LEFT | DT_SINGLELINE, D3DCOLOR_XRGB(23, 25, 111));
	formatRect.top += 35;
	formatRect.left += 50;
	gPTextHelperFont->DrawText(NULL, L"按住鼠标左键并拖动:平移模型", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));
	formatRect.top += 25;
	gPTextHelperFont->DrawText(NULL, L"按住鼠标右键并拖动:旋转模型", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));
	formatRect.top += 25;
	gPTextHelperFont->DrawText(NULL, L"滑动鼠标滚轮:拉伸模型", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));
	formatRect.top += 25;
	gPTextHelperFont->DrawText(NULL, L"W、S、A、D键:平移模型 ", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));
	formatRect.top += 25;
	gPTextHelperFont->DrawText(NULL, L"上、下、左、右方向键:旋转模型 ", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));
	formatRect.top += 25;
	gPTextHelperFont->DrawText(NULL, L"ESC键 : 退出程序", -1, &formatRect,
		DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255));


	gPD3DDevice->EndScene();
	gPD3DDevice->Present(nullptr, nullptr, nullptr, nullptr);

}
开发者ID:wakqaz4,项目名称:MyGame,代码行数:55,代码来源:main.cpp

示例3: DrawTextString

void cGraphicsLayer::DrawTextString( int x, int y,
                                     DWORD color, const char * str )
{

    HRESULT r = 0;

    if( !m_pBackSurf )
        return;

    // Get a handle for the font to use
    HFONT hFont = (HFONT)GetStockObject( SYSTEM_FONT );

    LPD3DXFONT pFont = 0;
    // Create the D3DX Font
    r = D3DXCreateFont( m_pDevice, hFont, &pFont );
    if( FAILED( r ) )
        return;

    // Rectangle where the text will be located
    RECT TextRect = { x, y, 0, 0 };

    // Inform font it is about to be used
    pFont->Begin();

    // Calculate the rectangle the text will occupy
    pFont->DrawText( str, -1, &TextRect, DT_CALCRECT, 0 );

    // Output the text, left aligned
    pFont->DrawText( str, -1, &TextRect, DT_LEFT, color );

    // Finish up drawing
    pFont->End();

    // Release the font
    pFont->Release();

}
开发者ID:ehershey,项目名称:development,代码行数:37,代码来源:GraphicsLayer.cpp

示例4: render_0

//-----------------------------------------------------------------------------
// Name: render_0()
// Desc:
//-----------------------------------------------------------------------------
void render_0( void )
{
    D3DXMATRIX matView;
    D3DXMATRIX matWorld;
    D3DXMATRIX matRotation;
    D3DXMATRIX matTranslation;
    static int nFrameCount = 0;
    static double nTimeOfLastFPSUpdate = 0.0;
    static char fpsString[50] = "Frames Per Second = ";
    RECT destRect;

    // Now we can clear just view-port's portion of the buffer to red...
    g_pd3dDevice_0->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 1.0f, 0.0f, 0.0f, 1.0f ), 1.0f, 0 );

    g_pd3dDevice_0->BeginScene();

    // For the left view-port, leave the view at the origin...
    D3DXMatrixIdentity( &matView );
    g_pd3dDevice_0->SetTransform( D3DTS_VIEW, &matView );

    // ... and use the world matrix to spin and translate the teapot
    // out where we can see it...
    D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f );
    D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f );
    matWorld = matRotation * matTranslation;
    g_pd3dDevice_0->SetTransform( D3DTS_WORLD, &matWorld );

    g_pd3dDevice_0->SetMaterial( &g_teapotMtrl );
    g_pTeapotMesh_0->DrawSubset(0);

    g_pd3dDevice_0->EndScene();

    // Report frames per second and the number of objects culled...
    ++nFrameCount;

    if( g_dElpasedAppTime - nTimeOfLastFPSUpdate > 1000 ) // Update once a second
    {
        sprintf( fpsString, "Frames Per Second = %4.2f", nFrameCount*1000.0/(g_dElpasedAppTime - nTimeOfLastFPSUpdate) );

        nTimeOfLastFPSUpdate = g_dElpasedAppTime;
        nFrameCount = 0;
    }

    SetRect( &destRect, 5, 5, 0, 0 );

    g_pd3dxFont->DrawText( NULL, fpsString, -1, &destRect, DT_NOCLIP, D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) );

    g_pd3dDevice_0->Present( NULL, NULL, NULL, NULL );
}
开发者ID:djrobx,项目名称:vpinballx,代码行数:53,代码来源:multipleFullscreen.c

示例5: DrawString

	void DrawString(std::string text, int x, int y) {

		RECT FontPosition;

		FontPosition.left = x;
		FontPosition.top = y;
		FontPosition.right = x + 20 * text.length();
		FontPosition.bottom = y + 30;
		font->DrawText(NULL,
									 text.c_str(),
									 -1,
									 &FontPosition,
									 DT_LEFT,
									 0xffffffff);
	}
开发者ID:gejben,项目名称:Pathfinding,代码行数:15,代码来源:Graphics.cpp

示例6: getTextWidth

int DirectXHook::getTextWidth(const char *szText, LPD3DXFONT pFont)
{
	RECT rcRect = { 0, 0, 0, 0 };
	if (pFont)
	{
		pFont->DrawText(NULL, szText, strlen(szText), &rcRect, DT_CALCRECT, D3DCOLOR_XRGB(0, 0, 0));
	}
	int width = rcRect.right - rcRect.left;
	std::string text(szText);
	std::reverse(text.begin(), text.end());

	text = text.substr(0, text.find_first_not_of(' ') != std::string::npos ? text.find_first_not_of(' ') : 0);
	for(char c : text)
	{
		width += getSpaceCharacterWidth(pFont);
	}
	return width;
}
开发者ID:ChurroV2,项目名称:ElDorito,代码行数:18,代码来源:DirectXHook.cpp

示例7: Game_Run

void Game_Run(HWND window)
{
    //make sure the Direct3D device is valid
    if (!d3ddev) return;

    //update input devices
    DirectInput_Update();


    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,100), 1.0f, 0);

    //start rendering
    if (d3ddev->BeginScene())
    {
        spriteobj->Begin(D3DXSPRITE_ALPHABLEND);
    

        //demonstrate font output
        FontPrint(fontArial24, 60, 50, "This is the Arial 24 font printed with ID3DXFont");

        FontPrint(fontGaramond36, 60, 100, "The text can be printed in any color like this magenta!", D3DCOLOR_XRGB(255,0,255));

        FontPrint(fontTimesNewRoman40, 60, 150, "Or how about bright green instead?", D3DCOLOR_XRGB(0,255,0));


        //demonstrate text wrapping inside a rectangular region
        RECT rect = { 60, 250, 350, 700 };
        D3DCOLOR white = D3DCOLOR_XRGB(255,255,255);
        string text = "This is a long string that will be ";
        text += "wrapped inside a rectangle.";
        fontTimesNewRoman40->DrawText( spriteobj, text.c_str(), text.length(), &rect, DT_WORDBREAK, white); 


        spriteobj->End();
        d3ddev->EndScene();
        d3ddev->Present(NULL, NULL, NULL, NULL);
    }

    if (KEY_DOWN(VK_ESCAPE)) gameover = true;
    if (controllers[0].wButtons & XINPUT_GAMEPAD_BACK)
        gameover = true;

}
开发者ID:kyphelps,项目名称:spring-2013,代码行数:43,代码来源:MyGame.cpp

示例8: DrawScore

VOID Graphics::DrawScore(LPCWSTR TextString, int x, int y, int x1, int y1, D3DCOLOR MyColor)
{
	LPD3DXFONT pFont = NULL;
	RECT Rec;
	HFONT hFont;

	hFont = CreateFont(30,10,0,0,FW_NORMAL,FALSE,FALSE,0,1,0,0,0,DEFAULT_PITCH|FF_MODERN,TEXT("Arial"));

	Rec.left = x;
	Rec.top = y;
	Rec.right = x1;
	Rec.bottom = y1;

	D3DXCreateFont(this->GetDevice(),30,10,FW_NORMAL,0,FALSE,1,0,0,DEFAULT_PITCH|FF_MODERN,TEXT("Times New Roman"),&pFont);
	pFont->DrawText(NULL,TextString,-1,&Rec,DT_WORDBREAK,MyColor);

	DeleteObject(hFont);
	if (pFont != NULL)
		pFont->Release();
}
开发者ID:Atimormia,项目名称:scroller,代码行数:20,代码来源:Graphics.cpp

示例9: render

void render()
{
    static RECT rc = {0, 0, 320, 100};   // rectangular region.. used for text drawing
    static DWORD frameCount = 0;
    static DWORD startTime = clock();
    char str[16];

    doMath();   // do the math.. :-P

    frameCount++;   //  increment frame count

    // Clear the back buffer to a black... values r g b are 0-256
    lpD3DDevice9->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER ,D3DCOLOR_XRGB(256, 256, 256), 1.0f, 0);

    // render the cubes
    myRect1->render(clock());
    myRect2->render(clock());
    myRect3->render(clock());
    myRect4->render(clock());
    myRect5->render(clock());

    // this function writex a formatted string to a character string
    // in this case.. it will write "Avg fps" followed by the
    // frames per second.. with 2 decimal places
    sprintf(str, "Avg fps %.2f", (float) frameCount / ((clock() - startTime) / 1000.0f));

    // draw the text string..
    // lpD3DXFont->Begin();
    lpD3DXFont->DrawText(NULL, str, -1, &rc, DT_LEFT, 0xFFFFFFFF);
    // lpD3DXFont->End();

    // present the back buffer.. or "flip" the page
    lpD3DDevice9->Present( NULL, NULL, NULL, NULL );   // these options are for using rectangular
    // regions for rendering/drawing...
    // 3rd is which target window.. NULL makes it use the currently set one (default)
    // last one is NEVER used.. that happens with DirectX often
}
开发者ID:pnchang,项目名称:advgraphics,代码行数:37,代码来源:example04.cpp

示例10: ProcessGUI

//----------------------------------------【ProcessGUI()函数】---------------------------------------------
// Desc:进行GUI的渲染
//---------------------------------------------------------------------------------------------------------
BOOL ProcessGUI(GUIClass * GUI, BOOL LMBDown, WORD MouseX, WORD MouseY, void(CALLBACK *GUIProc)(int Id, int State))
{
	if (!GUI) return FALSE;
	LPDIRECT3DDEVICE9  pd3dDevice9 = GUI->GetDevice();
	if (!pd3dDevice9) return FALSE;

	if (!(GUI->IsBKBufferUsed() && GUI->GetBkBuffer() && GUI->GetBkTexture()))
		return FALSE;

	//渲染GUI背景
	//pd3dDevice9->SetRenderState(D3DRS_LIGHTING, false);
	pd3dDevice9->SetTexture(0, GUI->GetBkTexture());
	pd3dDevice9->SetStreamSource(0, GUI->GetBkBuffer(), 0, sizeof(GUIVERTEX));
	pd3dDevice9->SetFVF(D3DFVF_GUI);
	pd3dDevice9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);


	//用来显示文本的对象
	LPD3DXFONT pFont = NULL;
	RECT rect = { 0, 0, GUI->GetBackgroundWidth(), GUI->GetBackgroundHeight() };

	// 创建一个顶点缓存对象用于按钮的渲染
	LPDIRECT3DVERTEXBUFFER9 pVertexBuffer = NULL;
	int iState = GUI_LBUTTON_UP;

	//渲染控件
	GUICONTROL *pGUIControl = NULL;
	for (WORD i = 0; i < GUI->GetControlNums(); i++)
	{
		iState = GUI_LBUTTON_UP;
		pGUIControl = GUI->GetControl(i);
		if (!pGUIControl) continue;

		switch (pGUIControl->type)
		{
		case UGP_GUI_STATIC_TEXT:
			pFont = GUI->GetFont(pGUIControl->index);
			if (!pFont) continue;

			//设置起始位置并输出文本
			rect.left = pGUIControl->x;
			rect.top = pGUIControl->y;
			pFont->DrawText(NULL, pGUIControl->text, -1, &rect, DT_LEFT, pGUIControl->color);
			break;

		case UGP_GUI_BUTTON:
			pVertexBuffer = GUI->GetCtrlBuffer(pGUIControl->index);
			if (!pVertexBuffer) continue;

			//开启Alpha混合
			pd3dDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
			pd3dDevice9->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
			pd3dDevice9->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

			if (MouseX >= pGUIControl->x && MouseX <= (pGUIControl->x + pGUIControl->width) &&
				MouseY >= pGUIControl->y && MouseY <= (pGUIControl->y + pGUIControl->height))
			{
				if (LMBDown)
					iState = GUI_LBUTTON_DOWN;
				else
					iState = GUI_MOUSE_OVER;
			}
			//开始渲染按钮
			if (iState == GUI_LBUTTON_DOWN) pd3dDevice9->SetTexture(0, pGUIControl->textureDown);
			if (iState == GUI_LBUTTON_UP) pd3dDevice9->SetTexture(0, pGUIControl->textureUP);
			if (iState == GUI_MOUSE_OVER) pd3dDevice9->SetTexture(0, pGUIControl->textureOver);

			pd3dDevice9->SetStreamSource(0, pVertexBuffer, 0, sizeof(GUIVERTEX));
			pd3dDevice9->SetFVF(D3DFVF_GUI);
			pd3dDevice9->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);

			//关闭Alpha混合
			pd3dDevice9->SetRenderState(D3DRS_ALPHABLENDENABLE, false);
		}
		if (GUIProc) GUIProc(pGUIControl->controlID, iState);
	}

	return TRUE;
}
开发者ID:whztt07,项目名称:Ninth-World,代码行数:82,代码来源:GUIClass.cpp

示例11: WinMain


//.........这里部分代码省略.........
	char str[128];
	RECT rect;
	sound_core->Play(false);
	if(clock_manager->GetFPS() < 60)
	{
		while(msg.message != WM_QUIT)
		{
			// If there are Window messages then process them.
			if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
			{
		       TranslateMessage( &msg );
		        DispatchMessage( &msg );
			}
			// Otherwise, do animation/game stuff.
			else
	     {
				switch(gameState)
				{
				case (1)://menu state
					/*
					TO DO IN CASE 1
					setup menu with UI and Graphics
					update
					render
					loop till user input to change gamestate
					*/
					//DO SOMETHING HERE
					
					pD3DDevice->BeginScene();
					pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0) , 1.0f, 0);
				
					GetClientRect(hWnd, &rect);
					sprintf(str, "Engine Demo");
					pFont->DrawText(NULL, str, -1, &rect,
							DT_TOP | DT_CENTER | DT_NOCLIP , D3DCOLOR_ARGB(255, 
							255, 
							255, 
							255			
							));
					gText.DisplayText("Play Demo - (1)", width / 2, height * 0.25f, 50, 25, WHITE);
					gText.DisplayText("Credits - (2)", width / 2, height * 0.5f, 50, 25, WHITE);
					gText.DisplayText("Exit Demo - (3)", width / 2, height * 0.75f, 50, 25, WHITE);
					pD3DDevice->EndScene();
					pD3DDevice->Present(0, 0, 0, 0);
					main_core->Update(enemy, gameState);
					if(input_core->OnePressed())
					{
						gameState = 2;
					}

					if(input_core->TwoPressed())
					{
						gameState = 3;
					}

					if(input_core->ThreePressed())
					{
						gameState = 4;
					}

					break;
				case (2)://game logic state
					float temp[3];
					float temp2[3];
					player->agentData.getPosition(temp);
					if(temp[1] <= 101)
开发者ID:GSP420,项目名称:Engine,代码行数:67,代码来源:main.cpp

示例12: RenderFunc

void CALLBACK RenderFunc(void)
{
	/**
	*	Set camera
	*	*/
	D3DMATRIX* pMatView = nullptr;
	GD::CMatrix44<float> viewMat(gEnv.m_pCamera->GetViewMatrixDX());
	pMatView = (D3DMATRIX*)(&viewMat);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_VIEW, pMatView); //应用取景变换矩阵

	D3DMATRIX* pProjMatrix;
	pProjMatrix = (D3DMATRIX*)(&gEnv.m_pCamera->GetProjMatrix().GetFliped());
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_PROJECTION, pProjMatrix);  //设置投影变换矩阵

	D3DVIEWPORT9* pViewPort;
	pViewPort = (D3DVIEWPORT9*)(&gEnv.m_pCamera->GetViewPort());
	gEnv.m_pDXDevice->GetD3DDevice()->SetViewport(pViewPort); //视口的设置

	WCHAR TempName[60] = L"当前显卡型号:";   //定义一个临时字符串,且方便了把"当前显卡型号:"字符串引入我们的目的字符串中
	WCHAR adapterName[30]{0};
	D3DADAPTER_IDENTIFIER9 Adapter;  //定义一个D3DADAPTER_IDENTIFIER9结构体,用于存储显卡信息
	LPDIRECT3D9  pD3D = NULL; //Direct3D接口对象的创建
	if (NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))) //初始化Direct3D接口对象,并进行DirectX版本协商
	{
		return;
	}
	pD3D->GetAdapterIdentifier(0, 0, &Adapter);//调用GetAdapterIdentifier,获取显卡信息
	int len = ::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, NULL, 0);//显卡名称现在已经在Adapter.Description中了,但是其为char类型,我们要将其转为wchar_t类型
	::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, adapterName, len);//这步操作完成后,g_strAdapterName中就为当前我们的显卡类型名的wchar_t型字符串了
	wcscat_s(TempName, adapterName);//把当前我们的显卡名加到“当前显卡型号:”字符串后面,结果存在TempName中	
	pD3D->Release();

	gPFont->DrawText(nullptr, TempName, -1, nullptr, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(124, 24, 222));

	D3DXMATRIX W;
	D3DXMatrixIdentity(&W);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_WORLD, &W);
	gEnv.m_pDXDevice->GetD3DDevice()->SetFVF(Vertex::FVF);
	gEnv.m_pDXDevice->GetD3DDevice()->SetStreamSource(0, gPVertexBuffer, 0, sizeof(Vertex));

	/**
	 *	Draw floor
	 *	*/
	gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gFloorMtrl);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, gPFloorTex);
	gEnv.m_pDXDevice->GetD3DDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
	/**
	 *	Draw wall
	 *	*/
	gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gWallMtrl);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, gPWallTex);
	gEnv.m_pDXDevice->GetD3DDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 6, 4);
	/**
	 *	Draw mirror
	 *	*/
	gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gMirrorMtrl);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, gPMirrorTex);
	gEnv.m_pDXDevice->GetD3DDevice()->DrawPrimitive(D3DPT_TRIANGLELIST, 18, 2);
	
	// Set teapot position
	static D3DXMATRIX T;
	static float x = 0.0f;
	static float y = 3.0f;
	static float z = -7.5f;	

	const float delta = 0.01f;
	// increase/decrease alpha via keyboard input
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_UPARROW))
	{
		y += delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_DOWNARROW))
	{
		y -= delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_LEFTARROW))
	{
		x += delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_RIGHTARROW))
	{
		x -= delta;
	}

	//Draw teapot
	D3DXMatrixTranslation(&T,
		x,
		y,
		z);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_WORLD, &T);
	gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gTeapotMtrl);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, 0);
	gPTeapot->DrawSubset(0);

	/**
	 *	Enable stencil, disable write to z-buffer and back-buffer
	 *	*/
		//Enable stencil, so that the mirror fragment which passed z-test's stencil are set to 0x01
	gEnv.m_pDXDevice->GetD3DDevice()->SetRenderState(D3DRS_STENCILENABLE, true);
	gEnv.m_pDXDevice->GetD3DDevice()->SetRenderState(D3DRS_STENCILFUNC, D3DCMP_ALWAYS);
//.........这里部分代码省略.........
开发者ID:wakqaz4,项目名称:MyGame,代码行数:101,代码来源:StencilMirror.cpp

示例13: RenderFunc

void CALLBACK RenderFunc(void)
{
	/**
	*	Set camera
	*	*/
	D3DMATRIX* pMatView = nullptr;
	GD::CMatrix44<float> viewMat(gEnv.m_pCamera->GetViewMatrixDX());
	pMatView = (D3DMATRIX*)(&viewMat);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_VIEW, pMatView); //应用取景变换矩阵

	D3DMATRIX* pProjMatrix;
	pProjMatrix = (D3DMATRIX*)(&gEnv.m_pCamera->GetProjMatrix().GetFliped());
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_PROJECTION, pProjMatrix);  //设置投影变换矩阵

	D3DVIEWPORT9* pViewPort;
	pViewPort = (D3DVIEWPORT9*)(&gEnv.m_pCamera->GetViewPort());
	gEnv.m_pDXDevice->GetD3DDevice()->SetViewport(pViewPort); //视口的设置

	WCHAR TempName[60] = L"当前显卡型号:";   //定义一个临时字符串,且方便了把"当前显卡型号:"字符串引入我们的目的字符串中
	WCHAR adapterName[30]{0};
	D3DADAPTER_IDENTIFIER9 Adapter;  //定义一个D3DADAPTER_IDENTIFIER9结构体,用于存储显卡信息
	LPDIRECT3D9  pD3D = NULL; //Direct3D接口对象的创建
	if (NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))) //初始化Direct3D接口对象,并进行DirectX版本协商
	{
		return;
	}
	pD3D->GetAdapterIdentifier(0, 0, &Adapter);//调用GetAdapterIdentifier,获取显卡信息
	int len = ::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, NULL, 0);//显卡名称现在已经在Adapter.Description中了,但是其为char类型,我们要将其转为wchar_t类型
	::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, adapterName, len);//这步操作完成后,g_strAdapterName中就为当前我们的显卡类型名的wchar_t型字符串了
	wcscat_s(TempName, adapterName);//把当前我们的显卡名加到“当前显卡型号:”字符串后面,结果存在TempName中	
	pD3D->Release();

	gPFont->DrawText(nullptr, TempName, -1, nullptr, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(124, 24, 222));

	// Set teapot position
	static D3DXMATRIX T;
	static float x = 0.0f;
	static float y = 3.0f;
	static float z = -7.5f;

	const float delta = 0.01f;
	// increase/decrease alpha via keyboard input
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_UPARROW))
	{
		y += delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_DOWNARROW))
	{
		y -= delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_LEFTARROW))
	{
		x += delta;
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_RIGHTARROW))
	{
		x -= delta;
	}

	//Draw teapot
	D3DXMatrixTranslation(&T,
		x,
		y,
		z);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_WORLD, &T);
	gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gTeapotMtrl);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, 0);
	gPTeapot->DrawSubset(0);

	D3DXMatrixIdentity(&T);
	gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_WORLD, &T);
	for (int i = 0; i < gAirplaneMtrl.size(); i++)
	{
		gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&gAirplaneMtrl[i]);
		gEnv.m_pDXDevice->GetD3DDevice()->SetTexture(0, gPAirplaneTex[i]);
		gPAirplane->DrawSubset(i);
	}

	/**
	 *	Change numFaces by pressing key Q E;
	 *	*/
	int numFaces = gPPAirplane->GetNumFaces();
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_Q))
	{
		gPPAirplane->SetNumFaces(numFaces + 1);
		//Need to add more than one face to invert an edge collapse transformation
		if (gPPAirplane->GetNumFaces() == numFaces)
		{
			gPPAirplane->SetNumFaces(numFaces + 2);
		}
	}
	if (gEnv.m_pKeyBoard->IsKeyDown(DIK_E))
	{
		gPPAirplane->SetNumFaces(numFaces - 1);
		//Need to add more than one face to invert an edge collapse transformation
		if (gPPAirplane->GetNumFaces() == numFaces)
		{
			gPPAirplane->SetNumFaces(numFaces - 2);
		}
	}
//.........这里部分代码省略.........
开发者ID:wakqaz4,项目名称:MyGame,代码行数:101,代码来源:ProgressiveMesh.cpp

示例14: render_frame

// this is the function used to render a single frame
void render_frame(void)
{
	static const int NBUKKIT = 200;
	static ULARGE_INTEGER bukkits[NBUKKIT];
	static int bukidx = 0;	
	int nbuk = (bukidx + 1) % NBUKKIT;
	int pbuk = (bukidx + NBUKKIT - 1) % NBUKKIT;
	int ntick = 0;	
	FILETIME curFrame;	

	GetSystemTimeAsFileTime(&curFrame);
	bukkits[bukidx].HighPart = curFrame.dwHighDateTime;
	bukkits[bukidx].LowPart = curFrame.dwLowDateTime;

	if (bukkits[pbuk].QuadPart != 0) {
		ntick = bukkits[bukidx].LowPart / 10000 - bukkits[pbuk].LowPart / 10000;
	}

    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0);
	d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);

	CUSTOMVERTEX* Vertices;
	v_buffer->Lock(0, 0, (void**)&Vertices, 0);
	for (unsigned i = 0; i < g_Sim.numPoints(); i++) {
		const Cloth::Point& p = g_Sim.point(i);
		Vertices[i].X = p.x();
		Vertices[i].Y = p.y();
		Vertices[i].Z = p.z();
		Vertices[i].COLOR = D3DCOLOR_XRGB(0, 0, 0);
	}
	v_buffer->Unlock();

    d3ddev->BeginScene();

    // select which vertex format we are using
    d3ddev->SetFVF(CUSTOMFVF);

	RECT r;
	r.left = 0; 
	r.top = 0;
	r.bottom = 0;
	r.right = 0;

	
	char buff[1024];
	if (bukkits[nbuk].QuadPart != 0) {		
		double fps = (float)NBUKKIT * (10000000.0 / (double)(bukkits[bukidx].QuadPart - bukkits[nbuk].QuadPart));
		sprintf_s(buff, 1024, "FPS: %0.1f", fps);
	} else {
		strcpy_s(buff, 1024, "FPS: ??");
	}
	font->DrawText(NULL, buff, -1, &r, DT_CALCRECT, D3DCOLOR_XRGB(1, 1, 1));
	font->DrawText(NULL, buff, -1, &r, 0, D3DCOLOR_XRGB(0, 255, 0));

    // SET UP THE PIPELINE    

    D3DXMATRIX matView;    // the view transform matrix

    D3DXMatrixLookAtLH(&matView,
                       &D3DXVECTOR3 (0.0f, 0.0f, -15.0f),    // the camera position
                       &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
                       &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction

    d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView

    D3DXMATRIX matProjection;     // the projection transform matrix

    D3DXMatrixPerspectiveFovLH(&matProjection,
                               D3DXToRadian(45),    // the horizontal field of view
                               (FLOAT)SCREEN_WIDTH / (FLOAT)SCREEN_HEIGHT, // aspect ratio
                               1.0f,    // the near view-plane
                               100.0f);    // the far view-plane

    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
    
	D3DXMATRIX matIdentity;
	D3DXMatrixIdentity(&matIdentity);

	d3ddev->SetTransform(D3DTS_WORLD, &matIdentity);	

	d3ddev->SetStreamSource(0, v_bordbuffer, 0, sizeof(CUSTOMVERTEX));
	d3ddev->DrawPrimitive(D3DPT_LINESTRIP, 0, 4);

	d3ddev->SetStreamSource(0, v_buffer, 0, sizeof(CUSTOMVERTEX));
	d3ddev->SetIndices(i_buffer);

	unsigned remaining = g_Sim.numConstraints();
	unsigned off = 0;
	while (remaining) {
		unsigned toDraw = (remaining > 128) ? 128 : remaining;
		d3ddev->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, g_Sim.numPoints(), off, toDraw);
		off += toDraw * 2;
		remaining -= toDraw;
	}
	//d3ddev->DrawIndexedPrimitive(D3DPT_LINELIST, 0, 0, g_Sim.numConstraints() * 2, 0, g_Sim.numConstraints());

    d3ddev->EndScene();

    d3ddev->Present(NULL, NULL, NULL, NULL);
//.........这里部分代码省略.........
开发者ID:m3lawren,项目名称:ClothDemo,代码行数:101,代码来源:main.cpp

示例15: render

void render()
{
   static RECT rc = {0, 0, 320, 100};   // rectangular region.. used for text drawing
   static DWORD frameCount = 0;
   static DWORD startTime = clock();
   char str[16];
   DWORD val;

   doMath();   // do the math.. :-P   
   
   frameCount++;   //  increment frame count
    
   // Clear the back buffer to a black... values r g b are 0-256
   lpD3DDevice8->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(256, 256, 256), 1.0f, 0);
   
   lpD3DDevice8->GetRenderState(D3DRS_LIGHTING, &val);
   if (val)
   {
      D3DLIGHT8 light;                           // structure for light data
      ZeroMemory( &light, sizeof(D3DLIGHT8) );   // zero the mem
      light.Type = D3DLIGHT_POINT;               // set type, either SPOT, DIRECTIONAL, or POINT

      // light being put onto objects..
      light.Diffuse.r = 1.0f;
      light.Diffuse.g = 1.0f;
      light.Diffuse.b = 1.0f;
      // ambient light of the light source.. only on when light is on
      light.Ambient.r = 0.25f;
      light.Ambient.g = 0.25f;
      light.Ambient.b = 0.25f;

      // attenuation = Atten0 + Atten1 * d + Atten2 * d * d;
      // where d is distance
      // attenuation is decreasing brightness as 
      // a vertex is further away from the light source
      light.Attenuation0   = .5f;
      light.Attenuation1   = 0.10f;
      light.Attenuation2   = 0.01f;

      // spot lights and directional lights also have a direction
      // but a POINT light shines in all directions.. kinda like a light bulb
      
      light.Position = D3DXVECTOR3(0, 0, -2);

      light.Range = 15;   // after this range the light doesn't affect vertices
      lpD3DDevice8->SetLight( 0, &light );    // set the light as index 0
      lpD3DDevice8->LightEnable( 0, true );   // enable light at index 0
      
      // ambient light.. for everything.. not attached to 
      // this light, just lighting in general
      lpD3DDevice8->SetRenderState( D3DRS_AMBIENT, 0x00202020 );
   }

   // render the cubes
   myRect1->render(clock());
   myRect2->render(clock());
   myRect3->render(clock());
   myRect4->render(clock());
   myRect5->render(clock());

   // this function writes a formatted string to a character string
   // in this case.. it will write "Avg fps"  followed by the 
   // frames per second.. with 2 decimal places
   sprintf(str, "Avg fps %.2f", (float) frameCount / ((clock() - startTime) / 1000.0f));
      
   // draw the text string..
   lpD3DXFont->Begin();
   lpD3DXFont->DrawText(str, -1, &rc, DT_LEFT, 0xFFFFFFFF);
   lpD3DXFont->End();
   
   // present the back buffer.. or "flip" the page
   lpD3DDevice8->Present( NULL, NULL, NULL, NULL );   // these options are for using rectangular
      // regions for rendering/drawing...
      // 3rd is which target window.. NULL makes it use the currently set one (default)
      // last one is NEVER used.. that happens with DirectX often
}
开发者ID:pnchang,项目名称:advgraphics,代码行数:76,代码来源:example06.cpp


注:本文中的LPD3DXFONT::DrawText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。