HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); m_terrain.Render(); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}, {400, 10, 0, 0}, {600, 10, 0, 0}}; m_pFont->DrawText(NULL, "W: Toggle Wireframe", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "+/-: Zoom In/Out", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "SPACE: Randomize Map", -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "F5: Save Terrain", -1, &r[3], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "F6: Load Terrain", -1, &r[4], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); //Render either of the meshes if(m_activeMesh == 0) m_mesh1.Render(); else m_mesh2.Render(); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}}; m_pFont->DrawText(NULL, "Space: Next Object", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "W: Toggle Wireframe", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
void RCDrawText::execute( Renderer& renderer ) { DX9Renderer& dxRenderer = static_cast< DX9Renderer& >( renderer ); ID3DXFont* dxFont = dxRenderer.getFont( m_font ); if ( !dxFont ) { return; } // draw text static int textLen = -1; DWORD format = DT_WORDBREAK; switch( m_justification ) { case TJ_LEFT: format |= DT_LEFT; break; case TJ_CENTERED: format |= DT_CENTER; break; case TJ_RIGHT: format |= DT_RIGHT; break; default: break; } dxFont->DrawText( NULL, m_text.c_str(), textLen, &m_overlaySize, format, D3DCOLOR_RGBA( ( ( int )( m_color.r * 255 ) ), ( ( int )( m_color.g * 255 ) ), ( ( int )( m_color.b * 255 ) ), ( ( int )( m_color.a * 255 ) ) ) ); }
void CGraphics::DrawText(unsigned int uiLeft, unsigned int uiTop, unsigned int uiRight, unsigned int uiBottom, unsigned long ulColor, float fScaleX, float fScaleY, unsigned long ulFormat, unsigned int fontIndex, bool bShadow, const char * szText) { // Is the sprite invalid? if(!m_pSprite) return; // Get the font ID3DXFont * pFont = GetFont(fontIndex); // Is the font invalid? if(!pFont) return; // Prevent the rect from getting scaled along with the size uiLeft = unsigned int ((float) uiLeft * (1.0f / fScaleX)); uiTop = unsigned int ((float) uiTop * (1.0f / fScaleY)); uiRight = unsigned int ((float) uiRight * (1.0f / fScaleX)); uiBottom = unsigned int ((float) uiBottom * (1.0f / fScaleY)); // Create the rect RECT rect; SetRect(&rect, uiLeft, uiTop, uiRight, uiBottom); D3DXMATRIX matrix; D3DXVECTOR2 scalingCentre(0.5f, 0.5f); D3DXVECTOR2 scaling(fScaleX, fScaleY); m_pSprite->Begin(D3DXSPRITE_ALPHABLEND | D3DXSPRITE_SORT_TEXTURE); D3DXMatrixTransformation2D(&matrix, NULL, 0.0f, &scaling, NULL, 0.0f, NULL); m_pSprite->SetTransform(&matrix); // If we need to draw shadow do it now if (bShadow) { RECT shadow_rect; SetRect(&shadow_rect, uiLeft + 1, uiTop + 1, uiRight + 1, uiBottom + 1); pFont->DrawText(m_pSprite, szText, -1, &shadow_rect, ulFormat, D3DCOLOR_ARGB(255, 0, 0, 0)); } // Draw the text pFont->DrawText(m_pSprite, szText, -1, &rect, ulFormat, ulColor); // End the sprite m_pSprite->End(); }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { //Set camera D3DXMATRIX view, proj; D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 10.0f, -50.0f), &D3DXVECTOR3(0.0f, 3.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); D3DXMatrixOrthoLH(&proj, 10.0f, 9.0f, 0.1f, 1000.0f); m_pDevice->SetTransform(D3DTS_VIEW, &view); m_pDevice->SetTransform(D3DTS_PROJECTION, &proj); if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); m_farmer1.Render(); m_farmer2.RenderProgressive(); //Number of polygons char number[50]; std::string text = itoa(m_farmer2.GetNumProgressiveFaces(), number, 10); text += " polygons (UP/DOWN Arrow)"; RECT r[] = {{170, 520, 0, 0}, {530, 520, 0, 0}, {470, 540, 0, 0}, {130, 540, 0, 0}}; m_pFont->DrawText(NULL, "Original", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "Progressive Mesh", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, text.c_str(), -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "(W)ireframe On/Off", -1, &r[3], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
void Game::displayGfxStats() { // Make static so memory is not allocated every frame. static char buffer[256]; sprintf_s(buffer, "Frames Per Second = %.2f\n" "Milliseconds Per Frame = %.4f\n", mFPS, mMilliSecPerFrame); D3DCOLOR textColor = D3DCOLOR_XRGB(0, 0, 0); if ( gMyGameWorld->BackgroundRed() + gMyGameWorld->BackgroundGreen() + gMyGameWorld->BackgroundBlue() < 384 ) textColor = D3DCOLOR_XRGB(255, 255, 255); RECT R = {5, 5, 0, 0}; HR(mFont->DrawText(0, buffer, -1, &R, DT_NOCLIP, textColor)); }
void DrawMyText( IDirect3DDevice9* g_pD3DDevice, char* StrokaTexta, int x, int y, int x1, int y1, D3DCOLOR MyColor ) { RECT Rec; HFONT hFont; ID3DXFont* pFont = 0; hFont = CreateFont(30, 10, 0, 0, FW_NORMAL, FALSE, FALSE, 0, 1, 0, 0, 0, DEFAULT_PITCH | FF_MODERN, "Arial"); Rec.left = x; Rec.top = y; Rec.right = x1; Rec.bottom = y1; D3DXCreateFont( g_pD3DDevice, 30, 10, FW_NORMAL, 0, FALSE, 0, 0, 0, DEFAULT_PITCH | FF_MODERN, "Arial", &pFont ); pFont->DrawText(0, StrokaTexta, -1, &Rec, DT_WORDBREAK, MyColor); if (pFont) pFont->Release(); }
void HelloD3DApp::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255, 255, 255), 1.0f, 0)); RECT formatRect; GetClientRect(mhMainWnd, &formatRect); HR(gd3dDevice->BeginScene()); mFont->DrawText(0, _T("Hello Direct3D"), -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256)); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear( 0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { if(m_pHeightMap != NULL)m_pHeightMap->Render(); RECT r = {630, 10, 800, 30}; m_pFont->DrawText(NULL, "Space: Change Image", -1, &r, DT_LEFT | DT_NOCLIP | DT_TOP, 0xffffffff); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
void InitDX9App::drawScene() { HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(255,255,255), 1.0f, 0)); RECT formatRect; GetClientRect(mhMainWnd, &formatRect); HR(gd3dDevice->BeginScene()); mFont->DrawText(0, L"Hello Direct3D 9", -1, &formatRect, DT_CENTER | DT_VCENTER, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256)); D3DXVECTOR2 line[] = { D3DXVECTOR2(0,0), D3DXVECTOR2(100.0f, 100.0f), D3DXVECTOR2(100.0f, 200.0f), }; mLine->Begin(); mLine->Draw(line, 3, D3DCOLOR_XRGB(255,0,0)); mLine->End(); HR(gd3dDevice->EndScene()); HR(gd3dDevice->Present(0, 0, 0, 0)); }
void Evolution::drawScene() { // Clear the backbuffer and depth buffer. HR(gd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0)); HR(gd3dDevice->BeginScene()); static char buffer[255]; static RECT clientRect = {0, 0, 0, 0}; GetClientRect(mhMainWnd, &clientRect); HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, true)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAREF, 25)); HR(gd3dDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER)); if (foodList.size() != 0 || eggList.size() != 0) drawEggsFood(); if (lifeformList.size() != 0) drawLifeforms(); if (mbDrawInfo) { sprintf(buffer, "Carnivore: %d\n" "Carnivore Parts: %d\n" "Egg Cycle Length: %f\n" "Egg Time Length: %f\n" "Food Cycle Length: %f\n" "Lifetime Length: %f\n" "Sight Distance: %f\n" "Fear Distance: %f\n" "Pursuit Length: %f\n" "Speed: %f", mDrawInfo.carnivore, mDrawInfo.carnivoreParts, mDrawInfo.eggCycleLength, mDrawInfo.eggTimeLength, mDrawInfo.foodCycleLength, mDrawInfo.lifeTimeLength, mDrawInfo.sightDistance, mDrawInfo.fearDistance, mDrawInfo.pursuitLength, mDrawInfo.speed); RECT N = {clientRect.left, clientRect.top+(4*18), clientRect.left+300, clientRect.top+(14*18)}; HR(mFont->DrawText(0, buffer, -1, &N, DT_LEFT | DT_NOCLIP, D3DCOLOR_XRGB(0, 0, 0))); } /*if (foodList.size() + BellyFoods + eggList.size() != mMaxBio || BellyFoods < 0) { sprintf(buffer, "BIOMASS LOST/GAINED"); RECT N = {clientRect.left, clientRect.top+(4*18), clientRect.left+300, clientRect.top+(13*18)}; HR(mFont->DrawText(0, buffer, -1, &N, DT_LEFT | DT_NOCLIP, D3DCOLOR_XRGB(255, 0, 0))); }*/ mGfxStats->display(); HR(gd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false)); HR(gd3dDevice->EndScene()); // Present the backbuffer. HR(gd3dDevice->Present(0, 0, 0, 0)); }
HRESULT APPLICATION::Render() { //Setup the viewport D3DVIEWPORT9 v, v2; v.Width = 800; v.Height = 600; v.X = 0; v.Y = 0; v.MaxZ = 1.0f; v.MinZ = 0.0f; m_pDevice->SetViewport(&v); v2 = v; // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xff4444ff, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { //Render big city m_city.Render(&m_camera); RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}}; m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); //Render city overview, set viewport v.X = 550; v.Y = 20; v.Width = 230; v.Height = 230; m_pDevice->SetViewport(&v); m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L ); //Setup camera view to orthogonal view looking down on city D3DXMATRIX viewTop, projectionTop; D3DXMatrixLookAtLH(&viewTop, &(m_city.GetCenter() + D3DXVECTOR3(0.0f, 100.0f, 0.0f)), &m_city.GetCenter(), &D3DXVECTOR3(0,0,1)); D3DXMatrixOrthoLH(&projectionTop, m_city.m_size.x * TILE_SIZE, m_city.m_size.y * TILE_SIZE, 0.1f, 1000.0f); m_pDevice->SetTransform(D3DTS_VIEW, &viewTop); m_pDevice->SetTransform(D3DTS_PROJECTION, &projectionTop); //Draw city blocks that are in view m_city.Render(NULL); //Restore viewport m_pDevice->SetViewport(&v2); //Draw line around smaller window D3DXVECTOR2 outline[] = {D3DXVECTOR2(550, 20), D3DXVECTOR2(779, 20), D3DXVECTOR2(779, 249), D3DXVECTOR2(550, 249), D3DXVECTOR2(550, 20)}; m_pLine->SetWidth(3.0f); m_pLine->Begin(); m_pLine->Draw(outline, 5, 0xff000000); m_pLine->End(); //Draw mouse m_mouse.Paint(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }
HRESULT APPLICATION::Render() { // Clear the viewport m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0L ); // Begin the scene if(SUCCEEDED(m_pDevice->BeginScene())) { for(int i=0;i<(int)m_objects.size();i++) m_objects[i].Render(); //Find intersecting object closest to the camera D3DXMATRIX identity; D3DXMatrixIdentity(&identity); int object = -1; float bestDist = 100000.0f; for(int i=0;i<(int)m_objects.size() - 1;i++) { float dist = -1.0f; //Do intersection tests if(m_intersectType == 0) { m_pDevice->SetTransform(D3DTS_WORLD, &m_objects[i].m_meshInstance.GetWorldMatrix()); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_meshInstance); } else if(m_intersectType == 1) { m_pDevice->SetTransform(D3DTS_WORLD, &identity); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_BBox); } else if(m_intersectType == 2) { m_pDevice->SetTransform(D3DTS_WORLD, &identity); RAY ray = m_mouse.GetRay(); dist = ray.Intersect(m_objects[i].m_BSphere); } m_objects[i].RenderBoundingVolume(m_intersectType); if(dist >= 0.0f && dist < bestDist) { object = i; bestDist = dist; } } //Write m_mouse text if(object != -1) { RECT mr[] = {{m_mouse.x + 2, m_mouse.y + 24, 0, 0}, {m_mouse.x, m_mouse.y + 22, 0, 0}}; m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000); m_pFontMouse->DrawText(NULL, m_objects[object].m_name.c_str(), -1, &mr[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffff0000); } RECT r[] = {{10, 10, 0, 0}, {10, 30, 0, 0}, {10, 50, 0, 0}}; m_pFont->DrawText(NULL, "Mouse Wheel: Change Camera Radius", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); m_pFont->DrawText(NULL, "Arrows: Change Camera Angle", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); m_pFont->DrawText(NULL, "Space: Change Bounding Volume", -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); RECT rc = {500, 10, 0, 0}; if(m_intersectType == 0) m_pFont->DrawText(NULL, "Mesh Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); else if(m_intersectType == 1) m_pFont->DrawText(NULL, "Box Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); else if(m_intersectType == 2) m_pFont->DrawText(NULL, "Sphere Intersection Test", -1, &rc, DT_LEFT| DT_TOP | DT_NOCLIP, 0xffffffff); //Draw m_mouse m_mouse.Paint(); // End the scene. m_pDevice->EndScene(); m_pDevice->Present(0, 0, 0, 0); } return S_OK; }