void render() { assert(g_pd3dDevice); camera(); g_pd3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(255, 0, 0), 1.0f, 0); g_pd3dDevice->BeginScene(); { switch(g_object) { case sphere: g_pSphereMesh->DrawSubset(0); break; case cube: g_pCubeMesh->DrawSubset(0); break; case torus: g_pTorusMesh->DrawSubset(0); break; default: assert(!"Invalid object"); break; } } g_pd3dDevice->EndScene(); g_pd3dDevice->Present(NULL, NULL, NULL, NULL); g_rotation += ROTATION_DELTA; }
VOID render(){ g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0); if(SUCCEEDED(g_pDevice->BeginScene())){ setWorldMatrix(); //First, Render the not transparent part for(DWORD i=0; i<g_dwNumMaterials; ++i){ if(g_pMeshMaterials[i].Diffuse.a == 1.0f){ g_pDevice->SetMaterial(&g_pMeshMaterials[i]); g_pDevice->SetTexture(0, g_pMeshTextures[i]); g_pMesh->DrawSubset(i); } } //Second , Render the transparent part for(DWORD i=0; i<g_dwNumMaterials; ++i){ if(g_pMeshMaterials[i].Diffuse.a != 1.0f){ g_pDevice->SetMaterial(&g_pMeshMaterials[i]); g_pDevice->SetTexture(0, g_pMeshTextures[i]); g_pMesh->DrawSubset(i); } } g_pDevice->EndScene(); } g_pDevice->Present(NULL, NULL, NULL, NULL); }
//************************************************************************************************************* void RenderScene(LPD3DXEFFECT effect, int what) { D3DXMATRIX inv; D3DXVECTOR4 uv(1, 1, 1, 1); D3DXVECTOR4 spec(1, 1, 1, 1); for( int i = 0; i < numobjects; ++i ) { SceneObject& obj = objects[i]; if( obj.behavior == what ) { D3DXMatrixInverse(&inv, 0, &obj.world); effect->SetMatrix("matWorld", &obj.world); effect->SetMatrix("matWorldInv", &inv); if( obj.type == FLOOR ) { uv.x = uv.y = 3; spec = D3DXVECTOR4(0.2f, 0.2f, 0.2f, 20.0f); effect->SetVector("uv", &uv); effect->SetVector("matSpecular", &spec); effect->CommitChanges(); device->SetTexture(0, texture2); box->DrawSubset(0); } else if( obj.type == CRATE ) { uv.x = uv.y = 1; spec = D3DXVECTOR4(0.2f, 0.2f, 0.2f, 20.0f); effect->SetVector("uv", &uv); effect->SetVector("matSpecular", &spec); effect->CommitChanges(); device->SetTexture(0, texture3); box->DrawSubset(0); } else if( obj.type == SKULL ) { uv.x = uv.y = 1; spec = D3DXVECTOR4(0.75f, 0.75f, 0.75f, 80.0f); effect->SetVector("uv", &uv); effect->SetVector("matSpecular", &spec); effect->CommitChanges(); device->SetTexture(0, texture1); skull->DrawSubset(0); } } } }
void Render(HWND hWnd) { g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); g_pDevice->BeginScene(); SetMatrix(); if (::GetAsyncKeyState(0x31) & 0x8000f) g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME); if (::GetAsyncKeyState(0x32) & 0x8000f) g_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); if (::GetAsyncKeyState(0x51) & 0x8000f) SetLight(g_pDevice, 1); if (::GetAsyncKeyState(0x57) & 0x8000f) SetLight(g_pDevice, 2); if (::GetAsyncKeyState(0x45) & 0x8000f) SetLight(g_pDevice, 3); D3DXMatrixTranslation(&g_WorldMatrix[0], -3.0f, -3.0f, 0.0f); g_WorldMatrix[0] = g_WorldMatrix[0] * R; g_pDevice->SetTransform(D3DTS_WORLD, &g_WorldMatrix[0]); g_pTeapot->DrawSubset(0); D3DXMatrixTranslation(&g_WorldMatrix[1], 3.0f, -3.0f, 0.0f); g_WorldMatrix[1] = g_WorldMatrix[1] * R; g_pDevice->SetTransform(D3DTS_WORLD, &g_WorldMatrix[1]); g_pCube->DrawSubset(0); D3DXMatrixTranslation(&g_WorldMatrix[2], 3.0f, 3.0f, 0.0f); g_WorldMatrix[2] = g_WorldMatrix[2] * R; g_pDevice->SetTransform(D3DTS_WORLD, &g_WorldMatrix[2]); g_pTorus->DrawSubset(0); D3DXMatrixTranslation(&g_WorldMatrix[3], -3.0f, 3.0f, 0.0f); g_WorldMatrix[3] = g_WorldMatrix[3] * R; g_pDevice->SetTransform(D3DTS_WORLD, &g_WorldMatrix[3]); g_pSphere->DrawSubset(0); RECT rect; GetClientRect(hWnd, &rect); int count = _stprintf_s(g_strFPS, 20, TEXT("FPS : %0.3f"), GetFPS()); g_pFont->DrawText(NULL, g_strFPS, count, &rect, DT_TOP | DT_RIGHT, D3DCOLOR_XRGB(255, 239, 136)); g_pDevice->EndScene(); g_pDevice->Present(NULL, NULL, NULL, NULL); }
//----------------------------------------------------------------------------- // Name: render_1() // Desc: //----------------------------------------------------------------------------- void render_1( void ) { D3DXMATRIX matView; D3DXMATRIX matWorld; D3DXMATRIX matRotation; D3DXMATRIX matTranslation; // Now we can clear just view-port's portion of the buffer to green... g_pd3dDevice_1->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 0.0f, 1.0f, 0.0f, 1.0f ), 1.0f, 0 ); g_pd3dDevice_1->BeginScene(); // For the left view-port, leave the view at the origin... D3DXMatrixIdentity( &matView ); g_pd3dDevice_1->SetTransform( D3DTS_VIEW, &matView ); // ... and use the world matrix to spin and translate the teapot // out where we can see it... D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f ); D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f ); matWorld = matRotation * matTranslation; g_pd3dDevice_1->SetTransform( D3DTS_WORLD, &matWorld ); g_pd3dDevice_1->SetMaterial( &g_teapotMtrl ); g_pTeapotMesh_1->DrawSubset(0); g_pd3dDevice_1->EndScene(); // We're done! Now, we just call Present() g_pd3dDevice_1->Present( NULL, NULL, NULL, NULL ); }
void XEnitity::DrawMeshContainer(LPD3DXMESHCONTAINER pMeshContainerBase, LPD3DXFRAME pFrameBase) const { CUSTOM_FRAME* pFrame = (CUSTOM_FRAME*)pFrameBase; CUSTOM_MESHCONTAINER* pMeshContainer = (CUSTOM_MESHCONTAINER*)pMeshContainerBase; if(pMeshContainer->pSkinInfo){ D3DXMATRIX Ident; D3DXMatrixIdentity(&Ident); m_d3ddev->SetTransform(D3DTS_WORLD, &Ident); } else{ m_d3ddev->SetTransform(D3DTS_WORLD, &pFrame->exCombTransformationMatrix); } unsigned int NumMaterials = pMeshContainer->NumMaterials; for(unsigned int i = 0; i < NumMaterials; ++i){ m_d3ddev->SetMaterial(&pMeshContainer->pExMaterials[i]); m_d3ddev->SetTexture(0, pMeshContainer->pExTextures[i]); LPD3DXMESH pMeshToDraw = (pMeshContainer->pSkinInfo) ? pMeshContainer->pExSkinMesh : pMeshContainer->MeshData.pMesh; pMeshToDraw->DrawSubset(i); } return; }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render(bool b_AutoRotation, bool b_WireframeMode) { // Clear the backbuffer and the zbuffer g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB( 0, 0, 0, 0 ), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Setup the world, view, and projection matrices // SetupMatrices(); if (b_AutoRotation) SetupMatrices(); g_pd3dDevice->SetRenderState(D3DRS_FILLMODE, (b_WireframeMode) ? D3DFILL_WIREFRAME : D3DFILL_SOLID); g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, (b_WireframeMode) ? D3DCULL_NONE : D3DCULL_CCW); // D3DRenderer are divided into subsets, one for each material. Render them in // a loop for( DWORD i = 0; i < g_dwNumMaterials; i++ ) { // Set the material and texture for this subset g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); // Draw the mesh subset g_pMesh->DrawSubset( i ); } // End the scene g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display // g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render() { // Clear the backbuffer and the zbuffer g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); // Begin the scene g_pd3dDevice->BeginScene(); // Setup the world, view, and projection matrices SetupMatrices(); // Meshes are divided into subsets, one for each material. Render them in // a loop for( DWORD i=0; i<g_dwNumMaterials; i++ ) { // Set the material and texture for this subset g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); // Draw the mesh subset g_pMesh->DrawSubset( i ); } // End the scene g_pd3dDevice->EndScene(); // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
void Render() { g_pd3dDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 255), 1.0f, 0); g_pd3dDevice->BeginScene(); D3DXMATRIXA16 matWorld; D3DXMatrixRotationY(&matWorld, timeGetTime() / 1000.0f); g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld); D3DXVECTOR3 vEyePt(0.0f, 3.0f,-5.0f); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMATRIXA16 matView; D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); g_pd3dDevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIXA16 matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI / 4, 1.0f, 1.0f, 100.0f); g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &matProj); for (DWORD i = 0; i < g_dwNumMaterials; i++) { g_pd3dDevice->SetMaterial(&g_pMeshMaterials[i]); g_pd3dDevice->SetTexture(0, g_pMeshTextures[i]); g_pMesh->DrawSubset(i); } g_pd3dDevice->EndScene(); g_pd3dDevice->Present(0, 0, 0, 0); }
//----------------------------------------------------------------------------- // Desc: 渲染场景 //----------------------------------------------------------------------------- VOID Render() { // 清除缓冲区 g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); //开始渲染场景 if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { SetWorldMatrix(); //设置世界矩阵 //逐块渲染网格模型 for( DWORD i=0; i<g_dwNumMaterials; i++ ) { //设置材料和纹理 g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); //渲染模型 g_pMesh->DrawSubset( i ); } //场景渲染结束 g_pd3dDevice->EndScene(); } //在屏幕上显示场景 g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
void Game_Run(HWND window) { if (!d3ddev) return; DirectInput_Update(); d3ddev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,100), 1.0f, 0); // slow rendering to approximately 60 fps if (timeGetTime() > screentimer + 14) { screentimer = GetTickCount(); //start rendering if (d3ddev->BeginScene()) { //rotate the view D3DXMATRIX matWorld; D3DXMatrixRotationY(&matWorld, timeGetTime()/1000.0f); d3ddev->SetTransform(D3DTS_WORLD, &matWorld); //draw the mesh mesh->DrawSubset(0); //stop rendering d3ddev->EndScene(); d3ddev->Present(NULL, NULL, NULL, NULL); } } //exit with escape key or controller Back button if (KEY_DOWN(VK_ESCAPE)) gameover = true; if (controllers[0].wButtons & XINPUT_GAMEPAD_BACK) gameover = true; }
VOID render(){ g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0); if(SUCCEEDED(g_pDevice->BeginScene())){ //Render the Shutter g_pDevice->SetRenderState(D3DRS_LIGHTING, FALSE); g_pDevice->SetTransform(D3DTS_WORLD, &g_matShutter); g_pDevice->SetStreamSource(0, g_pShutter, 0, sizeof(CUSTOMVERTEX)); g_pDevice->SetFVF(D3DFVF_CUSTOMVERTEX); g_pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2); //Render the Mesh g_pDevice->SetRenderState(D3DRS_LIGHTING, TRUE); g_pDevice->SetTransform(D3DTS_WORLD, &g_matTank); for(DWORD i=0; i<g_dwNumMaterials; ++i){ g_pDevice->SetMaterial(&g_pMeshMaterials[i]); g_pDevice->SetTexture(0, g_pMeshTextures[i]); g_pMesh->DrawSubset(i); }//Render the Mesh g_pDevice->EndScene(); } g_pDevice->Present(NULL, NULL, NULL, NULL); }
//랜더 void Render(int timeDelta) { //화면 청소 if (SUCCEEDED(g_pDevice->Clear( 0, //청소할 영역의 D3DRECT 배열 갯수 ( 전체 클리어 0 ) NULL, //청소할 영역의 D3DRECT 배열 포인터 ( 전체 클리어 NULL ) D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, //청소될 버퍼 플레그 ( D3DCLEAR_TARGET 컬러버퍼, D3DCLEAR_ZBUFFER 깊이버퍼, D3DCLEAR_STENCIL 스텐실버퍼 D3DCOLOR_XRGB(0,0,0), //컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB ) 1.0f, //깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 ) 0 //스텐실 버퍼를 채울값 ))) { //화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작 g_pDevice->BeginScene(); //r.SetTranslate(Vector3(0, 0, -498)); // teapot g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&g_LocalTm); g_pDevice->SetMaterial(&g_Mtrl); if (g_Mesh) g_Mesh->DrawSubset(0); //랜더링 끝 g_pDevice->EndScene(); //랜더링이 끝났으면 랜더링된 내용 화면으로 전송 g_pDevice->Present( NULL, NULL, NULL, NULL ); } }
//----------------------------------------------------------------------------- // Name: Render() // Desc: Draws the scene //----------------------------------------------------------------------------- VOID Render() { // Clear the backbuffer and the zbuffer g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 0 ), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { // Setup the world, view, and projection matrices SetupMatrices(); SetupLights(); // Meshes are divided into subsets, one for each material. Render them in // a loop for( DWORD i = 0; i < g_dwNumMaterials; i++ ) { // Set the material and texture for this subset g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); // Draw the mesh subset g_pMesh->DrawSubset( i ); } D3DXMATRIXA16 mat; D3DXMatrixTranslation( &mat, 1,0,0 ); g_pd3dDevice->SetTransform( D3DTS_WORLD, &mat ); for( DWORD i = 0; i < g_dwNumMaterials2; i++ ) { // Set the material and texture for this subset g_pd3dDevice->SetMaterial( &g_pMeshMaterials2[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures2[i] ); // Draw the mesh subset g_pMesh->DrawSubset( i ); } // End the scene g_pd3dDevice->EndScene(); } LPDIRECT3DTEXTURE9* pTemp = g_pMeshTextures; g_pMeshTextures = g_pMeshTextures2; g_pMeshTextures2 = pTemp; // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
// 3D 물체등을 그린다. void RenderScene() { // 뷰 행렬을 만든다. D3DXMATRIXA16 matView; D3DXVECTOR3 vEyePt(gWorldCameraPosition.x, gWorldCameraPosition.y, gWorldCameraPosition.z); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); // 투영행렬을 만든다. D3DXMATRIXA16 matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, FOV, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // 프레임마다 0.4도씩 회전을 시킨다. gRotationY += 0.4f * PI / 180.0f; if (gRotationY > 2 * PI) { gRotationY -= 2 * PI; } // 월드행렬을 만든다. D3DXMATRIXA16 matWorld; D3DXMatrixRotationY(&matWorld, gRotationY); // 월드/뷰/투영행렬을 미리 곱한다. D3DXMATRIXA16 matWorldView; D3DXMATRIXA16 matWorldViewProjection; D3DXMatrixMultiply(&matWorldView, &matWorld, &matView); D3DXMatrixMultiply(&matWorldViewProjection, &matWorldView, &matProjection); // 쉐이더 전역변수들을 설정 gpEnvironmentMappingShader->SetMatrix("gWorldMatrix", &matWorld); gpEnvironmentMappingShader->SetMatrix("gWorldViewProjectionMatrix", &matWorldViewProjection); gpEnvironmentMappingShader->SetVector("gWorldLightPosition", &gWorldLightPosition); gpEnvironmentMappingShader->SetVector("gWorldCameraPosition", &gWorldCameraPosition); gpEnvironmentMappingShader->SetVector("gLightColor", &gLightColor); gpEnvironmentMappingShader->SetTexture("DiffuseMap_Tex", gpStoneDM); gpEnvironmentMappingShader->SetTexture("SpecularMap_Tex", gpStoneSM); gpEnvironmentMappingShader->SetTexture("NormalMap_Tex", gpStoneNM); gpEnvironmentMappingShader->SetTexture("EnvironmentMap_Tex", gpSnowENV); // 쉐이더를 시작한다. UINT numPasses = 0; gpEnvironmentMappingShader->Begin(&numPasses, NULL); { for (UINT i = 0; i < numPasses; ++i) { gpEnvironmentMappingShader->BeginPass(i); { // 구체를 그린다. gpTeapot->DrawSubset(0); } gpEnvironmentMappingShader->EndPass(); } } gpEnvironmentMappingShader->End(); }
/* ================ */ virtual void commit () { if (m_map_kd != NULL) m_device->SetTexture(0, m_map_kd->obj.base); else m_device->SetTexture(0, NULL); m_device->SetMaterial(m_mtl); m_msh->DrawSubset(m_idx); }
//Add your objects here. void CALLBACK RenderFunc(void) { /** * Show GPU info on TOP|LEFT . */ WCHAR TempName[60] = L"GPU Info:"; WCHAR adapterName[30]{0}; D3DADAPTER_IDENTIFIER9 Adapter; LPDIRECT3D9 pD3D = NULL; if (NULL == (pD3D = Direct3DCreate9(D3D_SDK_VERSION))) { return; } pD3D->GetAdapterIdentifier(0, 0, &Adapter); int len = ::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, NULL, 0); ::MultiByteToWideChar(CP_ACP, 0, Adapter.Description, -1, adapterName, len); wcscat_s(TempName, adapterName); pD3D->Release(); gPFont->DrawText(nullptr, TempName, -1, nullptr, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(124, 24, 222)); /** * Set camera and view here. */ D3DMATRIX* pMatView = nullptr; GD::CMatrix44<float> viewMat(gEnv.m_pCamera->GetViewMatrixDX()); pMatView = (D3DMATRIX*)(&viewMat); gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_VIEW, pMatView); //应用取景变换矩阵 D3DMATRIX* pProjMatrix; pProjMatrix = (D3DMATRIX*)(&gEnv.m_pCamera->GetProjMatrix().GetFliped()); gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_PROJECTION, pProjMatrix); //设置投影变换矩阵 D3DVIEWPORT9* pViewPort; pViewPort = (D3DVIEWPORT9*)(&gEnv.m_pCamera->GetViewPort()); gEnv.m_pDXDevice->GetD3DDevice()->SetViewport(pViewPort); //视口的设置 /** * Draw terrain here. */ Matrix I; I.Identity(); gEnv.m_pTerrain->Draw(I, false); /** * Draw objects in scene here. */ D3DXMATRIX W; D3DXMatrixIdentity(&W); gEnv.m_pDXDevice->GetD3DDevice()->SetTransform(D3DTS_WORLD, &W); D3DMATERIAL9 mtrl; mtrl.Ambient = D3DCOLOR_WHITE; mtrl.Diffuse = D3DCOLOR_WHITE; mtrl.Emissive = D3DCOLOR_RED; mtrl.Specular = D3DCOLOR_PUREGREEN; mtrl.Power = 2.0f; gEnv.m_pDXDevice->GetD3DDevice()->SetMaterial(&mtrl); gPMesh->DrawSubset(0); }
//************************************************************************** //3D描画にとって核となる関数関連 //************************************************************************** //メッシュサブセットを描画 void Dx_Graphics3D::DrawSubset(LPD3DXMESH lpMesh,DWORD AttribId,D3DMATERIAL9 *pMat,LPDIRECT3DTEXTURE9 pTex) { //デバイスにマテリアルプロパティを設定 this->device->SetMaterial(pMat); //デバイスのステージにテクスチャを割り当てる this->device->SetTexture(0,pTex); //メッシュサブセットの属性IDを指定して描画 lpMesh->DrawSubset(AttribId); }
VOID ALPHA::draw(LPD3DXMESH mesh,LPDIRECT3DTEXTURE9* textures,INT n) //绘制 { _device->SetRenderState(D3DRS_ALPHABLENDENABLE,true); //打开Alpha融合 for(int i = 0;i < n;i++) { _device->SetTexture(0,textures[i]); mesh->DrawSubset(i); } _device->SetRenderState(D3DRS_ALPHABLENDENABLE,false); //关闭Alpha融合 }
void Direct3DRender(HWND hwnd) { gPD3DDevice->Clear(0, nullptr, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); gPD3DDevice->BeginScene(); InputUpdate(); MatrixSet(); RECT formatRect; GetClientRect(hwnd, &formatRect); for (int i = 0; i < gDwNumMtrl; i++) { gPD3DDevice->SetMaterial(&gPMaterial[i]); gPD3DDevice->SetTexture(0, gPTexture[i]); gPCharacter->DrawSubset(i); } int strLen = swprintf_s(gStrFPS, _T("FPS: %f"), 123.45f); gPTextFPSFont->DrawTextW(nullptr, gStrFPS, strLen, &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_XRGB(0, 239, 136)); strLen = sizeof(gStrAdapterDesc); gPTextAdapterFont->DrawTextW(nullptr, gStrAdapterDesc, -1, &formatRect, DT_TOP | DT_LEFT, D3DCOLOR_XRGB(23, 23, 236)); formatRect.top = 30; static wchar_t strInfo[256] = { 0 }; swprintf_s(strInfo, -1, L"模型坐标: (%.2f, %.2f, %.2f)", gMatWorld._41, gMatWorld._42, gMatWorld._43); gPTextHelperFont->DrawText(NULL, strInfo, -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(135, 239, 136, 255)); formatRect.top = WINDOW_HEIGHT * 2 / 3; gPTextInfoFont->DrawTextW(nullptr, _T("控制说明:"), -1, &formatRect, DT_NOCLIP|DT_LEFT | DT_SINGLELINE, D3DCOLOR_XRGB(23, 25, 111)); formatRect.top += 35; formatRect.left += 50; gPTextHelperFont->DrawText(NULL, L"按住鼠标左键并拖动:平移模型", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); formatRect.top += 25; gPTextHelperFont->DrawText(NULL, L"按住鼠标右键并拖动:旋转模型", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); formatRect.top += 25; gPTextHelperFont->DrawText(NULL, L"滑动鼠标滚轮:拉伸模型", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); formatRect.top += 25; gPTextHelperFont->DrawText(NULL, L"W、S、A、D键:平移模型 ", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); formatRect.top += 25; gPTextHelperFont->DrawText(NULL, L"上、下、左、右方向键:旋转模型 ", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); formatRect.top += 25; gPTextHelperFont->DrawText(NULL, L"ESC键 : 退出程序", -1, &formatRect, DT_SINGLELINE | DT_NOCLIP | DT_LEFT, D3DCOLOR_RGBA(255, 200, 0, 255)); gPD3DDevice->EndScene(); gPD3DDevice->Present(nullptr, nullptr, nullptr, nullptr); }
// 3D 물체등을 그린다. void RenderScene() { // 뷰행렬 초기화. D3DXMATRIXA16 matView; // D3DXVECTOR3 vEyePt(0.0f, 0.0f, -200.0f); D3DXVECTOR3 vEyePt(gWorldCameraPosition.x, gWorldCameraPosition.y, gWorldCameraPosition.z); D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec); // 투영행렬 초기화. D3DXMATRIXA16 matProjection; D3DXMatrixPerspectiveFovLH(&matProjection, FOV, ASPECT_RATIO, NEAR_PLANE, FAR_PLANE); // 회전. gRotationY += ((0.4f * PI) / 180.0f); if (gRotationY > 2 * PI) gRotationY -= 2 * PI; // 월드행렬 초기화. D3DXMATRIXA16 matWorld; // D3DXMatrixIdentity(&matWorld); D3DXMatrixRotationY(&matWorld, gRotationY); // 쉐이더에 전달. gpTextureMappingShader->SetMatrix("gWorldMatrix", &matWorld); gpTextureMappingShader->SetMatrix("gViewMatrix", &matView); gpTextureMappingShader->SetMatrix("gProjectionMatrix", &matProjection); gpTextureMappingShader->SetVector("gWorldLightPosition", &gWorldLightPosition); gpTextureMappingShader->SetVector("gWorldCameraPosition", &gWorldCameraPosition); // gpTextureMappingShader->SetTexture("DiffuseMap_Tex", gpEarthDM); // 쉐이더 적용. UINT numPasses = 0; gpTextureMappingShader->Begin(&numPasses, NULL); for (UINT i = 0; i < numPasses; ++i) { gpTextureMappingShader->BeginPass(i); gpSphere->DrawSubset(0); gpTextureMappingShader->EndPass(); } gpTextureMappingShader->End(); }
VOID Render( ) { RECT rt1, rt2; D3DXMATRIX matWorld, matScale, matRotateZ, matTrans; g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if ( SUCCEEDED( g_pD3DDevice->BeginScene( ) ) ) { SetupMatrices( ); SetRect( &rt1, 10, 10, 0, 0 ); if (!g_Method) { g_pFont->DrawTextW( NULL, L"AABB 충돌(left click으로 방법 변경)", -1, &rt1, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) ); } else { g_pFont->DrawTextW( NULL, L"OBB 충돌(left click으로 방법 변경)", -1, &rt1, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) ); } g_pD3DDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_WIREFRAME ); for ( DWORD i = 0; i < sizeof( g_Box ) / sizeof( g_Box[1] ); ++i ) { D3DXMatrixTranslation( &matTrans, g_Box[i].CenterPos.x, g_Box[i].CenterPos.y, g_Box[i].CenterPos.z ); D3DXMatrixScaling( &matScale, g_Box[i].BoxScaling, g_Box[i].BoxScaling, g_Box[i].BoxScaling ); D3DXMatrixRotationZ( &matRotateZ, g_Box[i].BoxRotateZ ); matWorld = matRotateZ * matScale * matTrans; g_pD3DDevice->SetTransform( D3DTS_WORLD, &matWorld ); g_pMesh->DrawSubset( 0 ); } SetRect( &rt2, 10, 30, 0, 0 ); if ( g_CheckFlag ) { g_pFont->DrawTextW( NULL, L"박았음!!", -1, &rt2, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) ); } else { g_pFont->DrawTextW( NULL, L"아직 멀었음!!", -1, &rt2, DT_NOCLIP, D3DXCOLOR( 1.f, 1.f, 0.f, 1.f ) ); } g_pD3DDevice->EndScene( ); } g_pD3DDevice->Present( NULL, NULL, NULL, NULL ); }
//----------------------------------------------------------------------------- // Name: render_0() // Desc: //----------------------------------------------------------------------------- void render_0( void ) { D3DXMATRIX matView; D3DXMATRIX matWorld; D3DXMATRIX matRotation; D3DXMATRIX matTranslation; static int nFrameCount = 0; static double nTimeOfLastFPSUpdate = 0.0; static char fpsString[50] = "Frames Per Second = "; RECT destRect; // Now we can clear just view-port's portion of the buffer to red... g_pd3dDevice_0->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_COLORVALUE( 1.0f, 0.0f, 0.0f, 1.0f ), 1.0f, 0 ); g_pd3dDevice_0->BeginScene(); // For the left view-port, leave the view at the origin... D3DXMatrixIdentity( &matView ); g_pd3dDevice_0->SetTransform( D3DTS_VIEW, &matView ); // ... and use the world matrix to spin and translate the teapot // out where we can see it... D3DXMatrixRotationYawPitchRoll( &matRotation, D3DXToRadian(g_fSpinX), D3DXToRadian(g_fSpinY), 0.0f ); D3DXMatrixTranslation( &matTranslation, 0.0f, 0.0f, 5.0f ); matWorld = matRotation * matTranslation; g_pd3dDevice_0->SetTransform( D3DTS_WORLD, &matWorld ); g_pd3dDevice_0->SetMaterial( &g_teapotMtrl ); g_pTeapotMesh_0->DrawSubset(0); g_pd3dDevice_0->EndScene(); // Report frames per second and the number of objects culled... ++nFrameCount; if( g_dElpasedAppTime - nTimeOfLastFPSUpdate > 1000 ) // Update once a second { sprintf( fpsString, "Frames Per Second = %4.2f", nFrameCount*1000.0/(g_dElpasedAppTime - nTimeOfLastFPSUpdate) ); nTimeOfLastFPSUpdate = g_dElpasedAppTime; nFrameCount = 0; } SetRect( &destRect, 5, 5, 0, 0 ); g_pd3dxFont->DrawText( NULL, fpsString, -1, &destRect, DT_NOCLIP, D3DXCOLOR( 1.0f, 1.0f, 1.0f, 1.0f ) ); g_pd3dDevice_0->Present( NULL, NULL, NULL, NULL ); }
void Renderer::DrawMesh( LPD3DXMESH pMesh ) { if ( pMesh == NULL ) { return; } UVNormalEnvVertexShader* pShader = &UVNormalEnvVertexShader::StaticType; CommitTransforms( pShader ); CommitTextureState(); m_pD3DDevice->SetVertexShader( pShader->GetVertexShader() ); m_pD3DDevice->SetVertexDeclaration( g_pPosNormalDeclaration ); pMesh->DrawSubset( 0 ); }
VOID Render() { if ( NULL == g_pd3dDevice ) { return; } g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 30, 10, 10 ), 1.0f, 0 ); if ( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { SetupLights(); SetupMatrices(); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); g_pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); D3DXMATRIXA16 thisMatrix; D3DXMatrixTranslation( &thisMatrix, 0.0f, -10.0f, 30.0f ); g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix ); D3DXMatrixRotationY( &thisMatrix, timeGetTime() / 1000.0f ); g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix ); D3DXMatrixScaling( &thisMatrix, 1.0f, 1.2f, 1.0f ); g_pd3dDevice->MultiplyTransform( D3DTS_WORLD, &thisMatrix ); for ( DWORD i = 0; i < g_dwNumMaterials; ++i ) { g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] ); g_pd3dDevice->SetTexture( 0, g_pMeshTextures[i] ); g_pMesh->DrawSubset( i ); } g_pd3dDevice->EndScene(); } g_pd3dDevice->Present( NULL, NULL, NULL, NULL ); }
VOID Render() { if ( !g_pd3dDevice ) return; LPDIRECT3DDEVICE9 d = g_pd3dDevice; d->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,255), 1.0f, 0 ); if ( SUCCEEDED( d->BeginScene() )) { SetupMatrices(); for (int i = 0; i< g_materialNums; ++i) { d->SetMaterial( &g_pMeshMaterials[i] ); d->SetTexture( 0, g_pMeshTextures[i] ); g_pMesh->DrawSubset( i ); } d->EndScene(); } d->Present( NULL, NULL, NULL, NULL ); }
//************************************************************************************************************* void DrawScene(LPD3DXEFFECT effect) { D3DXMATRIX world; D3DXMATRIX inv; D3DXVECTOR4 uv(3, 3, 0, 0); D3DXMatrixScaling(&world, 5, 0.1f, 5); D3DXMatrixInverse(&inv, NULL, &world); effect->SetMatrix("matWorld", &world); effect->SetMatrix("matWorldInv", &inv); effect->SetVector("uv", &uv); effect->Begin(0, 0); effect->BeginPass(0); { device->SetTexture(0, texture2); shadowreceiver->DrawSubset(0); if( !drawsilhouette ) { device->SetTexture(0, texture1); uv.x = uv.y = 1; effect->SetVector("uv", &uv); for( int i = 0; i < NUM_OBJECTS; ++i ) { D3DXMatrixInverse(&inv, NULL, &objects[i].world); effect->SetMatrix("matWorld", &objects[i].world); effect->SetMatrix("matWorldInv", &inv); effect->CommitChanges(); objects[i].object->DrawSubset(0); } } } effect->EndPass(); effect->End(); }
/** * \brief Called to render a mesh * \param device - the Direct3D device object * \param meshContainerBase - the mesh container * \param frameBase - frame containing the mesh * \author Keith Ditchburn \date 18 July 2005 */ void SkinnedData::DrawMeshContainer(LPD3DXMESHCONTAINER meshContainerBase, LPD3DXFRAME frameBase) const { // Cast to our extended frame type D3DXFRAME_EXTENDED *frame = (D3DXFRAME_EXTENDED*)frameBase; // Cast to our extended mesh container D3DXMESHCONTAINER_EXTENDED *meshContainer = (D3DXMESHCONTAINER_EXTENDED*)meshContainerBase; // Set the world transform d3dDevice->SetTransform(D3DTS_WORLD, &frame->exCombinedTransformationMatrix); // Loop through all the materials in the mesh rendering each subset for (unsigned int iMaterial = 0; iMaterial < meshContainer->NumMaterials; iMaterial++) { // Select the mesh to draw, if there is skin then use the skinned mesh else the normal one LPD3DXMESH pDrawMesh = (meshContainer->pSkinInfo) ? meshContainer->exSkinMesh: meshContainer->MeshData.pMesh; // Finally Call the mesh draw function pDrawMesh->DrawSubset(iMaterial); } }
VOID render(){ g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(192, 192, 192), 1.0f, 0); if(SUCCEEDED(g_pDevice->BeginScene())){ setWorldMatrix(); for(DWORD i=0; i<g_dwNumMaterials; ++i){ g_pDevice->SetMaterial(&g_pMeshMaterials[i]); g_pDevice->SetTexture(0, g_pMeshTextures[i]); g_pMesh->DrawSubset(i); } g_pDevice->EndScene(); } g_pDevice->Present(NULL, NULL, NULL, NULL); }
VOID Render() { g_pD3DDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 0, 0, 255 ), 1.0f, 0 ); if ( SUCCEEDED( g_pD3DDevice->BeginScene() ) ) { SetupLights(); SetupMatrices(); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); g_pD3DDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); //soldier D3DXMATRIXA16 matFirstTiger, matTrans, matRotate; //D3DXMatrixIdentity(&matFirstTiger); //g_pD3DDevice->GetTransform(D3DTS_WORLD, &matFirstTiger); D3DXMatrixTranslation( &matTrans, 0.f, -2.f, 0.f ); D3DXMatrixRotationY( &matRotate, timeGetTime() / 1000.0f ); D3DXMatrixMultiply( &matFirstTiger, &matRotate, &matTrans ); g_pD3DDevice->SetTransform( D3DTS_WORLD, &matFirstTiger ); for ( DWORD i = 0; i < g_dwNumMaterials; ++i ) { g_pD3DDevice->SetMaterial( &g_pMeshMaterials0[i] ); g_pD3DDevice->SetTexture( 0, g_pMeshTextures0[i] ); g_pMesh0->DrawSubset( i ); } g_pD3DDevice->EndScene(); } g_pD3DDevice->Present( NULL, NULL, NULL, NULL ); g_tick++; }