bool Lighting::EvaluateSpecular(LPDIRECT3DDEVICE9 Device, RenderMesh *RMesh, ShaderMat *Mat) { if(!Device || !RMesh || !m_Ready) { return(false); } if(!Mat->m_AlphaOn && Mat->m_ChannelLoaded & MAT_SPECULAR_ON) { SetRenderStates(); Device->SetVertexShader(m_VertexHandle[SHADER_SPEC]); Device->SetPixelShader(m_PixelHandle[SHADER_SPEC]); SetMaterialConst(Mat); Mat->SetChannelsSpecular(Device); Device->SetRenderState(D3DRS_ZWRITEENABLE,FALSE); Device->SetRenderState(D3DRS_ALPHABLENDENABLE,TRUE); Device->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_DESTALPHA); Device->SetRenderState(D3DRS_DESTBLEND,D3DBLEND_ONE); RMesh->Render(m_Device); } return(true); }
void DevReset() { SAFE_RELEASE(backBuf); SAFE_RELEASE(backDepthBuf); Image::AllRelease(); SAFE_RELEASE(scrDepthBuf); SAFE_RELEASE(scrBuf); SAFE_RELEASE(gameScr); g_d3dSprite->OnLostDevice(); HRESULT hr = g_d3dDev->Reset(&d3dpp); g_d3dSprite->OnResetDevice(); if (FAILED(hr)) { if (hr == D3DERR_DEVICELOST) { onDeviceLost(); } throw Error("デバイスのリセットエラー", hr); } ReadyResource(); SetRenderStates(); return; }
void CGraphicsMaterial::Draw(void) { int i; //Set the textures. for (i = 0; i < miNumTextures; i++) { if (mapsTexture[i]) { gcD3D.SetTexture(i, mapsTexture[i]->GetTexture()); } else { gcD3D.SetTexture(i, gcD3D.GetNullTexture()); } } for (; i < MAX_TEX; i++) { gcD3D.SetTexture(i, gcD3D.GetNullTexture()); } //Set the material. gcD3D.SetMaterial(&msMaterial); //Set any unusual render states this material might use. SetRenderStates(); }
//----------------------------------------------------------------------------- void CPUTModelOGL::DrawBoundingBox(CPUTRenderParameters &renderParams) { SetRenderStates(renderParams); CPUTMaterialOGL *pMaterial = (CPUTMaterialOGL*)mpBoundingBoxMaterial; mpBoundingBoxMaterial->SetRenderStates(renderParams); ((CPUTMeshOGL*)mpBoundingBoxMesh)->Draw(renderParams, this); }
//////////////////////////////////////////////////////////// /// Called after the window has been created //////////////////////////////////////////////////////////// void RenderWindow::OnCreate() { // Set the default rendering states SetRenderStates(); // Setup the default view myDefaultView.SetFromRect(FloatRect(0, 0, static_cast<float>(GetWidth()), static_cast<float>(GetHeight()))); SetView(myDefaultView); }
void DxStdMtl2::Draw() { bool NegScale; if(!IsDxMaterialEnabled(map)) return; TimeValue m_T = GetCOREInterface()->GetTime(); NegScale = TMNegParity(mpMeshCache->GetActiveNode(m_CurCache)->GetObjTMAfterWSM(m_T)); Mtl * m_Mtl = mpMeshCache->GetActiveNode(m_CurCache)->GetMtl(); Color col = GetCOREInterface()->GetViewportBGColor(); D3DCOLOR bkgColor = col.toRGB(); if(!pd3dDevice) pd3dDevice = GetDevice(); int w =0, h =0; myGWindow->GetWindowDimension(w,h); SetRenderStates(); if(pEffectParser) { SetEffectData(); if(!pEffectParser->PreRender(pd3dDevice,mpMeshCache->GetActiveRenderMesh(m_CurCache),this,this,bkgColor, w,h)) { DrawError(); return; } if(!mpMeshCache->GetActiveRenderMesh(m_CurCache)->Evaluate(pd3dDevice, mpMeshCache->GetActiveMesh(m_CurCache),GetMatIndex(m_Mtl),NegScale)) return; if(!pEffectParser->Render(pd3dDevice,mpMeshCache->GetActiveRenderMesh(m_CurCache),techniqueName.data())) { DrawError(); return; } } //draw the object in Red WireFrame mode for testing purposes else { DrawError(); } }
//////////////////////////////////////////////////////////// /// Draw something on the window //////////////////////////////////////////////////////////// void RenderWindow::Draw(const Drawable& Object) const { // Check whether we are called from the outside or from a previous call to Draw if (!myIsDrawing) { myIsDrawing = true; // Set our window as the current target for rendering if (SetActive()) { // Save the current render states and set the SFML ones if (myPreserveStates) { GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glPushMatrix()); GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPushMatrix()); GLCheck(glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT | GL_ENABLE_BIT | GL_TEXTURE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT)); SetRenderStates(); } // Set the window viewport and transform matrices GLCheck(glViewport(0, 0, GetWidth(), GetHeight())); GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glLoadMatrixf(myCurrentView->GetMatrix().Get4x4Elements())); GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glLoadIdentity()); // Let the object draw itself Object.Draw(*this); // Restore render states if (myPreserveStates) { GLCheck(glMatrixMode(GL_PROJECTION)); GLCheck(glPopMatrix()); GLCheck(glMatrixMode(GL_MODELVIEW)); GLCheck(glPopMatrix()); GLCheck(glPopAttrib()); } } myIsDrawing = false; } else { // We are already called from a previous Draw : we don't need to set the states again, just draw the object Object.Draw(*this); } }
HRESULT StartUp( HWND hWnd) { hWindow = hWnd; DisplaySize.cx = (UINT)GetSystemMetrics(SM_CXSCREEN); DisplaySize.cy = (UINT)GetSystemMetrics(SM_CYSCREEN); if (Settings.DSMode) { DirectSoundCreate8(NULL, &g_ds, NULL); g_ds->SetCooperativeLevel(hWnd, DSSCL_NORMAL); } else { if (Settings.coLibInit) { if (FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED))) { throw Error("COMの初期化に失敗"); } } if (FAILED(XAudio2Create(&g_xa))) { throw Error("XAudio2の初期化に失敗"); } if (FAILED(g_xa->CreateMasteringVoice(&g_xamv))) { throw Error("マスターボイスの作成に失敗"); } } scrPosFull = D3DXVECTOR3( (float)((DisplaySize.cx / 2 - g_pixSz * Settings.screenWidth / 2) / g_pixSz), (float)((DisplaySize.cy / 2 - g_pixSz * Settings.screenHeight / 2) / g_pixSz), 0.0f); scrPosWnd = D3DXVECTOR3(0.0f, 0.0f, 0.0f); if (Settings.ScreenOnly) { if (!g_fullScr) { hRectRgn = CreateRectRgn(0, 0, Settings.screenWidth * g_pixSz, Settings.screenHeight * g_pixSz); if (hRectRgn == NULL) { throw Error("リージョンの作成に失敗"); } if (SetWindowRgn(hWnd, hRectRgn, FALSE) == 0) { throw Error("リージョンの設定に失敗"); } } } g_d3d = Direct3DCreate9(D3D_SDK_VERSION); if (g_d3d == NULL) { throw Error("Direct3Dの初期化に失敗"); } SetD3dpp(g_fullScr); if (FAILED(g_d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &g_d3dDev))) { throw Error("Direct3Dデバイスの初期化に失敗"); } D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; vp.Width = d3dpp.BackBufferWidth; vp.Height = d3dpp.BackBufferHeight; vp.MinZ = 0.0f; vp.MaxZ = 1.0f; if (FAILED(g_d3dDev->SetViewport(&vp))) { throw Error("ビューポートの設定に失敗"); } SetRenderStates(); if (FAILED(D3DXCreateSprite(g_d3dDev, &g_d3dSprite))) { throw Error("スプライトの作成に失敗"); } SubSetUp(); ReadyResource(); ShowWindow(hWnd, SW_SHOW); hThd = _beginthreadex(NULL, 0, GameProcessLoop, NULL, 0, NULL); return S_OK; }
int CD3DFont::DrawTextScaled(float x, float y, float fXScale, float fYScale, float spacing, u32 dwColor, const std::string& Text) { if (!m_pVB) return 0; SetRenderStates(); D3D::ChangeStreamSource(0, m_pVB, 0, sizeof(FONT2DVERTEX)); float vpWidth = 1; float vpHeight = 1; float sx = x*vpWidth - 0.5f; float sy = y*vpHeight - 0.5f; float fStartX = sx; float invLineHeight = 1.0f / ((m_fTexCoords[0][3] - m_fTexCoords[0][1]) * m_dwTexHeight); // Fill vertex buffer FONT2DVERTEX* pVertices; int dwNumTriangles = 0L; m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); //First, let's measure the text float tw = 0; float mx = 0; float maxx = 0; for (char c : Text) { if (c == ('\n')) mx = 0; if (c < (' ')) continue; float tx1 = m_fTexCoords[c - 32][0]; float tx2 = m_fTexCoords[c - 32][2]; float w = (tx2 - tx1)*m_dwTexWidth; w *= (fXScale*vpHeight)*invLineHeight; mx += w + spacing*fXScale*vpWidth; if (mx > maxx) maxx = mx; } float offset = -maxx / 2; float wScale = (fXScale*vpHeight)*invLineHeight; float hScale = (fYScale*vpHeight)*invLineHeight; // Let's draw it for (char c : Text) { if (c == ('\n')) { sx = fStartX; sy += fYScale*vpHeight; } if (c < (' ')) continue; c -= 32; float tx1 = m_fTexCoords[c][0]; float ty1 = m_fTexCoords[c][1]; float tx2 = m_fTexCoords[c][2]; float ty2 = m_fTexCoords[c][3]; float w = (tx2 - tx1)*m_dwTexWidth; float h = (ty2 - ty1)*m_dwTexHeight; w *= wScale; h *= hScale; FONT2DVERTEX v[6]; v[0] = InitFont2DVertex(sx, sy + h, dwColor, tx1, ty2); v[1] = InitFont2DVertex(sx, sy, dwColor, tx1, ty1); v[2] = InitFont2DVertex(sx + w, sy + h, dwColor, tx2, ty2); v[3] = InitFont2DVertex(sx + w, sy, dwColor, tx2, ty1); v[4] = v[2]; v[5] = v[1]; memcpy(pVertices, v, 6 * sizeof(FONT2DVERTEX)); pVertices += 6; dwNumTriangles += 2; if (dwNumTriangles * 3 > (MAX_NUM_VERTICES - 6)) { // Unlock, render, and relock the vertex buffer m_pVB->Unlock(); dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles); m_pVB->Lock(0, 0, (void**)&pVertices, D3DLOCK_DISCARD); dwNumTriangles = 0; } sx += w + spacing*fXScale*vpWidth; } // Unlock and render the vertex buffer m_pVB->Unlock(); if (dwNumTriangles > 0) dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, dwNumTriangles); RestoreRenderStates(); return S_OK; }
bool Lighting::EvaluateLighting(LPDIRECT3DDEVICE9 Device, RenderMesh *RMesh, ShaderMat *Mat) { D3DLIGHT9 DLight; D3DXVECTOR3 Pos,Dir; RenderLight Light; int i; if(!Device || !RMesh || !m_Ready) { return(false); } m_Device = Device; // // Setup // // The force update is used when the scene is in an unknwon state - usual after a an undo of a light if(m_forceUpdate) GetLightsFromScene(); UpdateLights(); SetRenderStates(); // m_Lights.clear(); if(m_Lights.size()) { for(i=0; i < m_Lights.size(); i++) { SetShader(m_Lights[i].m_Type,Mat); SetMaterialConst(Mat); SetShaderConst(i,&m_Lights[i],Mat); RMesh->Render(m_Device); } } else { m_Device->GetLight(0,&DLight); Light.m_Dir = Point3(-DLight.Direction.x, -DLight.Direction.y, -DLight.Direction.z); Light.m_Color.x = DLight.Diffuse.r; Light.m_Color.y = DLight.Diffuse.g; Light.m_Color.z = DLight.Diffuse.b; Light.m_Pos.x = DLight.Position.x; Light.m_Pos.y = DLight.Position.y; Light.m_Pos.z = DLight.Position.z; Light.m_InnerRange = 1.0f; Light.m_OuterRange = 1.0f / (DLight.Range * 2.0f); SetShader(LIGHT_DIR,Mat); SetMaterialConst(Mat); SetShaderConst(0,&Light,Mat); RMesh->Render(m_Device); } return(true); }