/////////////////////////////////////////////////////////////////// // Function: "SpriteEnd" // // Last Modified: 5/25/2006 // // Input: void // // Return: true if successful. // // Purpose: Ends the sprite for rendering. /////////////////////////////////////////////////////////////////// bool CSGD_Direct3D::SpriteEnd(void) { if (FAILED(m_lpSprite->End())) DXERROR(_T("Failed to end sprite scene.")) return true; }
/////////////////////////////////////////////////////////////////// // Function: "DeviceEnd" // // Last Modified: 5/25/2006 // // Input: void // // Return: true if successful. // // Purpose: Ends the device for rendering. /////////////////////////////////////////////////////////////////// bool CSGD_Direct3D::DeviceEnd(void) { if (FAILED(m_lpDirect3DDevice->EndScene())) DXERROR(_T("Failed to end device scene.")) return true; }
/////////////////////////////////////////////////////////////////// // Function: "SpriteBegin" // // Last Modified: 5/25/2006 // // Input: void // // Return: true if successful. // // Purpose: Begins the sprite for rendering. /////////////////////////////////////////////////////////////////// bool CSGD_Direct3D::SpriteBegin(void) { if (FAILED(m_lpSprite->Begin(D3DXSPRITE_ALPHABLEND))) DXERROR(_T("Failed to begin sprite scene.")) return true; }
/////////////////////////////////////////////////////////////////// // Function: "DeviceBegin" // // Last Modified: 5/25/2006 // // Input: void // // Return: true if successful. // // Purpose: Begins the device for rendering. /////////////////////////////////////////////////////////////////// bool CSGD_Direct3D::DeviceBegin(void) { if (FAILED(m_lpDirect3DDevice->BeginScene())) DXERROR(_T("Failed to begin device scene.")) return true; }
void Number::draw(int n) { if ( n < 0 || n > 11) return; pd3dDevice->SetTexture( 0, pTex ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE ); pd3dDevice->SetVertexShader(FVF_PNT); pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); pd3dDevice->SetStreamSource(0, polys, sizeof(PNTVertex)); DXERROR(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 4*n, 2)); pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); }
bool CSGD_TextureManager::DrawF(int nID, float nX, float nY, float fScaleX, float fScaleY, RECT* pSection, float fRotCenterX, float fRotCenterY, float fRotation, DWORD dwColor) { // Make sure the nID is in range. assert(nID > -1 && nID < (int)m_Textures.size() && "nID is out of range"); // Make sure that the texture is valid assert(m_Textures[nID].texture != NULL && "Attempting to draw released texture id"); // Make sure the sprite was created and we have a valid texture. if (!m_lpSprite) return false; D3DXMATRIX scale; D3DXMATRIX rotation; D3DXMATRIX translate; D3DXMATRIX combined; // Initialize the Combined matrix. D3DXMatrixIdentity(&combined); // Scale the sprite. D3DXMatrixScaling(&scale, fScaleX, fScaleY, 1.0f); combined *= scale; // Rotate the sprite. D3DXMatrixTranslation(&translate, -fRotCenterX * fScaleX, -fRotCenterY * fScaleY, 0.0f); combined *= translate; D3DXMatrixRotationZ(&rotation, fRotation); combined *= rotation; D3DXMatrixTranslation(&translate, fRotCenterX * fScaleX, fRotCenterY * fScaleY, 0.0f); combined *= translate; // Translate the sprite D3DXMatrixTranslation(&translate, (float)nX, (float)nY, 0.0f); combined *= translate; // Apply the transform. m_lpSprite->SetTransform(&combined); // Draw the sprite. if (FAILED(m_lpSprite->Draw(m_Textures[nID].texture, pSection, NULL, NULL, dwColor))) DXERROR("Failed to draw the texture."); // Move the world back to identity. D3DXMatrixIdentity(&combined); m_lpSprite->SetTransform(&combined); // success. return true; }
void Console::draw(){ //Setup prompt int fps = 1000 / dxs->getFrameTime(); sprintf( prompt, "%i fps ", fps ); if (position < desiredPosition ){ position+=7; if (position > desiredPosition) position = desiredPosition; } else if (position > desiredPosition){ position-=7; if (position < desiredPosition) position = desiredPosition; } char text[CONSOLE_WIDTH+3]; translate(0, (((float)position + 20) / HEIGHT)-1.0f, 0); //render the console if needed if(position > 0){ if ( contex == NULL ){ pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_DIFFUSE ); }else{ pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG2 ); pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_TEXTURE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTEXF_LINEAR ); pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTEXF_LINEAR ); pd3dDevice->SetTexture( 0, contex ); } pd3dDevice->SetRenderState(D3DRS_LIGHTING, FALSE); pd3dDevice->SetVertexShader(FVF_PNCT); pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE); pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); pd3dDevice->SetStreamSource(0, conpolys, sizeof(PNCTVertex)); DXERROR(pd3dDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2)); //Fix renderstates pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW); pd3dDevice->SetTexture( 0, NULL ); pd3dDevice->SetRenderState(D3DRS_LIGHTING, TRUE); pd3dDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE); RECT lineRect = {10, position - 15, 0, 0}; CONSOLE_LINE *line; //print the input line if (showInput){ sprintf(text,"%s> %s_", prompt, inputLine); pdxfDefFont->DrawText(text, -1, &lineRect, DT_NOCLIP, D3DCOLOR_XRGB(255, 255, 255)); } //work up screen printing the rest lineRect.top -= 15; line = consoleCurrent; while(line && lineRect.top >= 0){ pdxfDefFont->DrawText(line->text, -1, &lineRect, DT_NOCLIP, D3DCOLOR_XRGB(255, 255, 255)); lineRect.top -= 15; line = line->next; } } else {//Show the last line of text RECT lineRect = {0, 0, WIDTH, position}; sprintf(text,"%s: %s", prompt, consoleHead->text); pdxfDefFont->DrawText(text, -1, &lineRect, DT_NOCLIP, D3DCOLOR_XRGB(255, 255, 255)); } }
/////////////////////////////////////////////////////////////////// // Function: "Initialize" // // Last Modified: 2/26/2013 // // Input: hWnd A handle to the window to initialize // Direct3D in. // nScreenWidth The width to initialize the device into. // nScreenHeight The height to initialize the device into. // bIsWindowed The screen mode to initialize the device into. // bVsync true to put the device into vsynced display mode. // // Return: true if successful. // // Purpose: Initializes Direct3D9. /////////////////////////////////////////////////////////////////// bool CSGD_Direct3D::Initialize(HWND hWnd, int nScreenWidth, int nScreenHeight, bool bIsWindowed, bool bVsync) { // Make sure the hWnd is valid. if (!hWnd) return false; // Set the handle to the window & store window style. m_hWnd = hWnd; m_lWindowStyle = GetWindowLong( m_hWnd, GWL_STYLE ); // Create the Direct3D9 Object. m_lpDirect3DObject = Direct3DCreate9(D3D_SDK_VERSION); // Make sure the object is valid. if (!m_lpDirect3DObject) DXERROR(_T("Failed to Create D3D Object")) // Setup the parameters for using Direct3D. m_PresentParams.BackBufferWidth = nScreenWidth; m_PresentParams.BackBufferHeight = nScreenHeight; m_PresentParams.BackBufferFormat = D3DFMT_UNKNOWN; m_PresentParams.BackBufferCount = 1; m_PresentParams.MultiSampleType = D3DMULTISAMPLE_NONE; m_PresentParams.MultiSampleQuality = 0; m_PresentParams.SwapEffect = D3DSWAPEFFECT_COPY; m_PresentParams.hDeviceWindow = hWnd; m_PresentParams.Windowed = true; m_PresentParams.EnableAutoDepthStencil = false; m_PresentParams.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER; m_PresentParams.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT; m_PresentParams.PresentationInterval = (bVsync) ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE; // Create the Direct3D Device. if (FAILED(m_lpDirect3DObject->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &m_PresentParams, &m_lpDirect3DDevice))) DXERROR(_T("Failed to Create D3D Device")) // Create Sprite Object. if (FAILED(D3DXCreateSprite(m_lpDirect3DDevice, &m_lpSprite))) DXERROR(_T("Failed to Create the Sprite object")) // Create Font Object. if (FAILED( D3DXCreateFont( m_lpDirect3DDevice, // D3D device 23, // Height 0, // Width FW_SEMIBOLD, // Weight 1, // MipLevels, 0 = autogen mipmaps FALSE, // Italic DEFAULT_CHARSET, // CharSet OUT_DEFAULT_PRECIS, // OutputPrecision DEFAULT_QUALITY, // Quality DEFAULT_PITCH | FF_DONTCARE, // PitchAndFamily _T("Arial"), // pFaceName &m_lpFont ) // ppFont )) DXERROR(_T("Failed to Create the Font Object")) // Create the Rect Texture. if (FAILED(D3DXCreateTexture(m_lpDirect3DDevice, 1, 1, 1, 0, D3DFMT_UNKNOWN, D3DPOOL_MANAGED, &m_lpTexture))) DXERROR(_T("Failed to Create the Rect Texture")) // Fill the Rect Texture. D3DLOCKED_RECT area; m_lpTexture->LockRect(0,&area,0,D3DLOCK_DISCARD); ((DWORD*)area.pBits)[0] = 0xFFFFFFFF; m_lpTexture->UnlockRect(0); // Preload font characters for speed. m_lpFont->PreloadCharacters( '0', '9' ); m_lpFont->PreloadCharacters( 'A', 'Z' ); m_lpFont->PreloadCharacters( 'a', 'z' ); // Switch to fullscreen? if( !bIsWindowed ) return Resize( nScreenWidth, nScreenHeight, bIsWindowed ); // Return success. return true; }