void Text::init(wstring fontName, int size) { D3DX10_FONT_DESC fontDesc; fontDesc.Height = size; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy(fontDesc.FaceName, fontName.c_str());// toWString(fontName).c_str()); D3DX10CreateFontIndirect(device, &fontDesc, &font); }
void D3DApp::initApp(){ initMainWindow(); initDirect3D(); D3DX10_FONT_DESC fontDesc; fontDesc.Height = 12; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy(fontDesc.FaceName, L"Times New Roman"); D3DX10CreateFontIndirect(md3dDevice, &fontDesc, &mFont); }
void SimpleFontManager::Init(Graphics * graphics) { // DEBUG font { D3DX10_FONT_DESC fd; fd.Height = 16; fd.Width = 0; fd.Weight = 0; fd.MipLevels = 1; fd.Italic = false; fd.CharSet = OUT_DEFAULT_PRECIS; fd.Quality = DEFAULT_QUALITY; fd.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy(fd.FaceName, L"Arial"); D3DX10CreateFontIndirect(graphics->Device(), &fd, &mDebugFont); mDebugFontColor = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f); } }
void CDX10Core::InitFont() { // Create font if( m_pFont ) SAFE_DX_RELEASE( m_pFont ); D3DX10_FONT_DESC fontDesc; fontDesc.Height = 25; fontDesc.Width = 12; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; _tcscpy_s( fontDesc.FaceName, 32, _T( "Calibri" ) ); HR( D3DX10CreateFontIndirect( m_pDevice, &fontDesc, &m_pFont ) ); }
void CreateDrawingFont(void) { D3DX10_FONT_DESC fontDesc; fontDesc.Height = 24; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy(fontDesc.FaceName, L"Times New Roman"); if(pDevice == NULL) { printf("Device to create font on is NULL.\n"); return; } D3DX10CreateFontIndirect(pDevice, &fontDesc, &pFont); }
void TextObject::Initialise() { DrawableObject::Initialise(); mLocalisedString = StringManager::GetInstance()->GetLocalisedString(mStringId.c_str()); mCachedWideString = Utilities::ConvertCharStringToWcharString(mLocalisedString.c_str()); // font setup { D3DX10_FONT_DESC fd; fd.Height = mFontSize; fd.Width = 0; fd.Weight = 0; fd.MipLevels = 1; fd.Italic = false; fd.CharSet = OUT_DEFAULT_PRECIS; fd.Quality = DEFAULT_QUALITY; fd.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy(fd.FaceName, Utilities::ConvertCharStringToWcharString(mFontName.c_str())); D3DX10CreateFontIndirect(Graphics::GetInstance()->Device(), &fd, &mFont); } }
bool CDX10Renderer::Initialise(HINSTANCE _hInstance, HWND _hwnd, int _iClientWidth, int _iClientHeight) { m_hAppInst = _hInstance; m_hMainWnd = _hwnd; m_iTargetWidth = _iClientWidth; m_iTargetHeight = _iClientHeight; m_iClientWidth = _iClientWidth; m_iClientHeight = _iClientHeight; // Set up DX swap chain DXGI_SWAP_CHAIN_DESC sd; sd.BufferDesc.Width = m_iTargetWidth; sd.BufferDesc.Height = m_iTargetHeight; sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = m_hMainWnd; sd.Windowed = true; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; // Create DX10 device UINT createDeviceFlags = 0; #if defined(DEBUG) || defined(_DEBUG) createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; #endif // Create the ID3D10Device and IDXGISwapChain which interfaces // with the D3D10CreateDeviceAndSwapChain function if(FAILED(D3D10CreateDeviceAndSwapChain(0, //default adapter D3D10_DRIVER_TYPE_HARDWARE, 0, // no software device createDeviceFlags, D3D10_SDK_VERSION, &sd, &m_pSwapChain, &m_pDevice))) { MessageBoxA(0, "Failed to create DX10 device.", "ERROR", MB_OK); return (false); } // Create raster states. And set an initial state D3D10_RASTERIZER_DESC rsDesc; ZeroMemory(&rsDesc, sizeof(D3D10_RASTERIZER_DESC)); // Make backface cull solid and set this as initial state rsDesc.FillMode = D3D10_FILL_SOLID; rsDesc.CullMode = D3D10_CULL_BACK; m_pDevice->CreateRasterizerState(&rsDesc, &m_pDefaultRasterState); m_pDevice->RSSetState(m_pDefaultRasterState); Resize(m_iClientWidth, m_iClientHeight); // Load the effect if (FAILED(D3DX10CreateEffectFromFile(L"default.fx", 0, 0, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, m_pDevice, 0, 0, &m_pDefaultEffect, 0, 0))) { MessageBoxA(0, "Failed to create DX10 device.", "ERROR", MB_OK); return (false); } m_pDefaultTech = m_pDefaultEffect->GetTechniqueByName("DefaultTech"); // Create matrix effect pointers m_pWorldMatrixEffectVariable = m_pDefaultEffect->GetVariableByName( "gWorld" )->AsMatrix(); m_pViewMatrixEffectVariable = m_pDefaultEffect->GetVariableByName( "gView" )->AsMatrix(); m_pProjectionMatrixEffectVariable = m_pDefaultEffect->GetVariableByName( "gProjection" )->AsMatrix(); // Vert layout D3D10_INPUT_ELEMENT_DESC layout[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0 }, { "COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0 } }; UINT numElements = 2; D3D10_PASS_DESC passDesc; m_pDefaultTech->GetPassByIndex(0)->GetDesc(&passDesc); if (FAILED(m_pDevice->CreateInputLayout(layout, numElements, passDesc.pIAInputSignature, passDesc.IAInputSignatureSize, &m_pDefaultVertexInputLayout ) ) ) { MessageBoxA(0, "Failed to create DX10 device.", "ERROR", MB_OK); return (false); }; // Set the input layout m_pDevice->IASetInputLayout(m_pDefaultVertexInputLayout); m_pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP); // Set effect values now because they will not change D3DXMATRIX world; D3DXMatrixIdentity(&world); D3DXMatrixTranslation(&world, m_iClientWidth * -0.5f, m_iClientHeight * -0.5f, 0.0f); D3DXMATRIX rot; D3DXMatrixRotationX(&rot, static_cast<float>(D3DX_PI)); world = world * rot; // Set up the view matrix //-------------------------------------------------------------- D3DXVECTOR3 eye(0.0f, 0.0f, -1.0f); D3DXVECTOR3 view(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMATRIX viewMatrix; D3DXMatrixLookAtLH( &viewMatrix, &eye, &view, &up); //Set up projection matrix //-------------------------------------------------------------- D3DXMATRIX projectionMatrix; D3DXMatrixOrthoLH(&projectionMatrix, static_cast<float>(m_iClientWidth), static_cast<float>(m_iClientHeight), 0.0f, 1.0f); //D3DXMatrixPerspectiveFovLH(&projectionMatrix, (float)D3DX_PI * 0.5f, (float)m_iClientWidth/m_iClientHeight, 0.1f, 100.0f); m_pWorldMatrixEffectVariable->SetMatrix(world); m_pViewMatrixEffectVariable->SetMatrix(viewMatrix); m_pProjectionMatrixEffectVariable->SetMatrix(projectionMatrix); D3D10_TECHNIQUE_DESC techDesc; m_pDefaultTech->GetDesc(&techDesc); for(unsigned int p = 0; p < techDesc.Passes; ++p ) { m_pDefaultTech->GetPassByIndex(p)->Apply(0); } //create vertex buffer (space for 100 vertices) //--------------------------------------------- UINT numVertices = 100; D3D10_BUFFER_DESC bd; bd.Usage = D3D10_USAGE_DYNAMIC; bd.ByteWidth = sizeof( TVertex ) * numVertices; //total size of buffer in bytes bd.BindFlags = D3D10_BIND_VERTEX_BUFFER; bd.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; bd.MiscFlags = 0; if ( FAILED( m_pDevice->CreateBuffer( &bd, 0, &m_pVertexBuffer ) ) ) { MessageBoxA(0, "Failed to create DX10 device.", "ERROR", MB_OK); return (false); } PushPenColour(TColour(0, 0, 0, 255).Value()); PushBrushColour(TColour(0, 0, 0, 255).Value()); // Init font D3DX10_FONT_DESC fontDesc; fontDesc.Height = 16; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy_s(fontDesc.FaceName, L"Times New Roman"); D3DX10CreateFontIndirect(m_pDevice, &fontDesc, &m_pFont); D3DX10CreateSprite(m_pDevice, 512, &m_pSprite); return(true); }
bool C_Graphics::initDirect3D(const C_Window& window) { // Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain. DXGI_SWAP_CHAIN_DESC sd; ZeroMemory( &sd, sizeof( sd ) ); sd.BufferDesc.Width = window.getWidth(); sd.BufferDesc.Height = window.getHeight(); sd.BufferDesc.RefreshRate.Numerator = 60; sd.BufferDesc.RefreshRate.Denominator = 1; sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // No multisampling sd.SampleDesc.Count = 1; sd.SampleDesc.Quality = 0; sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; sd.BufferCount = 1; sd.OutputWindow = window.getWindowHandle(); sd.Windowed = true; sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; sd.Flags = 0; // Create the device UINT createDeviceFlags = 0; //#if defined(DEBUG) || defined(_DEBUG) // createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG; //#endif HRESULT hr = D3D10CreateDeviceAndSwapChain( 0, //default adapter d_D3DDriverType, 0, // no software device createDeviceFlags, D3D10_SDK_VERSION, &sd, &d_SwapChain, &d_D3DDevice); if(FAILED(hr)) { DEBUGLOG(L"D3DDevice INIT FAILED"); DXTrace(__FILE__, (DWORD)__LINE__, hr, 0, true); return false; } DEBUGLOG(L"D3DDevice INIT SUCCESSFUL"); // The remaining steps that need to be carried out for D3D creation // also need to be executed every time the window is resized. So // just call the OnResize method here to avoid code duplication. onResize(window); D3DX10_FONT_DESC fontDesc; fontDesc.Height = 14; fontDesc.Width = 0; fontDesc.Weight = 0; fontDesc.MipLevels = 1; fontDesc.Italic = false; fontDesc.CharSet = DEFAULT_CHARSET; fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS; fontDesc.Quality = DEFAULT_QUALITY; fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE; wcscpy_s(fontDesc.FaceName, L"Times New Roman"); hr = D3DX10CreateFontIndirect(d_D3DDevice, &fontDesc, &d_Font); if(FAILED(hr)) { DEBUGLOG(L"Font INIT FAILED"); return false; } DEBUGLOG(L"Font INIT SUCCESSFUL"); // Init the defualt shader //d_pDefaultShader = new C_DefaultShader(d_D3DDevice); return true; }