Exemplo n.º 1
0
// `使用Direct3D9來繪圖`
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// `開始下繪圖指令`
	device->BeginScene(); 
	// `計算出一個可以轉換到鏡頭座標系的矩陣`
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);

	// `設定資料格式`
	// D3DFVF_XYZ = `使用3個浮點數來記錄位置`
	// D3DFVF_DIFFUSE = `使用32bits整數型態來記錄BGRA顏色`
	device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); 

	// `太陽`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_sun_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pSunVertices, sizeof(Vertex_VC) );
	// `地球`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_earth_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pEarthVertices, sizeof(Vertex_VC) );
	// `月亮`
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_moon_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pMoonVertices, sizeof(Vertex_VC) );

	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 

	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
Exemplo n.º 2
0
	void Draw( int iMeshIndex ) const
	{
		const MeshInfo& meshInfo = m_vMeshInfo[iMeshIndex];

		if( meshInfo.bNeedsTextureMatrixScale )
		{
			// Kill the texture translation.
			// XXX: Change me to scale the translation by the TextureTranslationScale of the first vertex.
			RageMatrix m;
			g_pd3dDevice->GetTransform( D3DTS_TEXTURE0, (D3DMATRIX*)&m );

			m.m[2][0] = 0;
			m.m[2][1] = 0;

			g_pd3dDevice->SetTransform( D3DTS_TEXTURE0, (D3DMATRIX*)&m );
		}

		g_pd3dDevice->SetFVF( D3DFVF_RageModelVertex );
		g_pd3dDevice->DrawIndexedPrimitiveUP(
			D3DPT_TRIANGLELIST,			// PrimitiveType
			meshInfo.iVertexStart,		// MinIndex
			meshInfo.iVertexCount,		// NumVertices
			meshInfo.iTriangleCount,	// PrimitiveCount,
			&m_vTriangles[0]+meshInfo.iTriangleStart,// pIndexData,
			D3DFMT_INDEX16,				// IndexDataFormat,
			&m_vVertex[0],				// pVertexStreamZeroData,
			sizeof(m_vVertex[0])		// VertexStreamZeroStride
		);
	}
Exemplo n.º 3
0
// `使用Direct3D9來繪圖`
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// `開始下繪圖指令`
	device->BeginScene(); 
	// `設定資料格式`
	device->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL);
	// `套用shader`
	device->SetVertexShader(g_pSelected_VS);
	device->SetPixelShader(g_pVertexColor_PS);
	// `設定光源`
	SetupLightingDX9();
	// `設定轉換矩陣`
	Matrix4x4 world_view_proj_matrix = g_world_matrix * g_view_proj_matrix;
	device->SetVertexShaderConstantF(0, &world_view_proj_matrix[0][0], 4);
	device->SetVertexShaderConstantF(4, &g_world_matrix[0][0], 4);
	// `鏡頭位置, 計算Specular會用到.`
	device->SetVertexShaderConstantF(8, &g_eye[0], 1);
	// `畫出格子`
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP, 0, g_iNumGridVertices, g_iNumGridTriangles, 
		g_pGridIndices, D3DFMT_INDEX16, g_pGridVertices, sizeof(Vertex_V3N3) );
	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 
	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
Exemplo n.º 4
0
void RageDisplay_D3D::DrawQuadStripInternal( const RageSpriteVertex v[], int iNumVerts )
{
	// there isn't a quad strip primitive in D3D, so we have to fake it with indexed triangles
	int iNumQuads = (iNumVerts-2)/2;
	int iNumTriangles = iNumQuads*2;
	int iNumIndices = iNumTriangles*3;

	// make a temporary index buffer
	static vector<uint16_t> vIndices;
	unsigned uOldSize = vIndices.size();
	unsigned uNewSize = max(uOldSize,(unsigned)iNumIndices);
	vIndices.resize( uNewSize );
	for( uint16_t i=(uint16_t)uOldSize/6; i<(uint16_t)iNumQuads; i++ )
	{
		vIndices[i*6+0] = i*2+0;
		vIndices[i*6+1] = i*2+1;
		vIndices[i*6+2] = i*2+2;
		vIndices[i*6+3] = i*2+1;
		vIndices[i*6+4] = i*2+2;
		vIndices[i*6+5] = i*2+3;
	}

	g_pd3dDevice->SetFVF( D3DFVF_RageSpriteVertex );
	SendCurrentMatrices();
	g_pd3dDevice->DrawIndexedPrimitiveUP(
		D3DPT_TRIANGLELIST, // PrimitiveType
		0, // MinIndex
		iNumVerts, // NumVertices
		iNumTriangles, // PrimitiveCount,
		&vIndices[0], // pIndexData,
		D3DFMT_INDEX16, // IndexDataFormat,
		v, // pVertexStreamZeroData,
		sizeof(RageSpriteVertex) // VertexStreamZeroStride
	);
}
Exemplo n.º 5
0
void CGutFontDX9::Render(void)
{
	if ( m_iNumCharacters==0 )
		return;

	LPDIRECT3DDEVICE9 pDevice = GutGetGraphicsDeviceDX9();
	// 套用字型貼圖
	sModelMaterial_DX9 mtl;
	mtl.m_bCullFace = false;
	mtl.m_pTextures[0] = m_pFontTexture;
	mtl.Submit();
	// 開啟Alpha Test
	pDevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
	pDevice->SetRenderState(D3DRS_ALPHAREF, 128);
	pDevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
	// 使用平行視角鏡頭
	Matrix4x4 proj_matrix = GutMatrixOrthoRH_DirectX(m_fWidth, m_fHeight, 0.0f, 1.0f);
	Matrix4x4 view_matrix; view_matrix.Identity();
	Matrix4x4 ident_matrix; ident_matrix.Identity();
	view_matrix[3].Set(-m_fWidth/2.0f, -m_fHeight/2.0f, 0.0f, 1.0f);
	// 設定轉換矩陣
	pDevice->SetTransform(D3DTS_PROJECTION, (D3DMATRIX*)&proj_matrix);
	pDevice->SetTransform(D3DTS_VIEW, (D3DMATRIX*)&view_matrix);
	pDevice->SetTransform(D3DTS_WORLD, (D3DMATRIX*)&ident_matrix);
	// 設定頂點資料格式
	pDevice->SetFVF(D3DFVF_XYZ|D3DFVF_TEX1); 
	// 畫出所有的文字
	pDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, 
		m_iNumCharacters*4, m_iNumCharacters*2, 
		m_pIndexArray, D3DFMT_INDEX16, 
		m_pVertexArray, sizeof(_FontVertex));
}
Exemplo n.º 6
0
//**関数***************************************************************************
//	概要	:	メッシュ描画
//*********************************************************************************
void CMesh::Draw(D3DXMATRIX& world)
{
	// ワールド マトリックス設定
    LPDIRECT3DDEVICE9 pDevice = CGraphics::GetDevice();
    pDevice->SetTransform(D3DTS_WORLD, &world);

	for (DWORD i = 0; i < m_dwAttr; i++) {
		DWORD id = m_pAttr[i].AttribId;
        // アルファ値をチェック
        D3DMATERIAL9 mtrl = m_pMaterial[id];
		if (mtrl.Diffuse.a < 1.0f)
			continue;
		pDevice->SetMaterial(&mtrl);
		pDevice->SetTexture(0, m_ppTexture[id]);	// テクスチャを設定
//		m_pD3DMesh->DrawSubset(id);								// 描画を実行
		pDevice->SetFVF(FVF_BVERTEX);
		pDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0,
			m_dwVtx, m_pAttr[i].FaceCount, &m_pIdx[m_pAttr[i].FaceStart * 3],
			D3DFMT_INDEX16, m_pVtx, sizeof(BVERTEX));
	}

	// アルファ ブレンド有効化
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
    pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	for (DWORD i = 0; i < m_dwAttr; i++) {
		DWORD id = m_pAttr[i].AttribId;
        // アルファ値をチェック
        D3DMATERIAL9 mtrl = m_pMaterial[id];
		if (mtrl.Diffuse.a >= 1.0f)
			continue;
		pDevice->SetMaterial(&mtrl);
		pDevice->SetTexture(0, m_ppTexture[id]);	// テクスチャを設定
//		m_pD3DMesh->DrawSubset(id);								// 描画を実行
		pDevice->SetFVF(FVF_BVERTEX);
		pDevice->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0,
			m_dwVtx, m_pAttr[i].FaceCount, &m_pIdx[m_pAttr[i].FaceStart * 3],
			D3DFMT_INDEX16, m_pVtx, sizeof(BVERTEX));
	}

    // アルファ ブレンド無効化
    pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
}
Exemplo n.º 7
0
void RenderSolarSystemDX9(void)
{
	int index = g_FrameCount % 2;
	LPDIRECT3DQUERY9 pQuery = g_pOcclusionQuery[index];

	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// 設定資料格式
	// D3DFVF_XYZ = 使用3個浮點數來記錄位置
	// D3DFVF_DIFFUSE = 使用32bits整數型態來記錄BGRA顏色
	device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); 
	// 太陽
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_sun_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pSunVertices, sizeof(Vertex_VC) );
	// 地球
	pQuery->Issue(D3DISSUE_BEGIN);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_earth_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pEarthVertices, sizeof(Vertex_VC) );
	pQuery->Issue(D3DISSUE_END);
	// 月亮
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_moon_matrix);
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0, g_iNumSphereVertices, g_iNumSphereTriangles, 
		g_pSphereIndices, D3DFMT_INDEX16, g_pMoonVertices, sizeof(Vertex_VC) );

	if ( g_FrameCount )
	{
		int num_loops = 0;
		int num_samples_passed = 0;
		// 去檢查前一個畫面的Occlusion Query結果
		pQuery = g_pOcclusionQuery[(index + 1) % 2];
		while( pQuery->GetData(&num_samples_passed, 4, D3DGETDATA_FLUSH)==S_FALSE  )
		{
			// 結果可能還沒出來, 要再查詢一次
			num_loops++;
		}

		printf("Earth %s, queried %05d times\r", num_samples_passed ? "visible" : "disapper", num_loops);
	}

	g_FrameCount++;
}
Exemplo n.º 8
0
HRESULT HookIDirect3DDevice9::DrawIndexedPrimitiveUP(LPVOID _this,
													 D3DPRIMITIVETYPE PrimitiveType,
													 UINT MinVertexIndex,
													 UINT NumVertices,
													 UINT PrimitiveCount,
													 CONST void* pIndexData,
													 D3DFORMAT IndexDataFormat,
													 CONST void* pVertexStreamZeroData,
													 UINT VertexStreamZeroStride)
{
	LOG_API();
	return pD3Dev->DrawIndexedPrimitiveUP(PrimitiveType, MinVertexIndex, NumVertices, PrimitiveCount, pIndexData, IndexDataFormat, pVertexStreamZeroData, VertexStreamZeroStride);
}
Exemplo n.º 9
0
void CLcMdlSM::RenderMesh()
{
	LPDIRECT3DDEVICE9 pDev = (LPDIRECT3DDEVICE9)LcDev_GetD3Device();

	DWORD dMnLgt;

	pDev->GetRenderState( D3DRS_LIGHTING, &dMnLgt);
	pDev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
	
	pDev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
	pDev->SetRenderState(D3DRS_ALPHAREF, 0x40);
	pDev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL);
	
	pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
	pDev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
	pDev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);

	pDev->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	pDev->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	pDev->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

	pDev->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
	pDev->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	pDev->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

	pDev->SetTextureStageState( 0, D3DTSS_ALPHAOP,   D3DTOP_MODULATE );
	pDev->SetTextureStageState( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
	pDev->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );


	PDTX	pDXTex	= (PDTX)m_pTex->GetPointer();

	pDev->SetTexture(0, pDXTex);
	pDev->SetFVF(VtxNDUV1::FVF);
	pDev->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST, 0
									, m_nVtx
									, m_nIdx
									, m_pIdx
									, D3DFMT_INDEX16
									, m_pVtx
									, sizeof(VtxNDUV1)
									);

	LcD3D_SetWorldIdentity(pDev);
	pDev->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
	pDev->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);

	pDev->SetRenderState( D3DRS_LIGHTING, dMnLgt);
}
Exemplo n.º 10
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	device->Clear(
		0, NULL, // 清除整個畫面 
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, // 清除顏色跟Z buffer 
		D3DCOLOR_ARGB(0, 0, 0, 0), // 設定要把顏色清成黑色
		1.0f, // 設定要把Z值清為1, 也就是離鏡頭最遠
		0 // 設定要把Stencil buffer清為0, 在這沒差.
		);

	// 開始下繪圖指令
	device->BeginScene(); 
	// 設定資料格式
	device->SetFVF(D3DFVF_XYZ); 

	for ( int i=0; i<4; i++ )
	{
		// `建立轉換矩陣`
		Matrix4x4 world_matrix;
		world_matrix.Scale_Replace(g_scale[i]); // `建立縮放矩陣`
		world_matrix[3] = g_position[i]; // `直接把位移填入矩陣左下角.`

		// `設定轉換矩陣`
		device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &world_matrix);

		// 畫出金字塔的8條邊線
		device->DrawIndexedPrimitiveUP(
			D3DPT_LINELIST, // 指定所要畫的基本圖形種類 
			0, // 會使用的最小頂點編號, 事實上沒太大用處
			5, // 頂點陣列里有幾個頂點
			8, // 要畫出幾個基本圖形
			g_indices, // 索引陣列
			D3DFMT_INDEX16, // 索引陣列的型態
			g_vertices, // 頂點陣列
			sizeof(Vector4) // 頂點陣列里每個頂點的記憶體間距
			); 
	}

	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 

	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Exemplo n.º 11
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	device->Clear(
		0, NULL, // 清除整個畫面 
		D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, // 清除顏色跟Z buffer 
		D3DCOLOR_ARGB(0, 0, 0, 0), // 設定要把顏色清成黑色
		1.0f, // 設定要把Z值清為1, 也就是離鏡頭最遠
		0 // 設定要把Stencil buffer清為0, 在這沒差.
		);

	static float angle = 0.0f;
	angle += 0.01f;

	// 開始下繪圖指令
	device->BeginScene(); 

	// 設定資料格式
	// D3DFVF_XYZ = 使用4個浮點數來記錄位置
	// D3DFVF_DIFFUSE = 使用32bits整數型態來記錄BGRA顏色
	device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); 

	// 設定轉換矩陣
	Matrix4x4 world_matrix;
	world_matrix.RotateZ_Replace(angle); // 產生旋轉矩陣
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &world_matrix);

	// 畫出金字塔的8條邊線
	device->DrawIndexedPrimitiveUP(
		D3DPT_TRIANGLELIST, // 指定所要畫的基本圖形種類 
		0, // 會使用的最小頂點編號, 事實上沒太大用處
		5, // 頂點陣列里有幾個頂點
		6, // 要畫出幾個基本圖形
		g_indices, // 索引陣列
		D3DFMT_INDEX16, // 索引陣列的型態
		g_vertices, // 頂點陣列
		sizeof(Vertex_VC) // 頂點陣列里每個頂點的記憶體間距
		); 

	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 

	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Exemplo n.º 12
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// 消除畫面
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// 開始下繪圖指令
	device->BeginScene(); 
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &g_world_matrix);
	// 設定光源
	SetupLightingDX9();

	// 設定資料格式
	device->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL);
	// 畫出格子
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP, 0, g_iNumGridVertices, g_iNumGridTriangles, 
		g_pGridIndices, D3DFMT_INDEX16, g_pGridVertices, sizeof(Vertex_V3N3) );
	// 宣告所有的繪圖指令都下完了
	device->EndScene(); 
	// 把背景backbuffer的畫面呈現出來
	device->Present( NULL, NULL, NULL, NULL );
}
Exemplo n.º 13
0
void CBillboard::RenderBySoftware ( CRenderManager &_RM, const CColor &_Color )
{
	TCOLOREDTEXTURE1_VERTEX l_Points[4];
    unsigned short l_Indexes[6] = { 0, 2, 3, 1 };
	
	unsigned long color_aux = _Color.GetUint32Argb();

    l_Points[0].x		= m_PointA.x;
    l_Points[0].y		= m_PointA.y;
    l_Points[0].z		= m_PointA.z;
    l_Points[0].tu		= 0.0f;
    l_Points[0].tv		= 0.0f;
    l_Points[0].color	= color_aux;
        
    l_Points[1].x		= m_PointB.x;
    l_Points[1].y		= m_PointB.y;
    l_Points[1].z		= m_PointB.z;
    l_Points[1].tu		= 1.0f;
    l_Points[1].tv		= 0.0f;
    l_Points[1].color	= color_aux;

    l_Points[2].x		= m_PointC.x;
    l_Points[2].y		= m_PointC.y;
    l_Points[2].z		= m_PointC.z;
    l_Points[2].tu		= 0.0f;
    l_Points[2].tv		= 1.0f;
    l_Points[2].color	= color_aux;

    l_Points[3].x		= m_PointD.x;
    l_Points[3].y		= m_PointD.y;
    l_Points[3].z		= m_PointD.z;
    l_Points[3].tu		= 1.0f;
    l_Points[3].tv		= 1.0f;        
    l_Points[3].color	= color_aux;
	
	LPDIRECT3DDEVICE9 Device = _RM.GetDevice();
	Device->SetTexture( 0, m_Texture->GetDXTexture() );
    Device->SetFVF((DWORD ) TCOLOREDTEXTURE1_VERTEX::GetFVF() );
    Device->DrawIndexedPrimitiveUP( D3DPT_TRIANGLEFAN, 0, 4, 2, l_Indexes ,D3DFMT_INDEX16, l_Points, sizeof(TCOLOREDTEXTURE1_VERTEX) );
}
Exemplo n.º 14
0
///<summary>
/// CBillboard:: Render : Dibuja el Quad con la textura que le pasamos por parámetro
///</summary>
///<param name="device" name2="texture">Renderizamos la textura que le pasamos como parámetro.</param>
///<returns name="void"></returns>
void CBillboard::Render(LPDIRECT3DDEVICE9 device, LPDIRECT3DTEXTURE9 & texture)
{
		VERTEX_TEXTURED l_Points[4];
		unsigned short l_Indexes[6]={0,2,1,1,2,3};

		l_Points[0].x=m_PointA.x;
		l_Points[0].y=m_PointA.y;
		l_Points[0].z=m_PointA.z;
		l_Points[0].u=0.0f;
		l_Points[0].v=1.0f;
		l_Points[0].color=m_Color;
		
		l_Points[1].x=m_PointB.x;
		l_Points[1].y=m_PointB.y;
		l_Points[1].z=m_PointB.z;
		l_Points[1].u=1.0f;
		l_Points[1].v=1.0f;
		l_Points[1].color=m_Color;

		l_Points[2].x=m_PointC.x;
		l_Points[2].y=m_PointC.y;
		l_Points[2].z=m_PointC.z;
		l_Points[2].u=0.0f;
		l_Points[2].v=0.0f;
		l_Points[2].color=m_Color;

		l_Points[3].x=m_PointD.x;
		l_Points[3].y=m_PointD.y;
		l_Points[3].z=m_PointD.z;
		l_Points[3].u=1.0f;
		l_Points[3].v=0.0f;		
		l_Points[3].color=m_Color;


		device->SetTexture(0,texture);
		device->SetFVF(D3DFVF_VERTEX_TEXTURED);
		device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLELIST,0,6,2,l_Indexes,D3DFMT_INDEX16,l_Points,sizeof(VERTEX_TEXTURED));
}
Exemplo n.º 15
0
/// 프러스텀을 화면에 그려준다.
BOOL CFrustum::Draw( LPDIRECT3DDEVICE9 pDev )
{
	WORD		index[] = { 0, 1, 2,
							0, 2, 3,
							4, 7, 6,
							4, 6, 5,
							1, 5, 6,
							1, 6, 2,
							0, 3, 7,
							0, 7, 4,
							0, 4, 5,
							0, 5, 1,
							3, 7, 6,
							3, 6, 2 };

    D3DMATERIAL9 mtrl;
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );

	typedef struct tagVTX
	{
		D3DXVECTOR3	p;
	} VTX;

	VTX		vtx[8];
	memset( vtx, 0, sizeof(vtx) * 8);

	for( int i = 0 ; i < 8 ; i++ )
		vtx[i].p = m_vtx[i];

	pDev->SetFVF( D3DFVF_XYZ );
	pDev->SetStreamSource( 0, NULL, 0, sizeof(VTX) );
	pDev->SetTexture( 0, NULL );
	pDev->SetIndices( 0 );
	pDev->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_DISABLE );
	pDev->SetTextureStageState( 1, D3DTSS_COLOROP,   D3DTOP_DISABLE );
	pDev->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE);
	pDev->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_ONE );
	pDev->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );

	// 파란색으로 상,하 평면을 그린다.
    pDev->SetRenderState( D3DRS_LIGHTING, TRUE );
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse.b = mtrl.Ambient.b = 1.0f;
    pDev->SetMaterial( &mtrl );
	pDev->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, 8, 4, index, D3DFMT_INDEX16, vtx, sizeof( vtx[0] ) );

	// 녹색으로 좌,우 평면을 그린다.
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse.g = mtrl.Ambient.g = 1.0f;
    pDev->SetMaterial( &mtrl );
	pDev->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, 8, 4, index+4*3, D3DFMT_INDEX16, vtx, sizeof( vtx[0] ) );

	// 붉은색으로 원,근 평면을 그린다.
    ZeroMemory( &mtrl, sizeof(D3DMATERIAL9) );
    mtrl.Diffuse.r = mtrl.Ambient.r = 1.0f;
    pDev->SetMaterial( &mtrl );
	pDev->DrawIndexedPrimitiveUP( D3DPT_TRIANGLELIST, 0, 8, 4, index+8*3, D3DFMT_INDEX16, vtx, sizeof( vtx[0] ) );

	pDev->SetRenderState( D3DRS_ALPHABLENDENABLE, FALSE );
    pDev->SetRenderState( D3DRS_LIGHTING, FALSE );
	return TRUE;
}
Exemplo n.º 16
0
void CBillboard::RenderByHardware ( CRenderManager &_RM, const CColor &_Color )
{
	//CORE->GetRenderableObjectsTechniqueManager()->GetPoolRenderableObjectTechniques().GetResource(
	std::string l_TechniqueName = "DrawSingleTextureTechnique"; // CORE->GetEffectsManager()->GetTechniqueEffectNameByVertexDefault( ( int ) TGEOMETRYCOLORTEXTURA1VERTEX::GetVertexType() );
	CEffectTechnique* l_pTechnique = CORE->GetEffectManager()->GetEffectTechnique ( l_TechniqueName );

	CEffect* l_pEffect = l_pTechnique->GetEffect();
	l_pTechnique->BeginRender();
	LPD3DXEFFECT l_Effect = l_pTechnique->GetEffect()->GetD3DEffect();

	if ( l_Effect != NULL )
	{
		l_Effect->SetTechnique ( l_pTechnique->GetD3DTechnique() );
		UINT l_NumPasses;
		if ( SUCCEEDED ( l_Effect->Begin ( &l_NumPasses, 0 ) ) )
		{
			
			for ( UINT iPass = 0; iPass < l_NumPasses; iPass++ )
			{
				l_Effect->BeginPass(iPass);
	
				//_RM->DrawColoredQuad2DTexturedInPixels ( _Color, _U0, _V0, _U1, _V1 );

				TCOLOREDTEXTURE1_VERTEX l_Points[4];
				unsigned short l_Indexes[6] = { 0, 2, 3, 1 };
	
				unsigned long color_aux = _Color.GetUint32Argb();

				l_Points[0].x		= m_PointA.x;
				l_Points[0].y		= m_PointA.y;
				l_Points[0].z		= m_PointA.z;
				l_Points[0].tu		= 0.0f;
				l_Points[0].tv		= 0.0f;
				l_Points[0].color	= color_aux;
        
				l_Points[1].x		= m_PointB.x;
				l_Points[1].y		= m_PointB.y;
				l_Points[1].z		= m_PointB.z;
				l_Points[1].tu		= 1.0f;
				l_Points[1].tv		= 0.0f;
				l_Points[1].color	= color_aux;

				l_Points[2].x		= m_PointC.x;
				l_Points[2].y		= m_PointC.y;
				l_Points[2].z		= m_PointC.z;
				l_Points[2].tu		= 0.0f;
				l_Points[2].tv		= 1.0f;
				l_Points[2].color	= color_aux;

				l_Points[3].x		= m_PointD.x;
				l_Points[3].y		= m_PointD.y;
				l_Points[3].z		= m_PointD.z;
				l_Points[3].tu		= 1.0f;
				l_Points[3].tv		= 1.0f;        
				l_Points[3].color	= color_aux;

				Mat44f mat, rotYaw, rotPitch, rotRoll;          
	  
				//mat.SetIdentity ( );         
				//rotYaw.SetIdentity ( );         
				//rotPitch.SetIdentity ( );         
				//rotRoll.SetIdentity ( );          
				//mat.Translate( GetPosition ( ) );                          
				///*rotPitch.SetRotByAngleX( mathUtils::Deg2Rad<float> ( GetPitch()) );           
				//rotYaw.SetRotByAngleY ( mathUtils::Deg2Rad<float> ( GetYaw()) );         
				//rotRoll.SetRotByAngleZ ( mathUtils::Deg2Rad<float> ( GetRoll()) ); */                         
				//mat = mat * rotYaw * rotPitch * rotRoll;                          
	  
				//_RM->SetTransform ( mat );          


				LPDIRECT3DDEVICE9 Device = _RM.GetDevice();
				Device->SetTexture( 0, m_Texture->GetDXTexture() );
				if ( SUCCEEDED ( Device->SetVertexDeclaration( TCOLOREDTEXTURE1_VERTEX::GetVertexDeclaration() ) ) )
				{
					Device->DrawIndexedPrimitiveUP( D3DPT_TRIANGLEFAN, 0, 4 ,2 , l_Indexes, D3DFMT_INDEX16, l_Points, sizeof( TCOLOREDTEXTURE1_VERTEX ) );
				}

				l_Effect->EndPass();
			}
			l_Effect->End();
		}
	}
}
Exemplo n.º 17
0
// 使用DirectX 9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	// `清除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);

	// `開始下繪圖指令`
	device->BeginScene(); 

	// `設定資料格式`
	// `D3DFVF_XYZ = 使用3個浮點數來記錄位置`
	// `D3DFVF_DIFFUSE = 使用32bits整數型態來記錄BGRA顏色`
	device->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE); 

	// `計算出一個可以轉換到鏡頭座標系的矩陣`
	Matrix4x4 view_matrix = GutMatrixLookAtRH(g_eye, g_lookat, g_up);
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);

	Vector4 border(-15.0f, 0.0f, -15.0f);
	Vector4 grid_position = border;

	const int grids_x = 30;
	const int grids_z = 30;

	for ( int x=0; x<grids_x; x++ )
	{
		int grid_x = x & 0x07;
		grid_position[2] = border[2];

		for ( int z=0; z<grids_z; z++ )
		{
			int grid_z = z & 0x07;
			char c = g_map[grid_x][grid_z];

			// `設定轉換矩陣`
			Matrix4x4 object_matrix;
			object_matrix.Translate_Replace(grid_position);

			if ( c==0 ) // `馬路`
			{
				device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &object_matrix);
				// `畫出地板`
				device->DrawIndexedPrimitiveUP(
					D3DPT_TRIANGLESTRIP,
					0,
					4,
					2,
					g_road_trianglestrip_indices,
					D3DFMT_INDEX16,
					g_road_vertices,
					sizeof(Vertex_VC)
					);
			}
			else // `金字塔`
			{
				// `設定金字塔的高度`
				object_matrix.Scale_Replace(1.0f, (float) c, 1.0f);
				object_matrix[3] = grid_position;
				device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &object_matrix);
				// `畫出金字塔`
				device->DrawIndexedPrimitiveUP(
					D3DPT_TRIANGLEFAN, // `指定所要畫的基本圖形種類`
					0, // `會使用的最小頂點編號, 事實上沒太大用處.`
					5, // `頂點陣列里有幾個頂點`
					4, // `要畫出幾個基本圖形`
					g_pyramid_trianglefan_indices,	// `索引陣列`
					D3DFMT_INDEX16,		// `索引陣列的型態`
					g_pyramid_vertices,	// `頂點陣列`
					sizeof(Vertex_VC)	// `頂點陣列里每個頂點的記憶體間距`
					);
			}

			grid_position[2] += 1.0f;
		}

		grid_position[0] += 1.0f;
	}

	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 

	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}