void Direct3DUpdate(HWND hwnd) { ////////////////////////////////////////////////////////////////////////// // Five steps of rendering: clear, beginScene, render, EndScene, present ////////////////////////////////////////////////////////////////////////// gPD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0); RECT formatRect; GetClientRect(hwnd, &formatRect); gPD3DDevice->BeginScene(); gPD3DDevice->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD); gPD3DDevice->SetStreamSource(0, gPVertexBuffer, 0, sizeof(CUSTOM_VERTEX)); gPD3DDevice->SetFVF(D3DFVF_CUSTOM_VERTEX); gPD3DDevice->SetIndices(gPIndexBuffer); gPD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 17, 0, 16); int charCount = swprintf_s(gStrFPS, 20, _T("FPS:%0.3f"), GetFPS()); gPFont->DrawText(NULL, gStrFPS, charCount, &formatRect, DT_TOP | DT_RIGHT, D3DCOLOR_XRGB(255, 39, 136)); gPD3DDevice->EndScene(); gPD3DDevice->Present(nullptr, nullptr, nullptr, nullptr); }
// Render the model using the given matrix list as a hierarchy (must be one matrix per node) // and from the given camera void CMesh::Render( CMatrix4x4* matrices, CCamera* camera ) { if (m_HasGeometry) { for (TUInt32 subMesh = 0; subMesh < m_NumSubMeshes; ++subMesh) { // Get a reference to the submesh and its material to reduce code clutter SSubMeshDX& sub = m_SubMeshesDX[subMesh]; SMeshMaterialDX& material = m_Materials[sub.material]; // Set textures from the material for (TUInt32 texture = 0; texture < material.numTextures; ++texture) { g_pd3dDevice->SetTexture( texture, material.textures[texture] ); } // Set material properties SetMaterialColour( material.diffuseColour, material.specularColour, material.specularPower ); // Use the render method from the sub-mesh's material and the matrix from its node UseMethod( material.renderMethod, &matrices[sub.node], camera ); // Tell DirectX the vertex and index buffers to use g_pd3dDevice->SetStreamSource( 0, sub.vertexBuffer, 0, sub.vertexSize ); g_pd3dDevice->SetIndices( sub.indexBuffer ); // Draw the primitives from the buffer - a triangle list g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, sub.numVertices, 0, sub.numIndices / 3 ); } } }
//------------------------------------------------------------- // Trigger the render of indexed primitives //------------------------------------------------------------- void VCND3D9Shader::RenderIndexedPrimitive( VCNUInt faceCount, VCNUInt vertexCount, VCNInt primitiveType /*= D3DPT_TRIANGLELIST*/ ) { HRESULT hr = S_FALSE; // Get a pointer to the D3D device LPDIRECT3DDEVICE9 device = GetD3DDevice(); // Start the technique and commit all the data VCNUInt numPasses; hr = mShader->Begin( &numPasses, 0 ); VCN_ASSERT( SUCCEEDED(hr) ); // Render all the passes of this technique (generally only 1). for( VCNUInt i=0; i<numPasses; ++i ) { // Start the pass hr = mShader->BeginPass( i ); VCN_ASSERT( SUCCEEDED(hr) ); // Render indexed primitives hr = device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primitiveType, 0, 0, vertexCount, 0, faceCount ); VCN_ASSERT( hr != D3DERR_INVALIDCALL && "VCNDXShader::RenderIndexedPrimitive - D3DERR_INVALIDCALL!" ); VCN_ASSERT( SUCCEEDED(hr) && "VCNDXShader::RenderIndexedPrimitive - DRAW FAILED!" ); // End the pass hr = mShader->EndPass(); VCN_ASSERT( SUCCEEDED(hr) ); } hr = mShader->End(); VCN_ASSERT( SUCCEEDED(hr) ); }
void render_submodel( LPDIRECT3DDEVICE9 device, SubModel& submodel ) { if( submodel.texture ) { device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 ); device->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_SELECTARG1 ); device->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE ); device->SetTextureStageState( 1, D3DTSS_COLOROP, D3DTOP_DISABLE ); device->SetTextureStageState( 1, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); device->SetTexture( 0, submodel.texture->texture ); } else { device->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_DISABLE ); device->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE ); device->SetTexture( 0, NULL ); } device->SetIndices( submodel.ib ); device->SetStreamSource( 0, submodel.vb, 0, sizeof(model_vertex_type) ); device->SetFVF( model_vertex_type::format ); device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, submodel.index_source.size(), 0, submodel.index_source.size() / 3 ); }
/**----------------------------------------------------------------------------- * 메시 그리기 *------------------------------------------------------------------------------ */ void DrawMesh( D3DXMATRIXA16* pMat ) { g_pd3dDevice->SetTransform( D3DTS_WORLD, pMat ); g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->SetIndices( g_pIB ); g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_cxHeight*g_czHeight, 0, (g_cxHeight-1)*(g_czHeight-1)*2 ); }
/**----------------------------------------------------------------------------- * 메시 그리기 *------------------------------------------------------------------------------ */ void DrawMesh( D3DXMATRIXA16* pMat ) { g_pd3dDevice->SetRenderState( D3DRS_FILLMODE, g_bWireframe ? D3DFILL_WIREFRAME : D3DFILL_SOLID ); g_pd3dDevice->SetTransform( D3DTS_WORLD, pMat ); g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ); g_pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ); g_pd3dDevice->SetIndices( g_pIB ); g_pd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_cxHeight*g_czHeight, 0, g_nTriangles ); }
//************************************************************************************************************* void DrawShadowVolume(const ShadowCaster& caster) { extrude->SetMatrix("matWorld", &caster.world); extrude->CommitChanges(); device->SetVertexDeclaration(shadowdecl); device->SetStreamSource(0, caster.vertices, 0, sizeof(D3DXVECTOR4)); device->SetIndices(caster.indices); device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, caster.numvertices, 0, caster.numfaces); }
void DrawCube() { // translate model to origin D3DXMATRIX world ; D3DXMatrixTranslation(&world, 0.0f, 0.0f, 0.0f) ; g_pd3dDevice->SetTransform(D3DTS_WORLD, &world) ; // set view D3DXVECTOR3 eyePt(5.0f, 5.0f, -5.0f) ; D3DXVECTOR3 upVec(0.0f, 1.0f, 0.0f) ; D3DXVECTOR3 lookCenter(0.0f, 0.0f, 0.0f) ; D3DXMATRIX view ; D3DXMatrixLookAtLH(&view, &eyePt, &lookCenter, &upVec) ; g_pd3dDevice->SetTransform(D3DTS_VIEW, &view) ; // set projection D3DXMATRIX proj ; D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI / 4, 1.0f, 1.0f, 1000.0f) ; g_pd3dDevice->SetTransform(D3DTS_PROJECTION, &proj) ; D3DXMATRIX worldviewproj = world * view * proj; // Set matrix g_pEffect->SetMatrix(g_hWVP, &worldviewproj); // Set technique g_pEffect->SetTechnique(g_hTech); // Render pass UINT numPass = 0; g_pEffect->Begin(&numPass, 0); g_pEffect->BeginPass(0); // Set texture D3DXCreateTextureFromFile(g_pd3dDevice, "../Common/Media/crate.jpg", &g_pCubeTexture) ; g_pEffect->SetTexture("g_pCubeTexture", g_pCubeTexture); /*g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);*/ // Set stream source, and index buffer g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(Vertex) ); g_pd3dDevice->SetIndices(g_pIB) ; g_pd3dDevice->SetFVF(VERTEX_FVF) ; // Totally 24 points and 12 triangles g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12) ; g_pEffect->EndPass(); g_pEffect->End(); }
HRESULT HookIDirect3DDevice9::DrawIndexedPrimitive(LPVOID _this, D3DPRIMITIVETYPE PrimitiveType, INT BaseVertexIndex, UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount) { LOG_API(); return pD3Dev->DrawIndexedPrimitive(PrimitiveType, BaseVertexIndex, MinVertexIndex, NumVertices, startIndex, primCount); }
void cSubDivSurf::Draw( matrix4& mat ) { LPDIRECT3DDEVICE9 lpDevice = Graphics()->GetDevice(); Graphics()->SetWorldMatrix( mat ); HRESULT hr; // The index buffer LPDIRECT3DINDEXBUFFER9 pIndexBuffer = 0; // Create the index buffer lpDevice->CreateIndexBuffer( m_nTris * 3 * sizeof( WORD ), // Size in bytes of buffer D3DUSAGE_WRITEONLY, // Will only be writing to the buffer D3DFMT_INDEX16, // 16 bit indices D3DPOOL_DEFAULT, // Default memory pooling &pIndexBuffer, // Address of the buffer pointer NULL ); // Reserved. set to NULL // Pointer to the index buffer data WORD* pData = 0; // Lock the index buffer pIndexBuffer->Lock( 0, 0, (void**)&pData, 0 ); // Copy the index data into the index buffer CopyMemory( pData, m_d3dTriList, m_nTris * 3 * sizeof( WORD ) ); // Unlock the index buffer pIndexBuffer->Unlock(); // Tell Direct3D to use the index buffer lpDevice->SetIndices( pIndexBuffer ); // Attach the vertex buffer to rendering stream 0 lpDevice->SetStreamSource( 0, m_pVertexBuffer, 0, sizeof( sVertex ) ); // Draw the primitive hr = lpDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_nVerts, 0, m_nTris ); if( FAILED( hr ) ) { DP0("[cSubDivSurf::Draw]: DrawIndexedPrimitive failed!\n"); } pIndexBuffer->Release(); }
//랜더 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(255, 255, 255), //컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB ) 1.0f, //깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 ) 0 //스텐실 버퍼를 채울값 ))) { //화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작 g_pDevice->BeginScene(); Matrix44 mR; if (g_ani) { g_alpha += timeDelta / 1000.f; if (g_alpha > 1) { g_alpha = 1; g_ani = false; } } Vector3 v = g_from.Interpolate(g_to, g_alpha); Quaternion quat(Vector3(0,1,0), v); mR = quat.GetMatrix(); Matrix44 tm = mR * g_LocalTm; g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&tm); g_pDevice->SetTexture(0, g_Texture); g_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); g_pDevice->SetMaterial(&g_Mtrl); g_pDevice->SetStreamSource( 0, g_pVB, 0, sizeof(Vertex) ); g_pDevice->SetIndices(g_pIB); g_pDevice->SetFVF( Vertex::FVF ); g_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_VtxSize, 0, g_FaceSize); //랜더링 끝 g_pDevice->EndScene(); //랜더링이 끝났으면 랜더링된 내용 화면으로 전송 g_pDevice->Present( NULL, NULL, NULL, NULL ); } }
VOID render(){ g_pDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(192,192,192), 1.0f, 0); if(SUCCEEDED(g_pDevice->BeginScene())){ //Render to the back-buffer g_pDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX)); g_pDevice->SetFVF(D3DFVF_CUSTOMVERTEX); g_pDevice->SetIndices(g_pIB); g_pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0,0,9,0,8); g_pDevice->EndScene(); } g_pDevice->Present(NULL, NULL, NULL, NULL); }
//------------------------------------------------- // Name: Render // Desc: //------------------------------------------------- HRESULT cprimitive::Render(LPDIRECT3DDEVICE9 pd3dDevice) { HRESULT hr; W( pd3dDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ) ); W( pd3dDevice->SetIndices(g_pIB) ); W( pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(CUSTOMVERTEX) ) ); W( pd3dDevice->SetFVF( D3DFVF_CUSTOMVERTEX ) ); W( pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, m_numVertices, 0, m_numIndices/3) ); return S_OK; }
void ModelMesh::Render( LPDIRECT3DDEVICE9 device ) { if( !IsLoaded() ) return; device->SetRenderState( D3DRS_FILLMODE, m_d3d_fillmode); device->SetRenderState( D3DRS_CULLMODE, m_d3d_cullmode ); device->SetStreamSource( 0, m_vb, 0, sizeof(ModelVertexStruct) ); device->SetFVF( ModelVertexStruct::FVF ); device->SetIndices( m_ib ); device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_vertex_size, 0, m_index_size / 3 ); }
//랜더 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(150, 150, 150), //컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB ) 1.0f, //깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 ) 0 //스텐실 버퍼를 채울값 ))) { //화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작 g_pDevice->BeginScene(); g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&global->localTm); g_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); g_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSU, global->addressMode) ; g_pDevice->SetSamplerState(0, D3DSAMP_ADDRESSV, global->addressMode) ; g_pDevice->SetMaterial(&global->mtrl); g_pDevice->SetTexture(0, global->texture); g_pDevice->SetStreamSource( 0, global->vb, 0, sizeof(Vertex) ); g_pDevice->SetIndices(global->ib); g_pDevice->SetFVF( Vertex::FVF ); g_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, global->vtxSize, 0, global->faceSize); switch (global->mode) { case sGlobal::RENDER_FACE_NORMAL: g_pDevice->SetStreamSource( 0, global->fnvb, 0, sizeof(Vertex) ); g_pDevice->DrawPrimitive( D3DPT_LINELIST, 0, global->faceNormalVtxSize/2); break; case sGlobal::RENDER_VERTEX_NORMAL: g_pDevice->SetStreamSource( 0, global->vnvb, 0, sizeof(Vertex) ); g_pDevice->DrawPrimitive( D3DPT_LINELIST, 0, global->vertexNormalVtxSize/2); break; } //랜더링 끝 g_pDevice->EndScene(); //랜더링이 끝났으면 랜더링된 내용 화면으로 전송 g_pDevice->Present( NULL, NULL, NULL, NULL ); } }
void VCND3D9Shader::RenderIndexedPrimitive( VCNPrimitiveType primitiveType, VCNInt baseVertexIndex, VCNUInt minVertexIndex, VCNUInt numVertices, VCNUInt startIndex, VCNUInt primCount) { HRESULT hr = S_FALSE; // Get a pointer to the D3D device LPDIRECT3DDEVICE9 device = GetD3DDevice(); // Render primitives hr = device->DrawIndexedPrimitive( (D3DPRIMITIVETYPE)primitiveType, baseVertexIndex, minVertexIndex, numVertices, startIndex, primCount); VCN_ASSERT( hr != D3DERR_INVALIDCALL && "VCNDXShader::RenderIndexedPrimitive - D3DERR_INVALIDCALL!" ); VCN_ASSERT( SUCCEEDED(hr) && "VCNDXShader::RenderIndexedPrimitive - DRAW FAILED!" ); }
void Draw( void ) override { HRESULT hr; LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device; hr = device->SetMaterial(&m_Material->mat); m_Material->tex->Set(); hr = device->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, m_Data->m_MaxVertex, m_Material->start_index, m_MaxPrimitive); }
void CTile::Render(LPDIRECT3DDEVICE9 _device) { _device->SetStreamSource( 0, m_pVB, 0, sizeof(TILEVERTEX) ); _device->SetFVF( D3DFVF_CUSTOMVERTEX ); _device->SetIndices( m_pIB ); if(_b == true){ _device->SetMaterial(&m_matrl); }else{ ZeroMemory(&m_matrl, sizeof(D3DMATERIAL9)); _device->SetMaterial(&m_matrl); } _device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 6, 0, 2); //_device->DrawPrimitive(D3DPT_TRIANGLELIST,0,2); }
//랜더 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(255, 255, 255), //컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB ) 1.0f, //깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 ) 0 //스텐실 버퍼를 채울값 ))) { //화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작 g_pDevice->BeginScene(); static float y = 0; y += timeDelta / 1000.f; // 각도가 2*PI 에 이르면 0으로 초기화한다. if (y >= 6.28f) y = 0; Matrix44 rx, ry, r; rx.SetRotationX(MATH_PI/4.f); // x축으로 45도 회전시킨다. ry.SetRotationY(y); // y축으로 회전 r = rx*ry; g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&r); Matrix44 rry; rry.SetRotationY(-y); // y축으로 회전 Vector3 dir = global->lightDir * rry; global->light.Direction = *(D3DXVECTOR3*)&dir; g_pDevice->SetLight(0, &global->light); // 광원 설정. g_pDevice->SetMaterial(&global->mtrl); g_pDevice->SetStreamSource( 0, global->vb, 0, sizeof(Vertex) ); g_pDevice->SetIndices(global->ib); g_pDevice->SetFVF( Vertex::FVF ); g_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, global->vtxSize, 0, global->faceSize); //랜더링 끝 g_pDevice->EndScene(); //랜더링이 끝났으면 랜더링된 내용 화면으로 전송 g_pDevice->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(); d->SetStreamSource( 0, g_pVertexBuff, 0, sizeof(CUSTOMVERTEX) ); d->SetFVF( D3DFVF_CUSTOMVERTEX ); d->SetIndices( g_pIndexBuff ); // 인덱스 버퍼 선택 d->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12 ); d->EndScene(); } d->Present( NULL, NULL, NULL, NULL ); }
// Draw cube void DrawCube() { // Set texture D3DXCreateTextureFromFile(g_pd3dDevice, "../Common/Media/crate.jpg", &g_pCubeTexture) ; g_pd3dDevice->SetTexture(0, g_pCubeTexture) ; g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pd3dDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR); // Set stream source, and index buffer g_pd3dDevice->SetStreamSource( 0, g_pVB, 0, sizeof(Vertex) ); g_pd3dDevice->SetIndices(g_pIB) ; g_pd3dDevice->SetFVF(VERTEX_FVF) ; // Totally 24 points and 12 triangles g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 24, 0, 12) ; }
//랜더 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(255, 255, 255), //컬러버퍼를 청소하고 채워질 색상( 0xAARRGGBB ) 1.0f, //깊이버퍼를 청소할값 ( 0 ~ 1 0 이 카메라에서 제일가까운 1 이 카메라에서 제일 먼 ) 0 //스텐실 버퍼를 채울값 ))) { //화면 청소가 성공적으로 이루어 졌다면... 랜더링 시작 g_pDevice->BeginScene(); static float y = 0; y += timeDelta / 1000.f; // 각도가 2*PI 에 이르면 0으로 초기화한다. if (y >= 6.28f) y = 0; //Matrix44 rx, ry, r; //rx.SetRotationX(MATH_PI/2.f); // x축으로 45도 회전시킨다. //ry.SetRotationY(y); // y축으로 회전 //r = rx*ry; //g_pDevice->SetTransform(D3DTS_WORLD, (D3DXMATRIX*)&r); g_pDevice->SetTexture(0, g_Texture1); g_pDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR); g_pDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT); g_pDevice->SetMaterial(&g_Mtrl); g_pDevice->SetStreamSource( 0, g_pVB, 0, sizeof(Vertex) ); g_pDevice->SetIndices(g_pIB); g_pDevice->SetFVF( Vertex::FVF ); g_pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, g_VtxSize, 0, g_FaceSize); //랜더링 끝 g_pDevice->EndScene(); //랜더링이 끝났으면 랜더링된 내용 화면으로 전송 g_pDevice->Present( NULL, NULL, NULL, NULL ); } }
bool si3::SealData::draw( LPDIRECT3DDEVICE9 device, const D3DXMATRIX & world_mat, LPDIRECT3DTEXTURE9 texture, IDirect3DVertexBuffer9 * vertbuff, IDirect3DIndexBuffer9 * indexbuff, int index_num, int triangle_num, const D3DMATERIAL9 & material) const { // 頂点フォーマット設定 device->SetFVF(LAND_FVF); //マテリアル設定 device->SetMaterial(&material); //テクスチャ設定 device->SetTexture(0, texture); device->SetStreamSource(0, vertbuff, 0, sizeof(DxTop2D)); device->SetIndices(indexbuff); // ライティング無し device->LightEnable(0, FALSE); device->SetRenderState(D3DRS_LIGHTING, FALSE); device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID); // プリミティブ描画 device->DrawIndexedPrimitive( D3DPT_TRIANGLESTRIP, 0, 0, index_num, 0, triangle_num); // ライティング有り device->LightEnable(0, TRUE); device->SetRenderState(D3DRS_LIGHTING, TRUE); return true; }
//---------------------------------------- //Name : DrawPrimitive() //DESC : 绘制顶点缓存中的图形 //---------------------------------------- void DrawPrimitive() { //设置渲染状态 g_pd3dDevice->SetRenderState(D3DRS_LIGHTING,false); g_pd3dDevice->SetRenderState(D3DRS_CULLMODE,D3DCULL_CCW); //渲染三角形 //需要通过IDirect3DDevice9接口的SetStreamSource方法将包含几何体信息的顶点缓存与渲染流水线相关联 /* HRESULT IDirect3DDevice9::SetStreamSource( UINT StreamNumber, //用于指定与该顶点缓存建立连接的数据流 IDirect3DVertexBuffer9 *pStreamData, //包含顶点数据的顶点缓存指针 UINT OffsetInBytes, //在数据流中以字节为单位的偏移量 UINT Stride //在顶点缓冲中存储的每个顶点结构的大小,可以通过sizeof运算符计算顶点结构的实际大小 ); */ //渲染三角形 g_pd3dDevice->SetStreamSource(0,g_pVertexBuf,0,sizeof(CUSTOMVERTEX)); //调用IDirect3DDevice9接口的SetFVF方法指定顶点格式 g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX); //将物体模型的顶点填充到顶点缓存,并设置数据流输入源和顶点格式后,可以调用IDirect3DDevice9接口的DrawPrimitive方法根据顶点缓存中的顶点绘制模型。 /* HRESULT IDirect3DDevice9::DrawPrimitive( D3DPRIMITIVETYPE PrimitiveType, UINT StartVertex, UINT PrimitiveCount ); */ //利用顶点缓存绘制矩形 //g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,2); //利用索引缓存绘制矩形 g_pd3dDevice->SetIndices(g_pIndexBuf); g_pd3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,8,0,12); }
void CGutModel_DX9::Render(int mask) { LPDIRECT3DDEVICE9 pDevice = GutGetGraphicsDeviceDX9(); bool bSubMtl = mask ? true : false; for ( int i=0; i<m_iNumMeshes; i++ ) { sModelMesh_DX9 *pMesh = m_pMeshArray + i; for ( int j=0; j<pMesh->m_iNumVertexChunks; j++ ) { sModelVertexChunk_DX9 *pVertexChunk = pMesh->m_pVertexChunk + j; pDevice->SetFVF(pVertexChunk->m_FVF); pDevice->SetStreamSource(0, pVertexChunk->m_pVertexBuffer, 0, pVertexChunk->m_iVertexSize); pDevice->SetIndices(pVertexChunk->m_pIndexBuffer); for (int l=0; l<pVertexChunk->m_iNumBatches; l++ ) { sModelBatch *pBatch = pVertexChunk->m_pBatchArray + l; if ( bSubMtl ) { if ( s_pMaterialOverwrite ) { s_pMaterialOverwrite->Submit(mask); } else if ( m_pMaterialArray ) { if ( pBatch->m_iMaterialID>=0 ) m_pMaterialArray[pBatch->m_iMaterialID].Submit(mask); else m_pMaterialArray[0].Submit(mask); } } pDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, pVertexChunk->m_iNumVertices, pBatch->m_iIndexArrayBegin, pBatch->m_iNumPrimitives); } } } }
VOID jcd3d::jcd3d_display(DWORD timeDelta) { if(lpd3dd != NULL) { static FLOAT eyeRadius = 6.0f; static FLOAT eyeDegree = 0.0f; static FLOAT eyeHeight = 0.0f; if(jcd3d_keyDown('A')) { eyeDegree += 0.05f; } if(jcd3d_keyDown('D')) { eyeDegree -= 0.05f; } if(jcd3d_keyDown('W')) { eyeHeight += 0.05f; } if(jcd3d_keyDown('S')) { eyeHeight -= 0.05f; } D3DXMATRIX view; D3DXVECTOR3 eye(cosf(eyeDegree) * eyeRadius, eyeHeight, sinf(eyeDegree) * eyeRadius); D3DXVECTOR3 target(0.0f, 0.0f, 0.0f); D3DXVECTOR3 up(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&view, &eye, &target, &up); lpd3dd->SetTransform(D3DTS_VIEW, &view); lpd3dd->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0); lpd3dd->BeginScene(); lpd3dd->SetStreamSource(0, lpvb, 0, sizeof(JCD3D_Vertex_xyz_diffuse)); lpd3dd->SetFVF(JCD3D_Vertex_xyz_diffuse::FVF); lpd3dd->SetIndices(lpib); lpd3dd->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, CORNOR_AMOUNT * (LAYER_AMOUNT + 1), 0, CORNOR_AMOUNT * 2 * LAYER_AMOUNT); lpd3dd->EndScene(); lpd3dd->Present(NULL, NULL, NULL, NULL); } }
void dbTerrain::Render() { if (dbDevice::canRender() != D3D_OK) return; LPDIRECT3DDEVICE9 dev = dbDevice::getDevice(); HRESULT hr; hr = dev->SetStreamSource(0, vertex_buffer_.GetVB(), 0, sizeof(TERRAIN_VERTEX)); hr = dev->SetIndices(index_buffer_.GetIB()); hr = dev->SetFVF(TERRAIN_VERTEX::FVF); dbDevice::SetRenderState( D3DRS_CULLMODE, D3DCULL_CW); // dbDevice::SetRenderState( D3DRS_LIGHTING, false ); if (FAILED( dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, max_vertex_, 0, max_index_ / 3))) DBX_ERROR("Could not render terrain!"); // dbDevice::SetRenderState( D3DRS_LIGHTING, true ); }
HRESULT Grid::VRender(Scene * pScene) { // This is slightly different from the Chapter 7 implementation... LPDIRECT3DDEVICE9 pDevice = pScene->m_pDevice; DWORD oldLightMode; pDevice->GetRenderState( D3DRS_LIGHTING, &oldLightMode ); pDevice->SetRenderState( D3DRS_LIGHTING, FALSE ); DWORD oldCullMode; pDevice->GetRenderState( D3DRS_CULLMODE, &oldCullMode ); pDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE ); // Setup our texture. Using textures introduces the texture stage states, // which govern how textures get blended together (in the case of multiple // textures) and lighting information. In this case, we are modulating // (blending) our texture with the diffuse color of the vertices. pDevice->SetTexture( 0, m_pTexture ); pDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE ); pDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE ); pDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE ); pDevice->SetStreamSource( 0, m_pVerts, 0, sizeof(COLORED_TEXTURED_VERTEX) ); pDevice->SetIndices(m_pIndices); pDevice->SetFVF( D3DFVF_COLORED_TEXTURED_VERTEX ); pDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST , 0, 0, m_numVerts, 0, m_numPolys ); // Notice that the render states are returned to // their original settings..... // Could there be a better way??? pDevice->SetTexture (0, NULL); pDevice->SetRenderState( D3DRS_LIGHTING, oldLightMode ); pDevice->SetRenderState( D3DRS_CULLMODE, oldCullMode ); return S_OK; }
bool CNO::Draw( LPDIRECT3DDEVICE9 dev) { CBranch::sIBNode *node; // set custom vertex dev->SetFVF( CUSTOM_BODY_VERTEX_FVF); // set vertex buffer dev->SetStreamSource( 0, m_bodyVertBuf, 0, sizeof( BODY_VERTEX)); // set index buffer dev->SetIndices( m_indexBuffer); // go through all active levels and their drawing chain and draw. for( int i= 0; i < this->GetNumOfActiveLvls( ); i++) { CBranch *curr = this->GetLevelHeads( i)->GetChainPointers( )->NextInBodyDraw; while( curr) { // set model matrix dev->SetTransform( D3DTS_WORLD, &curr->GetWorldMatrix( ) ); // draw the branch node = curr->GetBodyNode( ); if( D3D_OK != dev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST , node->pToVert , 0 , node->count , node->pToIndx , ( node->count - NUM_OF_VERT_ON) * 2 ) ) return false; // step to next curr = curr->GetChainPointers( )->NextInBodyDraw; } } return true; }
//描画 void Vertices::Draw(LPDIRECT3DDEVICE9 pD3DDevice, D3DXMATRIX *pmtrx) { if (!pD3DDevice || !pVertexBuffer) return; D3DXMATRIX mtrxOld; //ワールド変換行列保存用 pD3DDevice->GetTransform(D3DTS_WORLD, &mtrxOld); //ワールド行列を保存 pD3DDevice->SetTransform(D3DTS_WORLD, pmtrx); //デバイスにマトリックスを設定 pD3DDevice->SetStreamSource(0, pVertexBuffer, 0, sizeof(D3DVERTEX)); //頂点バッファをデバイスのストリームにセット if (pIndexBuffer) //インデックスバッファが存在する場合 { pD3DDevice->SetIndices(pIndexBuffer); //インデックスバッファをセット pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, vectorD3DVERTEX.size(), 0, Primitives); //頂点インデックスありで描画 } else { //存在しない場合 pD3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, Primitives); //頂点インデックスなしで描画 } pD3DDevice->SetTransform(D3DTS_WORLD, &mtrxOld); //デバイスのワールド変換行列を復元 return; }