int SceneGraph::Render() { int result = 0; int hr = 0; D3DCOLOR color = D3DRGBA(0.0f, 0.0f, 0.0f, 1.0f); // Clear the back buffer if (FAILED( hr = m_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER , color, 1.0f, 0) ) ) result = 1; //Load/Set appropriate textures and techniques if (FAILED( hr = m_pEffect->SetTechnique( "RenderScene_GeometrynLightsOnly" ) ) ) result = 1; D3DXMATRIXA16 identity; D3DXMatrixIdentity(&identity); SceneGraphNodeData data; data.pDevice = m_pDevice; data.pEffect = m_pEffect; data.projection = m_Projection; data.transform = identity; data.vecEye = m_VecEye; data.view = m_View; if( SUCCEEDED( m_pDevice->BeginScene() ) ) { m_Root.Action(&data); if (FAILED( hr = m_pDevice->EndScene() ) ) result = 1; } else result = 1; return result | hr; }
SCERROR GfxD3D7Device::Initialize(GFX_VALUE winmod,GFX_VALUE vmode,GFX_VALUE bpp,bool disable_drv_info) { bpp_ = GFX_UNKNOWN; wndMode_ = GFX_UNKNOWN; mode_ = GFX_UNKNOWN; refrate_ = GFX_UNKNOWN; width_ = 0; height_ = 0; filler_color_ = D3DRGBA(0,0,0,1); filler_depth_ = 1.0f; modelview_stack_count_ = 0; wModeNoMenu_ = false; wModeNoFrame_ = false; safe_ = true; flip_immediate_ = false; enableFlipping_ = true; enableExclusive_ = true; vsync_ = false; memset( texpf_, 0, sizeof(texpf_) ); fail_if_fail(InitializeDDraw()); { DDSCAPS2 ddsCaps2; DWORD dwTotal,dwFree; ZeroMemory(&ddsCaps2, sizeof(ddsCaps2)); ddsCaps2.dwCaps = DDSCAPS_LOCALVIDMEM; if ( SUCCEEDED(idraw_->GetAvailableVidMem(&ddsCaps2, &dwTotal, &dwFree) ) ) video_local_mem_ = dwTotal; } if ( !disable_drv_info ) { DDDEVICEIDENTIFIER2 idi; HRESULT hr = idraw_->GetDeviceIdentifier(&idi,/*D3DENUM_NO_WHQL_LEVEL*/ 0x00000002L); if ( hr == (HRESULT)E_INVALIDARG ) hr = idraw_->GetDeviceIdentifier(&idi,0); if ( SUCCEEDED(hr) ) { Lout << _S*"%?%?" %gfxd3d7 %idi.szDescription; Lout << _S*"%?DRIVER %-12? [%?]" %gfxd3d7 %idi.szDriver %teggo::GetModuleVersion(idi.szDriver); } } Lout << _S*"%?DDRAW %-12? [%?]" %gfxd3d7 %"ddraw.dll" %teggo::GetModuleVersion("ddraw.dll"); Lout << _S*"%?D3DIM %-12? [%?]" %gfxd3d7 %"d3dim700.dll" %teggo::GetModuleVersion("d3dim700.dll"); fail_if_fail(InitializeD3D()); id3d_->EnumDevices(LogHALCaps,this); LogVMemSize(+idraw_); //Lout << ""; //fail_if_fail(SetMode(GFX_WINDOWED,GFX_640x480,GFX_UNKNOWN,GFX_UNKNOWN)); fail_if_fail(SetMode(winmod,vmode,bpp,GFX_UNKNOWN)); context_restored_ = false; return SCE_OK; }
void CRadar::DrawUI(LPDIRECT3DDEVICE7 lpDevice) { if (!Enabled)return; if ((lpSurface==NULL)||(lpSurface->IsLost())) { UpdateSurface(); Update(); } const float w=130.0f*game->width/640.0f; const float h=130.0f*game->width/640.0f; const float x=game->width-20-w; const float y=game->height-20-h; const int c=D3DRGBA(1,1,1,0.45f); const float r=0.9f; D3DTLVERTEX v[4]={ D3DTLVERTEX(D3DVECTOR(x,y,0),r,c,0,0,0), D3DTLVERTEX(D3DVECTOR(x+w,y,0),r,c,0,1,0), D3DTLVERTEX(D3DVECTOR(x,y+h,0),r,c,0,0,1), D3DTLVERTEX(D3DVECTOR(x+w,y+h,0),r,c,0,1,1) }; if (Config.alpha) { // lpDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,FALSE); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,TRUE); lpDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND,D3DBLEND_SRCALPHA); lpDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND,D3DBLEND_INVSRCALPHA); lpDevice->SetTextureStageState(0,D3DTSS_ALPHAOP,D3DTOP_MODULATE); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,TRUE); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAREF,8); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHAFUNC,D3DCMP_GREATEREQUAL); } lpDevice->SetTexture(0,lpSurface); lpDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,D3DFVF_TLVERTEX,v,4,0); lpDevice->SetTexture(0,NULL); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE,0); lpDevice->SetRenderState(D3DRENDERSTATE_ALPHATESTENABLE,0); // lpDevice->SetRenderState(D3DRENDERSTATE_ZENABLE,TRUE); }
void DrawShadow(LPDIRECT3DDEVICE7 lpDevice) { lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, FALSE ); lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, TRUE ); // Turn on alphablending lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE ); lpDevice->SetRenderState( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA ); lpDevice->SetRenderState( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA ); lpDevice->SetTextureStageState(0,D3DTSS_ALPHAARG1,D3DTA_DIFFUSE); // Only write where the stencil value == 1 lpDevice->SetRenderState( D3DRENDERSTATE_STENCILREF, 0x1 ); lpDevice->SetRenderState( D3DRENDERSTATE_STENCILFUNC, D3DCMP_EQUAL ); lpDevice->SetRenderState( D3DRENDERSTATE_STENCILPASS, D3DSTENCILOP_KEEP ); // Get viewport dimensions for big, gray square D3DVIEWPORT7 vp; lpDevice->GetViewport(&vp); FLOAT sx = (FLOAT)vp.dwWidth; FLOAT sy = (FLOAT)vp.dwHeight; D3DCOLOR color=D3DRGBA(0,0,0,0.5f); // Draw a big, gray square D3DTLVERTEX vBigGraySquare[4]; vBigGraySquare[0] = D3DTLVERTEX( D3DVECTOR( 0,sy,0.0f),1.0f,color,0,0,0 ); vBigGraySquare[1] = D3DTLVERTEX( D3DVECTOR( 0, 0,0.0f),1.0f,color,0,0,0 ); vBigGraySquare[2] = D3DTLVERTEX( D3DVECTOR(sx,sy,0.0f),1.0f,color,0,0,0 ); vBigGraySquare[3] = D3DTLVERTEX( D3DVECTOR(sx, 0,0.0f),1.0f,color,0,0,0 ); lpDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, D3DFVF_TLVERTEX, vBigGraySquare, 4, NULL ); // Restore render states lpDevice->SetRenderState( D3DRENDERSTATE_ZENABLE, TRUE ); lpDevice->SetRenderState( D3DRENDERSTATE_STENCILENABLE, FALSE ); lpDevice->SetRenderState( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE ); }
void Renderer::DrawScene() { D3DCOLOR color = D3DRGBA(0.0f,1.0f,0.0f,1.0f); // Clear the render target and the zbuffer m_pDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, color, 1.0f, 0 ); //Render the scene if( SUCCEEDED( m_pDevice->BeginScene() ) ) { // Get the projection & view matrix from the camera class // Update the effect's variables D3DXMATRIXA16 viewProjection = m_View * m_Projection; m_pEffect->SetMatrix( "g_mViewProjection" , &viewProjection); HRESULT hr; UINT iPass, cPasses; m_pDevice->SetVertexDeclaration( m_pVertexDeclHardware ); // Stream zero is our model, and its frequency is how we communicate the number of instances required, // which in this case is the total number of boxes m_pDevice->SetStreamSource( 0, m_pVB, 0, D3DXGetDeclVertexSize( m_VertexDeclaration , 0) ); m_pDevice->SetStreamSourceFreq( 0, D3DSTREAMSOURCE_INDEXEDDATA | m_Size); // Stream one is the instancing buffer, so this advances to the next value // after each box instance has been drawn, so the divider is 1. m_pDevice->SetStreamSource( 1, m_pVBInstanceData, 0, sizeof(InstanceData) ); m_pDevice->SetStreamSourceFreq( 1, D3DSTREAMSOURCE_INSTANCEDATA | 1ul ); m_pDevice->SetIndices( m_pIB ); // Render the scene with this technique // as defined in the .fx file m_pEffect->SetTechnique( "RenderScene" ); m_pEffect->Begin( &cPasses, 0 ); for( iPass = 0; iPass < cPasses; iPass++ ) { m_pEffect->BeginPass( iPass ); // Render the boxes with the applied technique // The effect interface queues up the changes and performs them // with the CommitChanges call. You do not need to call CommitChanges if // you are not setting any parameters between the BeginPass and EndPass. m_pEffect->CommitChanges(); //m_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 4 * 6, 0, 6 * 2 ); m_pSphere->DrawSubset(0); m_pEffect->EndPass(); } m_pEffect->End(); m_pDevice->SetStreamSourceFreq( 0, 1 ); m_pDevice->SetStreamSourceFreq( 1, 1 ); m_pDevice->EndScene(); } }