当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECT3DINDEXBUFFER9::Lock方法代码示例

本文整理汇总了C++中LPDIRECT3DINDEXBUFFER9::Lock方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DINDEXBUFFER9::Lock方法的具体用法?C++ LPDIRECT3DINDEXBUFFER9::Lock怎么用?C++ LPDIRECT3DINDEXBUFFER9::Lock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LPDIRECT3DINDEXBUFFER9的用法示例。


在下文中一共展示了LPDIRECT3DINDEXBUFFER9::Lock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: init_graphics

// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{   
    // create a vertex buffer interface called v_buffer
    d3ddev->CreateVertexBuffer(g_Sim.numPoints()*sizeof(CUSTOMVERTEX),
                               D3DUSAGE_WRITEONLY,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &v_buffer,
                               NULL);
	d3ddev->CreateVertexBuffer(5*sizeof(CUSTOMVERTEX),
		                       D3DUSAGE_WRITEONLY,
							   CUSTOMFVF,
							   D3DPOOL_MANAGED,
							   &v_bordbuffer,
							   NULL);
	d3ddev->CreateIndexBuffer(g_Sim.numConstraints() * 2 * sizeof(short),
							  D3DUSAGE_WRITEONLY,
							  D3DFMT_INDEX16,
							  D3DPOOL_MANAGED,
							  &i_buffer,
							  NULL);


	HRESULT hr = D3DXCreateFont(d3ddev, 17, 0, FW_NORMAL, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, ANTIALIASED_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Courier New"), &font );

	CUSTOMVERTEX* verts;
	v_bordbuffer->Lock(0, 0, (void**)&verts, 0);
	verts[0].X = MINX;
	verts[0].Y = MINY;
	verts[1].X = MINX;
	verts[1].Y = MAXY;
	verts[2].X = MAXX;
	verts[2].Y = MAXY;
	verts[3].X = MAXX;
	verts[3].Y = MINY;
	verts[4].X = MINX;
	verts[4].Y = MINY;

	verts[0].Z = verts[1].Z = verts[2].Z = verts[3].Z = verts[4].Z = 0.0f;
	verts[0].COLOR = verts[1].COLOR = verts[2].COLOR = verts[3].COLOR = verts[4].COLOR = D3DCOLOR_XRGB(127, 127, 127);
	v_bordbuffer->Unlock();

    short* indices;
    i_buffer->Lock(0, 0, (void**)&indices, 0);
	for (unsigned i = 0; i < g_Sim.numConstraints(); i++) {
		const std::pair<unsigned, unsigned>& p = g_Sim.constraint(i);
		indices[2 * i] = p.first;
		indices[2 * i + 1] = p.second;
	}
    i_buffer->Unlock();

}
开发者ID:m3lawren,项目名称:ClothDemo,代码行数:53,代码来源:main.cpp

示例2:

HRESULT	CameraWorkBase::SetIB( LPDIRECT3DINDEXBUFFER9 _pIB, LPVOID _indices, INT _nIndex, INT _Size )
{
	LPVOID pIndices;
	if( FAILED( _pIB->Lock( 0, _nIndex * _Size, (VOID**)&pIndices, 0 ) ) )
	{
		MessageBox( NULL, L"CameraWorkBase::m_pIB->Lock() failed.", NULL, MB_OK );
		return E_FAIL;
	}
	
		memcpy( pIndices, _indices, _nIndex * _Size );

	_pIB->Unlock();

	return S_OK;
}
开发者ID:yoonhada,项目名称:nlinelast,代码行数:15,代码来源:CameraWorkBase.cpp

示例3: ConvertVertex

//===============================================
//頂点情報のコンバート
//===============================================
//[input]
//	pD3DX9:Direct3Dデバイス
//[return]
//	HREULT値
//===============================================
bool CXMesh::ConvertVertex(LPDIRECT3DDEVICE9 pD3DX9)
{
    LPD3DXBUFFER pD3DXMtrlBuffer = NULL;

	/*Vertex Bufferにコピーする*/
	D3DVERTEX* pSrc;
	D3DVERTEX* pDest;
	LPDIRECT3DINDEXBUFFER9 pSrcIndex;
	WORD* pISrc;
	WORD* pIDest;

	/*VertexBuffer情報取得*/
	LPDIRECT3DVERTEXBUFFER9 pVB;
	MeshData.pMesh->GetVertexBuffer(&pVB);

	D3DVERTEXBUFFER_DESC	Desc;
	pVB->GetDesc( &Desc );

	DWORD nMeshVertices	= MeshData.pMesh->GetNumVertices();
	DWORD nMeshFaces	= MeshData.pMesh->GetNumFaces();

	/*頂点バッファを作成*/
	pD3DX9->CreateVertexBuffer( Desc.Size, 0, MeshData.pMesh->GetFVF(), D3DPOOL_MANAGED, &m_pMeshVB, NULL );

	/*インデックスバッファを作成*/
	pD3DX9->CreateIndexBuffer( nMeshFaces * 3 * sizeof(WORD), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &m_pMeshIndex, NULL );

	/*頂点バッファをコピー*/
	pVB->Lock(0,0,(void**)&pSrc,0);
	m_pMeshVB->Lock(0,0,(void**)&pDest,0);
	CopyMemory( pDest, pSrc, Desc.Size );

	pVB->Unlock();
	pVB->Release();
	m_pMeshVB->Unlock();

	/*インデックスのコピー*/
	MeshData.pMesh->GetIndexBuffer( &pSrcIndex );
	pSrcIndex->Lock( 0, 0, (void**)&pISrc, 0 );
	m_pMeshIndex->Lock( 0, 0, (void**)&pIDest, 0 );
	CopyMemory( pIDest, pISrc, nMeshFaces * 3 * sizeof( WORD ) );

	pSrcIndex->Unlock();
	m_pMeshIndex->Unlock();
	pSrcIndex->Release();

    return true;
}
开发者ID:Taka03,项目名称:Procon2007,代码行数:56,代码来源:CXMesh.cpp

示例4: LoadMesh

    void LoadMesh(const PMDLoader::DATA *_data)
    {
        LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device;
        HRESULT hr;

        // 頂点バッファの作成
        m_MaxVertex = _data->vert_count.u;
        hr = device->CreateVertexBuffer(
            sizeof(Vertex3D::VERTEX) * _data->vert_count.u,
            D3DUSAGE_WRITEONLY,                // 頂点バッファの使用方法
            Vertex3D::FVF,                     // 使用する頂点フォーマット
            D3DPOOL_MANAGED,                   // バッファを保持するメモリクエストを指定
            &m_VertexBuffer,                   // 頂点のバッファの先頭アドレス
            NULL );

        Vertex3D::VERTEX *vtx;
        hr = m_VertexBuffer->Lock(0,0,(void**)&vtx,0);
        for( unsigned int i = 0; i < _data->vert_count.u ; i++)
        {
            vtx[i].pos.x =   _data->vertex[i].pos[0].f;
            vtx[i].pos.y =   _data->vertex[i].pos[1].f;
            vtx[i].pos.z =  -_data->vertex[i].pos[2].f;
            vtx[i].nor.x =  _data->vertex[i].normal_vec[0].f;
            vtx[i].nor.y =  _data->vertex[i].normal_vec[1].f;
            vtx[i].nor.z = -_data->vertex[i].normal_vec[2].f;
            vtx[i].tex.x =  _data->vertex[i].uv[0].f;
            vtx[i].tex.y =  _data->vertex[i].uv[1].f;
        }
        hr = m_VertexBuffer->Unlock();

        // インデックスバッファの作成
        m_MaxIndex = _data->face_vert_count.u;
        hr = device->CreateIndexBuffer(
            sizeof( WORD ) * m_MaxIndex,    // バッファサイズ
            D3DUSAGE_WRITEONLY,             // 頂点バッファの使用方法
            D3DFMT_INDEX16,                 // 使用する頂点フォーマット
            D3DPOOL_MANAGED,                // バッファを保持するメモリクエストを指定
            &m_IndexBuffer,                 // 頂点インデックスのバッファの先頭アドレス
            NULL );

        WORD *idx;
        hr = m_IndexBuffer->Lock(0,0,(void**)&idx,0);
        for( unsigned int i=0; i < _data->face_vert_count.u ; i++)
        {
            idx[i] = _data->face_vert_index[i].u;
        }
        hr = m_IndexBuffer->Unlock();
    }
开发者ID:AyumiYasui,项目名称:Material,代码行数:48,代码来源:PMDNoBoneManagerDx9.cpp

示例5: D3DQuads_OnRecover

void D3DQuads_OnRecover (void)
{
	if (!d3d_QuadBuffer)
	{
		D3DMain_CreateVertexBuffer (D3D_MAX_QUADS * 4 * sizeof (quadvert_t), D3DUSAGE_DYNAMIC, &d3d_QuadBuffer);
		d3d_NumQuads = 0;
	}

	if (!d3d_QuadIndexes)
	{
		unsigned short *ndx = NULL;

		D3DMain_CreateIndexBuffer16 (D3D_MAX_QUADS * 6, 0, &d3d_QuadIndexes);
		d3d_QuadIndexes->Lock (0, 0, (void **) &ndx, d3d_GlobalCaps.DefaultLock);

		// strips?  go hang yer bollocks on them.  with a 4-entry vertex cache this is just fine
		for (int i = 0, v = 0; i < D3D_MAX_QUADS; i++, v += 4, ndx += 6)
		{
			ndx[0] = v + 0;
			ndx[1] = v + 1;
			ndx[2] = v + 2;
			ndx[3] = v + 0;
			ndx[4] = v + 2;
			ndx[5] = v + 3;
		}

		d3d_QuadIndexes->Unlock ();
		d3d_RenderDef.numlock++;
	}

	if (!d3d_QuadDecl)
	{
		D3DVERTEXELEMENT9 d3d_quadlayout[] =
		{
			VDECL (0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0),
			VDECL (0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0),
			VDECL (0, 16, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0),
			D3DDECL_END ()
		};

		hr = d3d_Device->CreateVertexDeclaration (d3d_quadlayout, &d3d_QuadDecl);
		if (FAILED (hr)) Sys_Error ("D3DQuads_OnRecover: d3d_Device->CreateVertexDeclaration failed");
	}
}
开发者ID:AAS,项目名称:directq,代码行数:44,代码来源:d3d_Quads.cpp

示例6: ChangeObject

void ChangeObject(void)
{
	//顶点数据  
	CUSTOMVERTEX vertices[] =
	{
		{ -20.0f, 20.0f, -20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ -20.0f, 20.0f, 20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ 20.0f, 20.0f, 20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ 20.0f, 20.0f, -20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ -20.0f, -20.0f, -20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ -20.0f, -20.0f, 20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ 20.0f, -20.0f, 20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) },
		{ 20.0f, -20.0f, -20.0f, D3DCOLOR_XRGB(rand() % 256, rand() % 256, rand() % 256) }
	};

	VOID * pVertics = 0;
	g_pVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertics, 0);
	memcpy(pVertics, vertices, sizeof(vertices));
	g_pVertexBuffer->Unlock();

	// 填充索引数据  
	WORD *pIndices = NULL;
	g_pIndexBuffer->Lock(0, 0, (void**)&pIndices, 0);
	// 顶面  
	pIndices[0] = 0, pIndices[1] = 1, pIndices[2] = 2;
	pIndices[3] = 0, pIndices[4] = 2, pIndices[5] = 3;
	// 正面  
	pIndices[6] = 0, pIndices[7] = 3, pIndices[8] = 7;
	pIndices[9] = 0, pIndices[10] = 7, pIndices[11] = 4;
	// 左侧面  
	pIndices[12] = 0, pIndices[13] = 4, pIndices[14] = 5;
	pIndices[15] = 0, pIndices[16] = 5, pIndices[17] = 1;
	// 右侧面  
	pIndices[18] = 2, pIndices[19] = 6, pIndices[20] = 7;
	pIndices[21] = 2, pIndices[22] = 7, pIndices[23] = 3;
	// 背面  
	pIndices[24] = 2, pIndices[25] = 5, pIndices[26] = 6;
	pIndices[27] = 2, pIndices[28] = 1, pIndices[29] = 5;
	// 底面  
	pIndices[30] = 4, pIndices[31] = 6, pIndices[32] = 5;
	pIndices[33] = 4, pIndices[34] = 7, pIndices[35] = 6;
	g_pIndexBuffer->Unlock();
}
开发者ID:liyongfa,项目名称:DirectX,代码行数:43,代码来源:demo1.cpp

示例7: GenOctreeFaceIndex

void GdsNode::GenOctreeFaceIndex()
{
	if ( !m_bUseOctree )
		return;

	RENDER_OBJECT_CONTAINER::iterator it = m_list_RenderObject.begin();
	for ( ; it != m_list_RenderObject.end() ; ++it )
	{
		LPDWORD pIB;
		GdsRenderObject* rendertoken = it->first;
		LPDIRECT3DINDEXBUFFER9 pI = rendertoken->GetIndexBuffer();
		if( SUCCEEDED( pI->Lock( 0 , 0 , (void**)&pIB , 0 ) ) )
		{
			int iMaxCountIndex = genTriIndex( m_pOctreeRootNode , pIB , 0 );
			rendertoken->SetIndexMaxCount( iMaxCountIndex );
		}		
		pI->Unlock();
	}
}
开发者ID:rodrigobmg,项目名称:choding,代码行数:19,代码来源:GdsNode.cpp

示例8:

																																					//
// Creates a DirectX mesh
void DirectX::Mesh::create( void* vertexBuffer, void* indexBuffer, unsigned long FVF, unsigned int nVertices, unsigned int nFaces, unsigned long options )
{
	// Calculate vertex stride
	int vertexStride =
		((FVF|D3DFVF_XYZ)      == FVF) * 12 +
		((FVF|D3DFVF_XYZRHW)   == FVF) * 12 +
		((FVF|D3DFVF_XYZB1)    == FVF) * 12 +
		((FVF|D3DFVF_XYZB2)    == FVF) * 12 +
		((FVF|D3DFVF_XYZB3)    == FVF) * 12 +
		((FVF|D3DFVF_XYZB4)    == FVF) * 12 +
		((FVF|D3DFVF_XYZB5)    == FVF) * 12 +
		((FVF|D3DFVF_XYZW)     == FVF) * 12 +
		((FVF|D3DFVF_NORMAL)   == FVF) * 12 +
		((FVF|D3DFVF_DIFFUSE)  == FVF) * 4  +
		((FVF|D3DFVF_SPECULAR) == FVF) * 4  +
		((FVF|D3DFVF_TEX1)     == FVF) * 8  +
		((FVF|D3DFVF_TEX2)     == FVF) * 8  +
		((FVF|D3DFVF_TEX3)     == FVF) * 8  +
		((FVF|D3DFVF_TEX4)     == FVF) * 8  +
		((FVF|D3DFVF_TEX5)     == FVF) * 8  +
		((FVF|D3DFVF_TEX6)     == FVF) * 8  +
		((FVF|D3DFVF_TEX7)     == FVF) * 8  +
		((FVF|D3DFVF_TEX8)     == FVF) * 8;

	// Create mesh  of sufficient size to store vertex/index buffer data
	HRESULT hr = D3DXCreateMeshFVF( nFaces, nVertices, options, FVF, DirectX::Manager::instance( )->getD3DDev( ), &m_mesh );
	if( hr ) MessageBox( NULL, L"Call to D3DXCreateMeshFVF has failed.", L"DirectX Engine", NULL );
	LPDIRECT3DVERTEXBUFFER9 vb; LPDIRECT3DINDEXBUFFER9 ib; m_mesh->GetVertexBuffer( &vb ); m_mesh->GetIndexBuffer( &ib );
	
	// Lock the ibuffer and load the indices
	char* pVertices; vb->Lock( NULL, NULL, (void**)&pVertices, D3DLOCK_DISCARD );
	memcpy( pVertices, vertexBuffer, nVertices*vertexStride ); vb->Unlock( );

	// Lock the vbuffer and load the vertices
	char* pIndices; ib->Lock( NULL, NULL, (void**)&pIndices, D3DLOCK_DISCARD );
	memcpy( pIndices, indexBuffer, nFaces*3*sizeof(short) ); ib->Unlock( );

	// Register with the manager
	if( !(options&D3DXMESH_SYSTEMMEM) ) 
		DirectX::Manager::instance( )->addResource( this );
}
开发者ID:nilimsarma,项目名称:Blokus_FPGA,代码行数:43,代码来源:Mesh.cpp

示例9: initVB

///Create Vertex Buffer
HRESULT initVB(){
	CUSTOMVERTEX vertices[9];
	vertices[0].x = 300;
	vertices[0].y = 250;
	vertices[0].z = 0.5f;
	vertices[0].rhw = 1.0f;
	vertices[0].color = 0xffff0000;
	for(int i=0; i<8; ++i){
		vertices[i+1].x = (float)(200*sin(i*3.14159/4.0)) + 300;
		vertices[i+1].y = -(float)(200*cos(i*3.14159/4.0)) + 250;
		vertices[i+1].z = 0.5f;
		vertices[i+1].rhw = 1.0f;
		vertices[i+1].color = 0xff00ff00;
	}
	WORD indices[] = { 0,1,2, 0,2,3, 0,3,4, 0,4,5, 0,5,6, 0,6,7, 0,7,8, 0,8,1 };
	//Vertex Buffer
	if(FAILED(g_pDevice->CreateVertexBuffer(9 * sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL)))
		return E_FAIL;

	VOID* pVertices;
	if(FAILED(g_pVB->Lock(0, sizeof(vertices), (void**)&pVertices, 0)))
		return E_FAIL;
	memcpy(pVertices, vertices, sizeof(vertices));
	g_pVB->Unlock();
	///Index Buffer
	if(FAILED(g_pDevice->CreateIndexBuffer(24* sizeof(WORD), 0, D3DFMT_INDEX16,
		D3DPOOL_DEFAULT, &g_pIB, NULL)))
		return E_FAIL;

	VOID* pIndices;
	if(FAILED(g_pIB->Lock(0, sizeof(indices), (void**)&pIndices, 0)))
		return E_FAIL;
	memcpy(pIndices, indices, sizeof(indices));
	g_pIB->Unlock();


	return S_OK;
}
开发者ID:junglek,项目名称:DirectX-Basic,代码行数:40,代码来源:Main.cpp

示例10: init_index_buffer

HRESULT init_index_buffer()
{
    CUSTOMINDEX	indices[] = {
		{ 0, 1, 2 }, { 0, 2, 3 },	/// 윗면
		{ 4, 6, 5 }, { 4, 7, 6 },	/// 아랫면
		{ 0, 3, 7 }, { 0, 7, 4 },	/// 왼면
		{ 1, 5, 6 }, { 1, 6, 2 },	/// 오른면
		{ 3, 2, 6 }, { 3, 6, 7 },	/// 앞면
		{ 0, 4, 5 }, { 0, 5, 1 }	/// 뒷면
    };

    if (FAILED( g_pd3dDevice->CreateIndexBuffer( 12 * sizeof(CUSTOMINDEX), 0, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &g_pIndexBuff, NULL )))
        return E_FAIL;

    VOID* pIndices;
    if (FAILED( g_pIndexBuff->Lock( 0, sizeof(indices), (void**)&pIndices, 0 )))
        return E_FAIL;
    memcpy( pIndices, indices, sizeof(indices) );
    g_pIndexBuff->Unlock();

    return S_OK;
}
开发者ID:netpyoung,项目名称:bs.3d_game_programming,代码行数:22,代码来源:2-7.cpp

示例11: ReadModelFile

bool ReadModelFile( const string &fileName, LPDIRECT3DVERTEXBUFFER9 &vtxBuff, int &vtxSize,  LPDIRECT3DINDEXBUFFER9 &idxBuff, int &faceSize )
{
	using namespace std;
	ifstream fin(fileName.c_str());
	if (!fin.is_open())
		return false;

	string vtx, vtx_eq;
	int numVertices;
	fin >> vtx >> vtx_eq >> numVertices;

	if (numVertices <= 0)
		return  false;

	vtxSize = numVertices;

	// 버텍스 버퍼 생성.
	if (FAILED(g_pDevice->CreateVertexBuffer( numVertices * sizeof(Vertex),
		D3DUSAGE_WRITEONLY, Vertex::FVF,
		D3DPOOL_MANAGED, &vtxBuff, NULL)))
	{
		return false;
	}

	// 버텍스 버퍼 초기화.
	Vertex* vertices;
	if (FAILED(vtxBuff->Lock( 0, sizeof(Vertex), (void**)&vertices, 0)))
		return false;
	float num1, num2, num3;
	for (int i = 0; i < numVertices; i++)
	{
		fin >> num1 >> num2 >> num3;
		vertices[i] = Vertex(num1, num2, num3);
	}
	vtxBuff->Unlock();


	string idx, idx_eq;
	int numIndices;
	fin >> idx >> idx_eq >> numIndices;

	if (numIndices <= 0)
		return false;

	faceSize = numIndices;

	if (FAILED(g_pDevice->CreateIndexBuffer(numIndices*3*sizeof(WORD), 
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,
		D3DPOOL_MANAGED,
		&idxBuff, NULL)))
	{
		return false;
	}

	WORD *indices = NULL;
	idxBuff->Lock(0, 0, (void**)&indices, 0);
	int num4, num5, num6;
	for (int i = 0; i < numIndices*3; i+=3)
	{
		fin >> num4 >> num5 >> num6;
		indices[ i] = num4;
		indices[ i+1] = num5;
		indices[ i+2] = num6;	
	}
	idxBuff->Unlock();

	ComputeNormals(vtxBuff, vtxSize, idxBuff, faceSize);
	return true;
}
开发者ID:butilities,项目名称:3D-Lecture-2,代码行数:70,代码来源:Target.cpp

示例12: SetObject

void SetObject(void)
{
	//顶点数据  
	CUSTOMVERTEX vertices[] =
	{
		// 正面顶点数据
		{ -10.0f, 10.0f, -10.0f, 0.0f, 0.0f },
		{ 10.0f, 10.0f, -10.0f, 1.0f, 0.0f },
		{ 10.0f, -10.0f, -10.0f, 1.0f, 1.0f },
		{ -10.0f, -10.0f, -10.0f, 0.0f, 1.0f },

		// 背面顶点数据
		{ 10.0f, 10.0f, 10.0f, 0.0f, 0.0f },
		{ -10.0f, 10.0f, 10.0f, 1.0f, 0.0f },
		{ -10.0f, -10.0f, 10.0f, 1.0f, 1.0f },
		{ 10.0f, -10.0f, 10.0f, 0.0f, 1.0f },

		// 顶面顶点数据  
		{ -10.0f, 10.0f, 10.0f, 0.0f, 0.0f },
		{ 10.0f, 10.0f, 10.0f, 1.0f, 0.0f },
		{ 10.0f, 10.0f, -10.0f, 1.0f, 1.0f },
		{ -10.0f, 10.0f, -10.0f, 0.0f, 1.0f },

		// 底面顶点数据  
		{ -10.0f, -10.0f, -10.0f, 0.0f, 0.0f },
		{ 10.0f, -10.0f, -10.0f, 1.0f, 0.0f },
		{ 10.0f, -10.0f, 10.0f, 1.0f, 1.0f },
		{ -10.0f, -10.0f, 10.0f, 0.0f, 1.0f },

		// 左侧面顶点数据  
		{ -10.0f, 10.0f, 10.0f, 0.0f, 0.0f },
		{ -10.0f, 10.0f, -10.0f, 1.0f, 0.0f },
		{ -10.0f, -10.0f, -10.0f, 1.0f, 1.0f },
		{ -10.0f, -10.0f, 10.0f, 0.0f, 1.0f },

		// 右侧面顶点数据  
		{ 10.0f, 10.0f, -10.0f, 0.0f, 0.0f },
		{ 10.0f, 10.0f, 10.0f, 1.0f, 0.0f },
		{ 10.0f, -10.0f, 10.0f, 1.0f, 1.0f },
		{ 10.0f, -10.0f, -10.0f, 0.0f, 1.0f },
	};

	VOID * pVertics = 0;
	g_pVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertics, 0);
	memcpy(pVertics, vertices, sizeof(vertices));
	g_pVertexBuffer->Unlock();

	// 填充索引数据  
	WORD *pIndices = NULL;
	g_pIndexBuffer->Lock(0, 0, (void**)&pIndices, 0);
	// 正面索引数据  
	pIndices[0] = 0; pIndices[1] = 1; pIndices[2] = 2;
	pIndices[3] = 0; pIndices[4] = 2; pIndices[5] = 3;

	// 背面索引数据  
	pIndices[6] = 4; pIndices[7] = 5; pIndices[8] = 6;
	pIndices[9] = 4; pIndices[10] = 6; pIndices[11] = 7;

	// 顶面索引数据  
	pIndices[12] = 8; pIndices[13] = 9; pIndices[14] = 10;
	pIndices[15] = 8; pIndices[16] = 10; pIndices[17] = 11;

	// 底面索引数据  
	pIndices[18] = 12; pIndices[19] = 13; pIndices[20] = 14;
	pIndices[21] = 12; pIndices[22] = 14; pIndices[23] = 15;

	// 左侧面索引数据  
	pIndices[24] = 16; pIndices[25] = 17; pIndices[26] = 18;
	pIndices[27] = 16; pIndices[28] = 18; pIndices[29] = 19;

	// 右侧面索引数据  
	pIndices[30] = 20; pIndices[31] = 21; pIndices[32] = 22;
	pIndices[33] = 20; pIndices[34] = 22; pIndices[35] = 23;

	g_pIndexBuffer->Unlock();
}
开发者ID:liyongfa,项目名称:DirectX,代码行数:76,代码来源:demo4.cpp

示例13: ImGui_ImplDX9_RenderDrawLists

// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
// If text or lines are blurry when integrating ImGui in your engine:
// - in your Render function, try translating your projection matrix by (0.5f,0.5f) or (0.375f,0.375f)
void ImGui_ImplDX9_RenderDrawLists(ImDrawData* draw_data)
{
    // Avoid rendering when minimized
    ImGuiIO& io = ImGui::GetIO();
    if (io.DisplaySize.x <= 0.0f || io.DisplaySize.y <= 0.0f)
        return;

    // Create and grow buffers if needed
    if (!g_pVB || g_VertexBufferSize < draw_data->TotalVtxCount)
    {
        if (g_pVB) { g_pVB->Release(); g_pVB = NULL; }
        g_VertexBufferSize = draw_data->TotalVtxCount + 5000;
        if (g_pd3dDevice->CreateVertexBuffer(g_VertexBufferSize * sizeof(CUSTOMVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL) < 0)
            return;
    }
    if (!g_pIB || g_IndexBufferSize < draw_data->TotalIdxCount)
    {
        if (g_pIB) { g_pIB->Release(); g_pIB = NULL; }
        g_IndexBufferSize = draw_data->TotalIdxCount + 10000;
        if (g_pd3dDevice->CreateIndexBuffer(g_IndexBufferSize * sizeof(ImDrawIdx), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, sizeof(ImDrawIdx) == 2 ? D3DFMT_INDEX16 : D3DFMT_INDEX32, D3DPOOL_DEFAULT, &g_pIB, NULL) < 0)
            return;
    }

    // Backup the DX9 state
    IDirect3DStateBlock9* d3d9_state_block = NULL;
    if (g_pd3dDevice->CreateStateBlock(D3DSBT_ALL, &d3d9_state_block) < 0)
        return;

    // Copy and convert all vertices into a single contiguous buffer
    CUSTOMVERTEX* vtx_dst;
    ImDrawIdx* idx_dst;
    if (g_pVB->Lock(0, (UINT)(draw_data->TotalVtxCount * sizeof(CUSTOMVERTEX)), (void**)&vtx_dst, D3DLOCK_DISCARD) < 0)
        return;
    if (g_pIB->Lock(0, (UINT)(draw_data->TotalIdxCount * sizeof(ImDrawIdx)), (void**)&idx_dst, D3DLOCK_DISCARD) < 0)
        return;
    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];
        const ImDrawVert* vtx_src = cmd_list->VtxBuffer.Data;
        for (int i = 0; i < cmd_list->VtxBuffer.Size; i++)
        {
            vtx_dst->pos[0] = vtx_src->pos.x;
            vtx_dst->pos[1] = vtx_src->pos.y;
            vtx_dst->pos[2] = 0.0f;
            //vtx_dst->col = (vtx_src->col & 0xFF00FF00) | ((vtx_src->col & 0xFF0000)>>16) | ((vtx_src->col & 0xFF) << 16);     // RGBA --> ARGB for DirectX9
			vtx_dst->col = vtx_src->col;
			vtx_dst->uv[0] = vtx_src->uv.x;
            vtx_dst->uv[1] = vtx_src->uv.y;
            vtx_dst++;
            vtx_src++;
        }
        memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
        idx_dst += cmd_list->IdxBuffer.Size;
    }
    g_pVB->Unlock();
    g_pIB->Unlock();
    g_pd3dDevice->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));
    g_pd3dDevice->SetIndices(g_pIB);
    g_pd3dDevice->SetFVF(D3DFVF_CUSTOMVERTEX);

    // Setup viewport
    D3DVIEWPORT9 vp;
    vp.X = vp.Y = 0;
    vp.Width = (DWORD)io.DisplaySize.x;
    vp.Height = (DWORD)io.DisplaySize.y;
    vp.MinZ = 0.0f;
    vp.MaxZ = 1.0f;
    g_pd3dDevice->SetViewport(&vp);

    // Setup render state: fixed-pipeline, alpha-blending, no face culling, no depth testing
    g_pd3dDevice->SetPixelShader(NULL);
    g_pd3dDevice->SetVertexShader(NULL);
    g_pd3dDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
    g_pd3dDevice->SetRenderState(D3DRS_LIGHTING, false);
    g_pd3dDevice->SetRenderState(D3DRS_ZENABLE, false);
    g_pd3dDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
    g_pd3dDevice->SetRenderState(D3DRS_ALPHATESTENABLE, false);
    g_pd3dDevice->SetRenderState(D3DRS_BLENDOP, D3DBLENDOP_ADD);
    g_pd3dDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
    g_pd3dDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
    g_pd3dDevice->SetRenderState(D3DRS_SCISSORTESTENABLE, true);
    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_MODULATE);
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
    g_pd3dDevice->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
    g_pd3dDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
    g_pd3dDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);

    // Setup orthographic projection matrix
    // Being agnostic of whether <d3dx9.h> or <DirectXMath.h> can be used, we aren't relying on D3DXMatrixIdentity()/D3DXMatrixOrthoOffCenterLH() or DirectX::XMMatrixIdentity()/DirectX::XMMatrixOrthographicOffCenterLH()
    {
        const float L = 0.5f, R = io.DisplaySize.x+0.5f, T = 0.5f, B = io.DisplaySize.y+0.5f;
        D3DMATRIX mat_identity = { { 1.0f, 0.0f, 0.0f, 0.0f,  0.0f, 1.0f, 0.0f, 0.0f,  0.0f, 0.0f, 1.0f, 0.0f,  0.0f, 0.0f, 0.0f, 1.0f } };
        D3DMATRIX mat_projection =
        {
//.........这里部分代码省略.........
开发者ID:guillaumeguerin,项目名称:GWToolboxpp,代码行数:101,代码来源:imgui_impl_dx9.cpp

示例14: CreateVertexBuffer

//--------------------------------------
//NAME : CreateVertexBuffer()
//DESC : 创建图形顶点缓存
//--------------------------------------
void CreateVertexBuffer()
{
	//顶点缓存(Vertex Buffer)是Direct3D用来保存顶点数据的内存空间,可以位于系统内存和图形卡的显存中。
	//当Direct3D绘制图形时,将根据这些顶点结构创建一个三角形列表来描述物体的形状和轮廓
	/*
	在Direct3D中,顶点缓存由IDirect3DVertexBuffer9接口对象表示。在使用顶点缓存之前,需要定义描述顶点的顶点结构,然后可以通过IDirect3DDevice9接口的CreateVertexBuffer方法创建顶点缓存

	HRESULT IDirect3DDevice9::CreateVertexBuffer(
	UINT       Length,
	DWORD    Usage, //指定使用缓存的一些附加属性
	DWORD    FVF, //将要存储在顶点缓存中的灵活顶点格式
	D3DPOOL   Pool, //一个D3DPOOL枚举类型,用于指定存储顶点缓存或索引缓冲的内存位置,在默认情况下时位于显存中
	IDirect3DVertexBuffer9**  ppVertexBuffer, //IDirect3DVertexBuffer9接口类型的变量的指针,分别用于接收创建的顶点缓存和索引缓存的指针
	HANDLE*   pSharedHandle
	);

	*/
	//创建顶点缓存
	g_pd3dDevice->CreateVertexBuffer(8*sizeof(CUSTOMVERTEX),0,D3DFVF_CUSTOMVERTEX,D3DPOOL_DEFAULT,&g_pVertexBuf,NULL);

	//填充顶点数据
	CUSTOMVERTEX*pVertices=NULL;

	/*
	在取得IDirect3DVertexBuffer9接口对象的指针后,就可以通过这该接口的Lock方法获取指向顶点缓存的存储区的指针,并通过该指针访问缓存中的数据

	HRESULT IDirect3DVertexBuffer9::Lock(
	UINT     OffsetToLock, //在存储区中加锁的起始位置
	UINT     SizeToLock, //以字节为单位的加锁的存储区大小,值为0表示整个缓存存储区
	BYTE  **ppbData, //用于接收被锁定的存储区起始位置的指针,该参数指向的存储区的读写方式由Flags参数指定
	DWORD  Flags
	);

	*/

	//锁定缓存区
	g_pVertexBuf->Lock(0,0,(void**)&pVertices,0);
	pVertices[0]=CUSTOMVERTEX(-5.0f,5.0f,-5.0f,D3DCOLOR_XRGB(255,0,0));
	pVertices[1]=CUSTOMVERTEX(-5.0f,5.0f,5.0f,D3DCOLOR_XRGB(0,255,0));
	pVertices[2]=CUSTOMVERTEX(5.0f,5.0f,5.0f,D3DCOLOR_XRGB(0,0,255));
	pVertices[3]=CUSTOMVERTEX(5.0f,5.0f,-5.0f,D3DCOLOR_XRGB(255,255,0));
	pVertices[4]=CUSTOMVERTEX(-5.0f,-5.0f,-5.0f,D3DCOLOR_XRGB(0,0,255));
	pVertices[5]=CUSTOMVERTEX(-5.0f,-5.0f,5.0f,D3DCOLOR_XRGB(255,255,0));
	pVertices[6]=CUSTOMVERTEX(5.0f,-5.0f,5.0f,D3DCOLOR_XRGB(255,0,0));
	pVertices[7]=CUSTOMVERTEX(5.0f,-5.0f,-5.0f,D3DCOLOR_XRGB(0,255,0));

	//当使用Lock方法对应缓存区进行加锁并完成数据的访问后,需要调用IDirect3DVertexBuffer9接口的Unlock方法对缓存进行解锁
	g_pVertexBuf->Unlock();

	//创建索引缓存
	g_pd3dDevice->CreateIndexBuffer(36*sizeof(WORD),0,D3DFMT_INDEX16,D3DPOOL_DEFAULT,&g_pIndexBuf,NULL);

	//填充索引数据
	WORD*pIndices=NULL;
	g_pIndexBuf->Lock(0,0,(void**)&pIndices,0);

	//顶面由两个三角形组成
	pIndices[0]=0,pIndices[1]=1,pIndices[2]=2;
	pIndices[3]=0,pIndices[4]=2,pIndices[5]=3;

	//正面
	pIndices[6]=0,pIndices[7]=3,pIndices[8]=7;
	pIndices[9]=0,pIndices[10]=7,pIndices[11]=4;

	//左侧面
	pIndices[12]=0,pIndices[13]=4,pIndices[14]=5;
	pIndices[15]=0,pIndices[16]=5,pIndices[17]=1;

	//右侧面
	pIndices[18]=2,pIndices[19]=6,pIndices[20]=7;
	pIndices[21]=2,pIndices[22]=7,pIndices[23]=3;

	//背面
	pIndices[24]=2,pIndices[25]=5,pIndices[26]=6;
	pIndices[27]=2,pIndices[28]=1,pIndices[29]=5;

	//底面
	pIndices[30]=4,pIndices[31]=6,pIndices[32]=5;
	pIndices[33]=4,pIndices[34]=7,pIndices[35]=6;
	g_pIndexBuf->Unlock();
}
开发者ID:haozzzzzzzz,项目名称:Direct3D_Transform,代码行数:85,代码来源:transform.cpp

示例15: sizeof

BOOL jcd3d::jcd3d_setup()
{
	srand((UINT)time(NULL));

	lpd3dd->CreateVertexBuffer(
		CORNOR_AMOUNT * (LAYER_AMOUNT + 1) * sizeof(JCD3D_Vertex_xyz_diffuse), 
		D3DUSAGE_WRITEONLY, JCD3D_Vertex_xyz_diffuse::FVF, D3DPOOL_MANAGED, &lpvb, NULL
	);
	// i5----i6----i7----i8
	//  |   /|    / |   /|
	//  |  / |   /  |  / |
	//  | /  |  /   | /  |
	//  |/   | /    |/   |
	// i1----i2----i3----i4
	JCD3D_Vertex_xyz_diffuse* vb;
	FLOAT degreeInc = D3DX_PI * 2 / CORNOR_AMOUNT;
	FLOAT radiusDegree = 0;
	FLOAT radiusDegreeInc = D3DX_PI * 2 / LAYER_AMOUNT;
	lpvb->Lock(0, 0, (VOID**)&vb, 0);
	for(INT layer = 0; layer < LAYER_AMOUNT + 1; layer++)
	{
		for(INT corner = 0; corner < CORNOR_AMOUNT; corner++)
		{
			vb[layer * CORNOR_AMOUNT + corner] = JCD3D_Vertex_xyz_diffuse(
				cosf(corner * degreeInc) * RADIUS_MAX * cosf(radiusDegree), 
				layer * LAYER_HEIGHT, 
				sinf(corner * degreeInc) * RADIUS_MAX * cosf(radiusDegree), 
				rand() * 200 % 0xFFFFFF
			);
		}
		radiusDegree += radiusDegreeInc;
	}
	lpvb->Unlock();

	lpd3dd->CreateIndexBuffer(
		6 * CORNOR_AMOUNT * LAYER_AMOUNT * sizeof(WORD), 
		D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, D3DPOOL_MANAGED, &lpib, NULL
	);
	WORD* ib;
	INT ibIndex = 0;
	lpib->Lock(0, 0, (VOID**)&ib, 0);
	for (INT layer = 0; layer < LAYER_AMOUNT; layer++)
	{
		for(INT corner = 0; corner < CORNOR_AMOUNT; corner++)
		{
			// i1----i2
			//  |   /|
			//  |  / |
			//  | /  |
			//  |/   |
			// i3----i4
			WORD index1 = layer * CORNOR_AMOUNT + corner;
			WORD index2 = corner == CORNOR_AMOUNT - 1 ? layer * CORNOR_AMOUNT + 0 : layer * CORNOR_AMOUNT + corner + 1;
			WORD index3 = (layer + 1) * CORNOR_AMOUNT + corner;
			WORD index4 = corner == CORNOR_AMOUNT - 1 ? (layer + 1) * CORNOR_AMOUNT + 0 : (layer + 1) * CORNOR_AMOUNT + corner + 1;
			ib[ibIndex++] = index1;
			ib[ibIndex++] = index2;
			ib[ibIndex++] = index3;
			ib[ibIndex++] = index2;
			ib[ibIndex++] = index4;
			ib[ibIndex++] = index3;
		}
	}
	lpib->Unlock();

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(&proj, D3DX_PI * 0.5f, (FLOAT)WIN_WIDTH / (FLOAT)WIN_HEIGHT, 1.0f, 1000.0f);
	lpd3dd->SetTransform(D3DTS_PROJECTION, &proj);

	if(!jcd3d_initRenderState(lpd3dd, D3DCULL_NONE, FALSE, TRUE, D3DSHADE_GOURAUD, D3DFILL_WIREFRAME, FALSE))
	{
		return FALSE;
	}

	return TRUE;
}
开发者ID:chengkehan,项目名称:lab,代码行数:76,代码来源:main.cpp


注:本文中的LPDIRECT3DINDEXBUFFER9::Lock方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。