int cText::Draw(std::string* pText, DWORD* pColor) { Util::TempRenderState Color(D3DRS_AMBIENT, *pColor); Util::TempRenderState OnLight(D3DRS_LIGHTING, TRUE); // 빛켬 SAFE_RELEASE(m_pMesh); // 기존 메쉬 삭제 HDC hdc = CreateCompatibleDC( NULL ); HFONT hFontOld = (HFONT)SelectObject(hdc, m_hFont); // 유니코드 변환 //wchar_t형 변수 선언 wchar_t* pStr; //멀티 바이트 크기 계산 길이 반환 int strSize = MultiByteToWideChar(CP_ACP, 0, pText->c_str(), -1, NULL, NULL); //wchar_t 메모리 할당 pStr = new WCHAR[strSize]; //형 변환 MultiByteToWideChar(CP_ACP, 0,pText->c_str(), strlen(pText->c_str())+1, pStr, strSize); // 3D 문자열을 생성 D3DXCreateTextW(cCore::pd3dDevice, hdc, pStr, 200.f, 0.01f, &m_pMesh, 0, 0); m_pMesh->DrawSubset(0); // 그리기 SelectObject(hdc, hFontOld); // DC 해제 DeleteDC( hdc ); // 단위행렬 적용 Util::SetIdentityMatrix(); delete[] pStr; // 메모리 반환 return 0; }
void cMainGame::Setup() { m_pGrid = new cGrid; m_pGrid->Setup(); m_pCamera = new cCamera; m_pCamera->Setup(); m_pCube = new cCube; m_pCube->Setup(); m_pSkinnedMesh = new cSkinnedMesh("Zealot/", "zealot.X"); // Get a handle to a device context HDC hdc = CreateCompatibleDC(NULL); // Describe the font we want. LOGFONT lf; ZeroMemory(&lf, sizeof(LOGFONT)); lf.lfHeight = 6; // in logical units lf.lfWidth = 3; // in logical units lf.lfEscapement = 0; lf.lfOrientation = 0; lf.lfWeight = 500; // boldness, range 0(light) - 1000(bold) lf.lfItalic = FALSE; lf.lfUnderline = FALSE; lf.lfStrikeOut = FALSE; lf.lfCharSet = DEFAULT_CHARSET; lf.lfOutPrecision = 0; lf.lfClipPrecision = 0; lf.lfQuality = 0; lf.lfPitchAndFamily = 0; strcpy(lf.lfFaceName, "굴림체"); // font style // Create the font and select it with the device context. HFONT hFont = CreateFontIndirect(&lf); HFONT hFontOld = (HFONT)SelectObject(hdc, hFont); // Create the text mesh based on the selected font in the HDC. D3DXCreateTextW(g_pD3DDevice, hdc, L"조원석", 0.001f, 0.001f, &m_pStringMesh, NULL, NULL); // Restore the old font and free the acquired HDC. SelectObject(hdc, hFontOld); DeleteObject(hFont); DeleteDC(hdc); if(ST_PN_VERTEX::FVF == m_pStringMesh->GetFVF()) { LPDIRECT3DVERTEXBUFFER9 pVB; m_pStringMesh->GetVertexBuffer(&pVB); DWORD dwNumVertices = m_pStringMesh->GetNumVertices(); VOID* pVertices; pVB->Lock(0, sizeof(ST_PN_VERTEX) * dwNumVertices, (void**)&pVertices, 0); D3DXVECTOR3 vMin, vMax; D3DXComputeBoundingBox((D3DXVECTOR3*)pVertices, dwNumVertices, D3DXGetFVFVertexSize(ST_PN_VERTEX::FVF), &vMin, &vMax); float fCenterX = (vMin.x + vMax.x) / 2.0f; ST_PN_VERTEX* pVertex = (ST_PN_VERTEX*)pVertices; for(DWORD i = 0; i < dwNumVertices; ++i) { pVertex[i].p.x -= fCenterX; } pVB->Unlock(); SAFE_RELEASE(pVB); } SetLight(); }