Ejemplo n.º 1
0
void D3DQuads_Begin (int numquads, quadvert_t **quadverts)
{
	D3DQuads_OnRecover ();

	D3D_SetStreamSource (0, d3d_QuadBuffer, 0, sizeof (quadvert_t));
	D3D_SetStreamSource (1, NULL, 0, 0);
	D3D_SetStreamSource (2, NULL, 0, 0);
	D3D_SetStreamSource (3, NULL, 0, 0);
	D3D_SetIndices (d3d_QuadIndexes);

	D3D_SetVertexDeclaration (d3d_QuadDecl);

	if (d3d_NumQuads + numquads >= D3D_MAX_QUADS)
	{
		d3d_QuadBuffer->Lock (0, 0, (void **) quadverts, d3d_GlobalCaps.DiscardLock);
		d3d_NumQuads = 0;
	}
	else
	{
		d3d_QuadBuffer->Lock (d3d_NumQuads * 4 * sizeof (quadvert_t),
			numquads * 4 * sizeof (quadvert_t),
			(void **) quadverts,
			d3d_GlobalCaps.NoOverwriteLock);
	}

	d3d_QuadsToDraw = numquads;
}
Ejemplo n.º 2
0
void initRectangleVertexes()
{
	VertexData data[4] = {
		/*   x          y           z       u   v   */
		{ 0, 0, 0, 0, 0 },
		{ Width, 0, 0, 1, 0 },
		{ 0, Height, 0, 0, 1 },
		{ Width, Height, 0, 1, 1 }
	};

	void *pRectBuffer = NULL;
	device->CreateVertexBuffer(4 * sizeof(VertexData), D3DUSAGE_WRITEONLY,
		D3DFVF_XYZ | D3DFVF_TEX0, D3DPOOL_DEFAULT, &pRectObject, NULL);

	pRectObject->Lock(0, 4 * sizeof(VertexData), &pRectBuffer, 0);

	memcpy(pRectBuffer, data, 4 * sizeof(VertexData));
	pRectObject->Unlock();

	D3DVERTEXELEMENT9 decl[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};

	device->CreateVertexDeclaration(decl, &RectDecl);
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
	// Initialize three vertices for rendering a triangle
	CUSTOMVERTEX g_Vertices[] =
	{
		{ -1.0f,-1.0f, 0.0f, 0xffff0000, },
		{  1.0f,-1.0f, 0.0f, 0xff0000ff, },
		{  0.0f, 1.0f, 0.0f, 0xffffffff, },
	};

	// Create the vertex buffer.
	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
	{
		return E_FAIL;
	}

	// Fill the vertex buffer.
	VOID* pVertices;
	if( FAILED( g_pVB->Lock( 0, sizeof(g_Vertices), (void**)&pVertices, 0 ) ) )
		return E_FAIL;
	memcpy( pVertices, g_Vertices, sizeof(g_Vertices) );
	g_pVB->Unlock();

	return S_OK;
}
Ejemplo n.º 4
0
// Prepare quad data, we build up a quad by combine two triangles
HRESULT InitVB()
{
	// Initialize three Vertices for rendering a triangle
	ScreenVertex Vertices[] =
	{
		{ 50.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 0
		{100.0f,  50.0f, 0.0f, 1.0f, 0xffff0000}, // 1
		{150.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 2
		{200.0f,  50.0f, 0.0f, 1.0f, 0xffff0000}, // 3
		{250.0f, 100.0f, 0.0f, 1.0f, 0xffff0000}, // 4
		{300.0f,  50.0f, 0.0f, 1.0f, 0xffff0000}, // 5
	};

	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 8* sizeof( ScreenVertex ),
		0, SCREEN_SPACE_FVF,
		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();

	return S_OK;
}
Ejemplo n.º 5
0
//-----------------------------------------------------------------------------
// Name: UpgradeGeometry()
//-----------------------------------------------------------------------------
HRESULT UpgradeGeometry( LONG lActualW, LONG lTextureW,
                         LONG lActualH, LONG lTextureH )
{
    HRESULT hr = S_OK;
    if( 0 == lTextureW || 0 == lTextureH )
    {
        return E_INVALIDARG;
    }
    FLOAT tuW = (FLOAT)lActualW / (FLOAT)lTextureW;
    FLOAT tvH = (FLOAT)lActualH / (FLOAT)lTextureH;

    // Fill the vertex buffer. We are setting the tu and tv texture
    // coordinates, which range from 0.0 to 1.0
    CUSTOMVERTEX* pVertices;
    if ( FAILED( hr = g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
    {
        Msg(TEXT("Could not lock the vertex buffer!  hr=0x%x"), hr);
        return E_FAIL;
    }

    for( DWORD i=0; i<nGrid; i++ )
    {
        FLOAT theta = (2*D3DX_PI*i)/(nGrid-1) + (FLOAT)(D3DX_PI/2.f);

        pVertices[2*i+0].tu       = tuW * ((FLOAT)i)/((FLOAT)nGrid-1.f);
        pVertices[2*i+0].tv       = tvH; 

        pVertices[2*i+1].tu       = tuW * ((FLOAT)i)/((FLOAT)nGrid-1.f);
        pVertices[2*i+1].tv       = 0.0f;
    }

    g_pVB->Unlock();
    return S_OK;
}
Ejemplo n.º 6
0
void Particles::intBuffers(LPDIRECT3DDEVICE9 d3ddev){
	D3DXCreateTextureFromFile(d3ddev,"white.png",&texture);

	struct CUSTOMVERTEX1 t_vert[] =
    {
		{-.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 0,},
        {-0.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 0,},
        {.05f, .05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 1, 1,},
        {.05f, -.05f, 0.0f, D3DCOLOR_XRGB(255, 255, 255), 0, 1,},
    };

    // create a vertex buffer interface called t_buffer
    d3ddev->CreateVertexBuffer(4*sizeof(CUSTOMVERTEX1),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &t_buffer,
                               NULL);

    VOID* pVoid;    // a void pointer

    // lock t_buffer and load the vertices into it
    t_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, t_vert, sizeof(t_vert));
    t_buffer->Unlock();

}
Ejemplo n.º 7
0
//-----------------------------------------------------------------------------
// Name: InitVB()
// Desc: Creates a vertex buffer and fills it with our vertices. The vertex
//       buffer is basically just a chuck of memory that holds vertices. After
//       creating it, we must Lock()/Unlock() it to fill it. For indices, D3D
//       also uses index buffers. The special thing about vertex and index
//       buffers is that they can be created in device memory, allowing some
//       cards to process them in hardware, resulting in a dramatic
//       performance gain.
//-----------------------------------------------------------------------------
HRESULT CDlg::InitVB()
{
    // Initialize three vertices for rendering a triangle
    CUSTOMVERTEX vertices[] =
    {
        { 150.0f,  50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
        { 250.0f, 250.0f, 0.5f, 1.0f, 0xffff0000, },
        {  50.0f, 250.0f, 0.5f, 1.0f, 0xffff0000, },
    };

    // Create the vertex buffer. Here we are allocating enough memory
    // (from the default pool) to hold all our 3 custom vertices. We also
    // specify the FVF, so the vertex buffer knows what data it contains.
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

    // Now we fill the vertex buffer. To do this, we need to Lock() the VB to
    // gain access to the vertices. This mechanism is required becuase vertex
    // buffers may be in device memory.
    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
    g_pVB->Unlock();

    return S_OK;
}
Ejemplo n.º 8
0
bool initializeObj() {
	//手动创建数组保存顶点数据
	unsigned INT colorInfo = D3DCOLOR_ARGB(1, 255, 255, 255);
	D3DVertexXYZRHW vertexData[] =
	{
		{ 10.0f, 10.0f, 0.0f, 1.0f, colorInfo },
		{ 200.0f, 10.0f, 0.0f, 1.0f, colorInfo },
		{ 10.0f, 200.0f, 0.0f, 1.0f, D3DCOLOR_ARGB(1, 0, 0, 0) },
		{ 200.0f, 200.0f, 0.0f, 1.0f, colorInfo },
		{ 400.0f, 200.0f, 0.0f, 1.0f, colorInfo },
		{ 200.0f, 400.0f, 0.0f, 1.0f, colorInfo },
	};

	//用D3D设备创建一个用于存放顶点数据的缓存
	if (FAILED(d3dDevice->CreateVertexBuffer(sizeof(vertexData), 0, D3DFVF_XYZRHW | D3DFVF_DIFFUSE,
											 D3DPOOL_DEFAULT, &d3dVertexBuf, NULL)))
		return false;

	//用ptr当媒介,向缓存填入顶点数据
	VOID *ptr;
	if (FAILED(d3dVertexBuf->Lock(0, sizeof(vertexData), (VOID**)&ptr, 0)))
		return false;
	memcpy(ptr, vertexData, sizeof(vertexData));
	d3dVertexBuf->Unlock();

	return true;
}
Ejemplo n.º 9
0
//---------------------------------------------------------------------------------
// Name: ComputeBoundingBox
// Desc: 
// pMin:[out] Pointer to a D3DXVECTOR3 structure, describing the returned lower-left 
// corner of the bounding box. See Remarks. 
// pMax:[out] Pointer to a D3DXVECTOR3 structure, describing the returned upper-right 
// corner of the bounding box. See Remarks.
//---------------------------------------------------------------------------------
FLOAT CD3DMesh::ComputeBoundingBox(D3DXVECTOR3 *pMin, D3DXVECTOR3 *pMax )
{
	HRESULT hr;
	 // Lock the vertex buffer, to generate a simple bounding sphere
	LPDIRECT3DVERTEXBUFFER9 pMeshVB   = NULL;

	hr = m_pSysMemMesh->GetVertexBuffer( &pMeshVB );
    if( SUCCEEDED(hr) )
    {
		VOID *       pVertices;
        hr = pMeshVB->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
        if( SUCCEEDED(hr) )
        {
            hr = D3DXComputeBoundingBox( (D3DXVECTOR3 *)pVertices, 
                                            m_pSysMemMesh->GetNumVertices(),
                                            D3DXGetFVFVertexSize(m_pSysMemMesh->GetFVF()),
                                            pMin,
											pMax);
            pMeshVB->Unlock();
        }
        pMeshVB->Release();
    }
    if( FAILED(hr) )
		return 0;   
	return 1;
}
Ejemplo n.º 10
0
LPDIRECT3DVERTEXBUFFER9 OvRenderer::CreateVertexStream( void* buffer, UINT stride, UINT count )
{
	OvDevice device = GetDevice();
	if ( device )
	{
		LPDIRECT3DVERTEXBUFFER9 vertexStream = NULL;
		UINT streamSize = count * stride;
		HRESULT hr = device->CreateVertexBuffer
			( streamSize
			, 0
			, 0
			, D3DPOOL_MANAGED
			, &vertexStream
			, NULL
			);
		if ( SUCCEEDED(hr) && vertexStream )
		{
			void* copyDest = NULL;
			if ( SUCCEEDED(vertexStream->Lock( 0, streamSize, &copyDest, 0)) && copyDest)
			{
				memcpy( copyDest, buffer, streamSize );
				vertexStream->Unlock();
				return vertexStream;
			}
		}
	}
	return NULL;
}
Ejemplo n.º 11
0
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
    HRESULT hr;

    m_pFont->InitDeviceObjects( m_pd3dDevice );

	ilInit();
	iluInit();
	ilutInit();
	ilutD3D8TexFromFile(m_pd3dDevice, __argv[1], &m_pTexture);
	//D3DXCreateTextureFromFile(m_pd3dDevice, __argv[1], &m_pTexture);

    // Create a vertex buffer
    {
        if( FAILED( hr = m_pd3dDevice->CreateVertexBuffer( 4*sizeof(VERTEX),
                                           D3DUSAGE_WRITEONLY,
                                           D3DFVF_VERTEX,
                                           D3DPOOL_MANAGED, &m_pVB ) ) )
            return hr;

        VERTEX* pVertices;
        m_pVB->Lock( 0, 4*sizeof(VERTEX), (BYTE**)&pVertices, 0 );
        memcpy( pVertices, g_vVertices, sizeof(VERTEX)*4 );
        m_pVB->Unlock();
    }

    return S_OK;
}
Ejemplo n.º 12
0
//------------------------------------------------------------------------------
HRESULT init_vertex_buffer()
{
    CUSTOMVERTEX vertices[] = {
		{ -1,  1,  1 , 0xFFFF0000 },		/// v0
		{  1,  1,  1 , 0xFF00FF00 },		/// v1
		{  1,  1, -1 , 0xFF0000FF },		/// v2
		{ -1,  1, -1 , 0xFFFFFF00 },		/// v3

		{ -1, -1,  1 , 0xFF00FFFF },		/// v4
		{  1, -1,  1 , 0xFFFF00FF },		/// v5
		{  1, -1, -1 , 0xFF000000 },		/// v6
		{ -1, -1, -1 , 0xFFFFFFFF },		/// v7
    };

    if (FAILED( g_pd3dDevice->CreateVertexBuffer( 8*sizeof(CUSTOMVERTEX),
                                                  0, D3DFVF_CUSTOMVERTEX,
                                                  D3DPOOL_DEFAULT, &g_pVertexBuff, NULL )))
        return E_FAIL;

    VOID* pVertices;
    if (FAILED( g_pVertexBuff->Lock( 0, sizeof(vertices), (void**)&pVertices, 0 )))
        return E_FAIL;
    memcpy( pVertices, vertices, sizeof(vertices) );
    g_pVertexBuff->Unlock();

    return S_OK;
}
Ejemplo n.º 13
0
//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Creates the scene geometry
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
    // Create the vertex buffer.
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
                0, D3DFVF_CUSTOMVERTEX,
                D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

    // Fill the vertex buffer. We are algorithmically generating a cylinder
    // here, including the normals, which are used for lighting.
    CUSTOMVERTEX* pVertices;
    if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    for( DWORD i=0; i<50z; i++ )
    {
        FLOAT theta = (2*D3DX_PI*i)/(50-1);
        pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
        pVertices[2*i+0].normal   = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
        pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
        pVertices[2*i+1].normal   = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
    }
    g_pVB->Unlock();

    return S_OK;
}
Ejemplo n.º 14
0
HRESULT InitializeVertexBuffer()
{
	//Store each point of the triangle together with its color
	CUSTOMVERTEX cvVertices[] =
	{
		{-10.f, 0.f, 0.f, D3DCOLOR_XRGB(255, 0, 0)},
		{0.f, 0.f, 10.f, D3DCOLOR_XRGB(0, 255, 0)},
		{10.f, 0.f, 0.f, D3DCOLOR_XRGB(0, 0, 255)}
	};

	//Create the vertex buffer
	if(FAILED(g_pD3DDevice->CreateVertexBuffer(sizeof(cvVertices), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVertexBuffer, 0)))
		return E_FAIL;

	//Get a pointer to the vertex buffer vertices and lock the vertex buffer
	void* pVertices = 0;
	if(FAILED(g_pVertexBuffer->Lock(0, sizeof(cvVertices), &pVertices, 0)))
		return E_FAIL;

	//Copy our stored vertices value into the vertex buffer
	memcpy(pVertices, cvVertices, sizeof(cvVertices));

	g_pVertexBuffer->Unlock();

	return S_OK;
}
Ejemplo n.º 15
0
Archivo: Main.cpp Proyecto: bafory/DTX
HRESULT InitialBufferVershin() {


	/*
	Вершины примитивов
	*/
    CUSTOMVERTEX Vershin[] =
    {
		
        {xLength, 0.0f, 0.0f, 0xffff0000 },
        {0.0f, 0.0f, 0.0f,  0x00000fff},
        {0.0f,  yHeight, 0.0f, 0xff00ff00 },

	    {xLength, 0.0f, 0.0f, 0xffff0000 },
	    {0, yHeight, 0.0f, 0xff00ff00 },
	    {xLength, yHeight, 0.0f,  0x00000fff },
		
    };

	/*-----------------------------------------------------------------------------------------------*/

	/*
	Для хранения вершин предназначен специальный буфер вершин.
	1.  задает размер буфера вершин в байтах.
	2.  определяет параметры работы с буфером и, как правило, всегда это значение выставляется в ноль. 
	3.  задает формат вершин буфера через набор FVF флагов.
	4.  определяет месторасположение буфера вершин. Значение D3DPOOL_DEFAULT говорит о том,
	    что библиотека сама позаботится о размещении буфера в памяти. 
    5.  задает адрес переменной, в которую будет помещен результат вызова метода,
	    т.е. эта переменная будет хранить адрес буфера вершин.
	6.  является зарезервированным в настоящее время и всегда должен быть пустым.
	*/
    if (FAILED(g_pd3dDevice->CreateVertexBuffer(6*sizeof(CUSTOMVERTEX), 
                                                    0, D3DFVF_CUSTOMVERTEX, 
                                                    D3DPOOL_DEFAULT, 
                                                    &pBufferVershin, NULL)))
        return E_FAIL;

	/*-----------------------------------------------------------------------------------------------*/

	/*
	Заполнить буфер данными о вершинах. Этот шаг реализуется в три приема.
	Вначале необходимо запереть буфер, т.к. заполнение его может производиться только 
	в закрытом состоянии. Достигается это вызовом метода Lock интерфейса 
	IDirect3DVertexBuffer9. Второй шаг состоит в непосредственном копировании данных 
	с помощью стандартной функции Win32API – memcpy(). И третий шаг заключается
	в отпирании буфера вершин с помощью метода Unlock интерфейса IDirect3DVertexBuffer9. 
	1. смещение от начала буфера, с которого будет производиться запирание области
	   (значение 0 указывает на то, что запирается весь буфер с самого начала)
	2. задает размер запираемой области в байтах
	3. параметр возвращает адрес запираемой области 
	4. задает набор флагов способа запирания и, как правило, всегда равен нулю.
	*/
    VOID* pBV;
    if (FAILED(pBufferVershin->Lock(0, sizeof(Vershin), (VOID**)&pBV, 0)))
        return E_FAIL;
    memcpy(pBV, Vershin, sizeof(Vershin));
    pBufferVershin->Unlock();
       return S_OK;
}
Ejemplo n.º 16
0
HRESULT InitVB()
{

    CUSTOMVERTEX Vertices[] =
    {
        { 150.0f,  50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
        { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
        {  50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
    };

    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3 * 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();

    return S_OK;
}
Ejemplo n.º 17
0
// Prepare vertex buffer
void InitVB()
{
	Vertex Quad[] = 
	{
		{-2.0f,  2.0f, 0,    0,    0},	
		{ 2.0f,  2.0f, 0, 3.0f,    0},	// repeat 3 times on x and y
		{-2.0f, -2.0f, 0,    0, 3.0f},	
		{ 2.0f, -2.0f, 0, 3.0f, 3.0f},	

		// scale effect
		/*{-2.0f,  2.0f, 0,    0,    0},	
		{ 2.0f,  2.0f, 0, 0.5f,    0},	
		{-2.0f, -2.0f, 0,    0, 0.5f},	
		{ 2.0f, -2.0f, 0, 0.5f, 0.5f},*/
	} ;

	// Create vertex buffer
	HRESULT hr ;
	hr = g_pd3dDevice->CreateVertexBuffer(4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, 
		VertexFVF, D3DPOOL_MANAGED, &g_pVB, NULL) ;
	if (FAILED(hr))
	{
		MessageBoxA(NULL, "Create vertex buffer failed!", "Error", 0) ;
	}

	// Copy data
	Vertex* v ;
	g_pVB->Lock(0, 0, (void**)&v, 0) ;
	memcpy(v, Quad, 4 * sizeof(Vertex)) ;
	g_pVB->Unlock() ;
}
Ejemplo n.º 18
0
void InitVertexBuffer()
{
	// Define vertex data
	Vertex Quad[] =
	{
		{-25.0f,  0.0f, 0.0f, 0.0f, 1.0f}, // 0
		{-25.0f, 50.0f, 0.0f, 0.0f, 0.0f}, // 1
		{ 25.0f,  0.0f, 0.0f, 1.0f, 1.0f}, // 3
		{ 25.0f, 50.0f, 0.0f, 1.0f, 0.0f}, // 2
	} ;

	// Create vertex buffer
	HRESULT hr ;
	hr = g_pd3dDevice->CreateVertexBuffer(4 * sizeof(Vertex), D3DUSAGE_WRITEONLY, 
		Vertex_FVF, D3DPOOL_MANAGED, &g_pVB, NULL) ;
	if (FAILED(hr))
	{
		DXTRACE_ERR_MSGBOX(DXGetErrorString(hr), hr) ;
	}

	// Fill vertex buffer
	Vertex* v ;
	g_pVB->Lock(0, 0, (void**)&v, 0) ;
	memcpy(v, Quad, 4 * sizeof(Vertex)) ;
	g_pVB->Unlock() ;
}
Ejemplo n.º 19
0
void SetTexturePlaybar(	int nIdx,					//记录当前对应的图组地址
						int nPatternAnim,			//记录当前显示帧
						int numAnimPattern, 		//记录当前对应的组成图组的图片数量
						int texPatternDivideX,		//记录当前图组X轴图片数量
						int texPatternDivideY )		//记录当前图组Y轴图片数量
{
	{//頂点バッファの中身を埋める
		VERTEX_2D *pVtx;
		float fPosXLeft, fPosXRight;
		float fPosYUp, fPosYDown;

		// 頂点データの範囲をロックし、頂点バッファへのポインタを取得
		g_pD3DVtxBuffPlaybar->Lock(0, 0, (void**)&pVtx, 0);

		pVtx += (nIdx * 4);

		// テクスチャ座標の設定 纹理坐标设定
		fPosXLeft = (float)(nPatternAnim % texPatternDivideX) * 1.0f / texPatternDivideX;
		fPosXRight = (float)(nPatternAnim % texPatternDivideX) * 1.0f / texPatternDivideX + 1.0f / texPatternDivideX;
		fPosYUp = (float)(nPatternAnim / (numAnimPattern / texPatternDivideY)) * 1.0f / texPatternDivideY;
		fPosYDown = (float)(nPatternAnim / (numAnimPattern / texPatternDivideY)) * 1.0f / texPatternDivideY + 1.0f / texPatternDivideY;

		pVtx[0].tex = D3DXVECTOR2(fPosXLeft, fPosYUp);
		pVtx[1].tex = D3DXVECTOR2(fPosXRight, fPosYUp);
		pVtx[2].tex = D3DXVECTOR2(fPosXLeft, fPosYDown);
		pVtx[3].tex = D3DXVECTOR2(fPosXRight, fPosYDown);

		// 頂点データをアンロックする
		g_pD3DVtxBuffPlaybar->Unlock();
	}
}
Ejemplo n.º 20
0
HRESULT init_geometry()
{
    { // try create vertex buffer
        HRESULT hr = g_pd3dDevice->CreateVertexBuffer( 50 * 2 * sizeof(CUSTOMVERTEX),
                                                      0, D3DFVF_CUSTOMVERTEX,
                                                      D3DPOOL_DEFAULT, &g_pVertexBuff, NULL );
        if ( FAILED( hr ) ) return E_FAIL;
    }

    { // try fill vertex buffer
        CUSTOMVERTEX* pVertices;

        HRESULT hr = g_pVertexBuff->Lock( 0, 0, (void**)&pVertices, 0 );
        if( FAILED( hr ) ) return E_FAIL;

        for (int i = 0; i < 50; ++i) {
            float angle = ( 2 * D3DX_PI * i) / (50 - 1 );
            float sin = sinf(angle);
            float cos = cosf(angle);

            pVertices[ 2 * i + 0 ].pos    = D3DXVECTOR3( sin, -1.0f, cos );
            pVertices[ 2 * i + 0 ].normal = D3DXVECTOR3( sin,  0.0f, cos );
            pVertices[ 2 * i + 1 ].pos    = D3DXVECTOR3( sin,  1.0f, cos );
            pVertices[ 2 * i + 1 ].normal = D3DXVECTOR3( sin,  0.0f, cos );
        }
        g_pVertexBuff->Unlock();
    }

    return S_OK;
}
Ejemplo n.º 21
0
//-----------------------------------------------------------------------------
// Desc: 创建场景图形
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
	//创顶点缓冲区
	if( FAILED( g_pd3dDevice->CreateVertexBuffer( 50*2*sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
	{
		return E_FAIL;
	}

	//填充顶点缓冲区
	CUSTOMVERTEX* pVertices;
	if( FAILED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
		return E_FAIL;
	for( DWORD i=0; i<50; i++ )
	{
		FLOAT theta = (2*D3DX_PI*i)/(50-1);
		pVertices[2*i+0].position = D3DXVECTOR3( sinf(theta),-1.0f, cosf(theta) );
		pVertices[2*i+0].normal   = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
		pVertices[2*i+1].position = D3DXVECTOR3( sinf(theta), 1.0f, cosf(theta) );
		pVertices[2*i+1].normal   = D3DXVECTOR3( sinf(theta), 0.0f, cosf(theta) );
	}
	g_pVB->Unlock();

	return S_OK;
}
Ejemplo n.º 22
0
bool InitImg()
{
	// 创建顶点缓存
	if( FAILED(g_pd3dD->CreateVertexBuffer(sizeof(Vertex)*4, 0, VertexFVF, D3DPOOL_MANAGED, &lpVB, NULL)) )
		return false;

	Vertex* pVertices;
	if( FAILED(lpVB->Lock( 0, 0, (void**)&pVertices, 0 )) )
		return false;

	pVertices[0] = Vertex(0.0f, 0.0f		,		0.0f, 0.0f);
	pVertices[1] = Vertex(0.0f, 1.0f		,		0.0f, 1.0f);
	pVertices[2] = Vertex(1.0f, 0.0f		,		1.0f, 0.0f);
	pVertices[3] = Vertex(1.0f, 1.0f		,		1.0f, 1.0f);
	lpVB->Unlock();

	//初始化texlist
	for(int i=0;i<65535;i++)
	{
		texlist_headp[i] = 0;
		texlist_nowp[i] = 0;
	}

	// 初始化着色器
	if(!InitEffect())
		return false;

	return true;
}
Ejemplo n.º 23
0
//-----------------------------------------------------------------------------
// Name: CalculateShades()
// Desc: Calculates shades of vertices depending on current time and background color
//-----------------------------------------------------------------------------
void CalculateShades()
{
    float cost = (float)cos(timeGetTime()/2000.0f - g_StartTime);

    static BYTE btRed1, btGrn1, btBlu1;
    static BYTE btRed2, btGrn2, btBlu2;

    CUSTOMVERTEX* pVertices = 0;
    if ( SUCCEEDED( g_pVB->Lock( 0, 0, (void**)&pVertices, 0 ) ) )
    {
        {
            btRed1 = (BYTE)(((0xFF-bkRed)*cost + (0xFF+bkRed))/2);
            btGrn1 = (BYTE)(((0xFF-bkGrn)*cost + (0xFF+bkGrn))/2);
            btBlu1 = (BYTE)(((0xFF-bkBlu)*cost + (0xFF+bkBlu))/2);
        }

        {
            btRed2 = (BYTE)(((bkRed-0xFF)*cost + (0xFF+bkRed))/2);
            btGrn2 = (BYTE)(((bkGrn-0xFF)*cost + (0xFF+bkGrn))/2);
            btBlu2 = (BYTE)(((bkBlu-0xFF)*cost + (0xFF+bkBlu))/2);
        }

        for( DWORD i=0; i<nGrid; i++ )
        {
            pVertices[2*i+0].color    = D3DCOLOR_XRGB(btRed1, btGrn1, btBlu1);
            pVertices[2*i+1].color    = D3DCOLOR_XRGB(btRed2, btGrn2, btBlu2);
        }
        g_pVB->Unlock();
    }
}
Ejemplo n.º 24
0
	void set_vertex(
		unsigned px, unsigned py, unsigned pw, unsigned ph,
		unsigned tw, unsigned th,
		unsigned x,  unsigned y,  unsigned w,  unsigned h
	)
	{
		d3dvertex vertex[4];
		vertex[0].x = vertex[2].x = (double)(x     - 0.5);
		vertex[1].x = vertex[3].x = (double)(x + w - 0.5);
		vertex[0].y = vertex[1].y = (double)(y     - 0.5);
		vertex[2].y = vertex[3].y = (double)(y + h - 0.5);

		vertex[0].z = vertex[1].z = vertex[2].z = vertex[3].z = 0.0;
		vertex[0].rhw = vertex[1].rhw = vertex[2].rhw = vertex[3].rhw = 1.0;

		double rw = (double)w / (double)pw * (double)tw;
		double rh = (double)h / (double)ph * (double)th;
		vertex[0].u = vertex[2].u = (double)(px    ) / rw;
		vertex[1].u = vertex[3].u = (double)(px + w) / rw;
		vertex[0].v = vertex[1].v = (double)(py    ) / rh;
		vertex[2].v = vertex[3].v = (double)(py + h) / rh;

		lpvbuf->Lock( 0, sizeof( d3dvertex ) * 4, ( void ** ) &vertex_ptr, 0 );
		memcpy( vertex_ptr, vertex, sizeof( d3dvertex ) * 4 );
		lpvbuf->Unlock();

		lpdev->SetStreamSource( 0, lpvbuf, 0, sizeof( d3dvertex ) );
	}
Ejemplo n.º 25
0
		LPDIRECT3DVERTEXBUFFER9 CreateVertexBuffer( LPDIRECT3DDEVICE9 device, OvByte* buffer, OvSize bufsize )
		{
			if ( device && buffer && bufsize )
			{
				LPDIRECT3DVERTEXBUFFER9 vertexStream = NULL;
				HRESULT hr = device->CreateVertexBuffer
					( bufsize
					, 0
					, 0
					, D3DPOOL_MANAGED
					, &vertexStream
					, NULL
					);
				if ( SUCCEEDED(hr) && vertexStream )
				{
					void* copyDest = NULL;
					if ( SUCCEEDED(vertexStream->Lock( 0, bufsize, &copyDest, 0)) && copyDest)
					{
						memcpy( copyDest, buffer, bufsize );
						vertexStream->Unlock();
						return vertexStream;
					}
				}
			}
			return NULL;
		}
Ejemplo n.º 26
0
/**-----------------------------------------------------------------------------
 * 정점버퍼를 생성하고 정점값을 채워넣는다.
 *------------------------------------------------------------------------------
 */
HRESULT InitVB()
{
	MYVERTEX Verts[3];
	Verts[0].p = D3DXVECTOR3(  0.0f,  1.0f, 0.0f );
	Verts[1].p = D3DXVECTOR3(  1.0f, -1.0f, 0.0f );
	Verts[2].p = D3DXVECTOR3( -1.0f, -1.0f, 0.0f );
	Verts[0].d = 0xffff0000;
	Verts[1].d = 0xff00ff00;
	Verts[2].d = 0xff0000ff;
	Verts[0].t = D3DXVECTOR2( 0.5f, 0.0f );
	Verts[1].t = D3DXVECTOR2( 1.0f, 1.0f );
	Verts[2].t = D3DXVECTOR2( 0.0f, 1.0f );

    /// 정점버퍼 생성
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(MYVERTEX), 0, MYVERTEX::FVF, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) )
    {
        return E_FAIL;
    }

    /// 정점버퍼를 값으로 채운다. 
    VOID* pVertices;
    if( FAILED( g_pVB->Lock( 0, sizeof(Verts), (void**)&pVertices, 0 ) ) )
        return E_FAIL;
    memcpy( pVertices, Verts, sizeof(Verts) );
    g_pVB->Unlock();


	return S_OK;
}
Ejemplo n.º 27
0
extern "C" void D3DChangeTextureSize(int w,int h)
{
	/*
	Makes sure the 3D object was built.
	It might not be, since this function is called by the video pipeline
	thread which can start before the Direct3D thread.
	*/
	if (g_pVB==NULL) return;

	if (w!=videoWidth || h!=videoHeight)
	{
	videoWidth  = min(w,DRONE_VIDEO_MAX_WIDTH);
	videoHeight = min(h,DRONE_VIDEO_MAX_HEIGHT);

	/* 
	Change the texture coordinates for the 3D object which renders the video.
	The texture buffer has a fixed and large size, but only part of it is filled 
	by D3DChangeTexture.
	*/
	CUSTOMVERTEX* pVertices;
    if( !FAILED( g_pVB->Lock( 0, 0, ( void** )&pVertices, 0 ) ) )
	{
		float scaleFactorW = (float)(videoWidth) /(float)(TEXTURE_WIDTH);
		float scaleFactorH = (float)(videoHeight)/(float)(TEXTURE_HEIGHT);

		pVertices[0].tu = 0.0f;            pVertices[0].tv = 0.0f; 
		pVertices[1].tu = scaleFactorW;    pVertices[1].tv = 0.0f; 
		pVertices[2].tu = 0.0f;            pVertices[2].tv = scaleFactorH; 
		pVertices[3].tu = scaleFactorW;    pVertices[3].tv = scaleFactorH;

		g_pVB->Unlock();
	}}
}
Ejemplo n.º 28
0
// this is the function that puts the 3D models into video RAM
void init_graphics(void)
{
    // create the vertices using the CUSTOMVERTEX struct
    CUSTOMVERTEX vertices[] =
    {
        { 3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(0, 0, 255), },
        { 0.0f, 3.0f, 0.0f, D3DCOLOR_XRGB(0, 255, 0), },
        { -3.0f, -3.0f, 0.0f, D3DCOLOR_XRGB(255, 0, 0), },
    };

    // create a vertex buffer interface called v_buffer
    d3ddev->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),
                               0,
                               CUSTOMFVF,
                               D3DPOOL_MANAGED,
                               &v_buffer,
                               NULL);

    VOID* pVoid;    // a void pointer

    // lock v_buffer and load the vertices into it
    v_buffer->Lock(0, 0, (void**)&pVoid, 0);
    memcpy(pVoid, vertices, sizeof(vertices));
    v_buffer->Unlock();
}
Ejemplo n.º 29
0
//-----------------------------------------------------------------------------
// Desc: 创建并填充顶点缓冲区
//-----------------------------------------------------------------------------
HRESULT InitVB()
{
    //顶点数据
    CUSTOMVERTEX vertices[] =
    {
        {  50.0f, 250.0f, 0.5f, 1.0f, 0xffff0000, },
        { 150.0f,  50.0f, 0.5f, 1.0f, 0xff00ff00, },
        { 250.0f, 250.0f, 0.5f, 1.0f, 0xff0000ff, },

    };

    //创建顶点缓冲区
    if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*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();

    return S_OK;
}
Ejemplo n.º 30
0
void initVertexData()
{
	size_t count = partCount;
	VertexData *vertexData = new VertexData[count];

	for(size_t i = 0; i < count; ++i)
	{
		vertexData[i].x = particlesCoord[i].x;
		vertexData[i].y = particlesCoord[i].y;
		vertexData[i].z = 0.f;
		vertexData[i].u = 0;
		vertexData[i].v = 0;
	}

	void *pRectBuffer = NULL;
	device->CreateVertexBuffer(count*sizeof(VertexData), D3DUSAGE_WRITEONLY,
		D3DFVF_XYZ | D3DFVF_TEX0, D3DPOOL_DEFAULT, &pVertexObject, NULL);

	pVertexObject->Lock(0, count*sizeof(VertexData), &pRectBuffer, 0);

	memcpy(pRectBuffer, vertexData, count*sizeof(VertexData));
	pVertexObject->Unlock();

	delete[] vertexData;
	vertexData = nullptr;

	D3DVERTEXELEMENT9 decl[] =
	{
		{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
		{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
		D3DDECL_END()
	};

	device->CreateVertexDeclaration(decl, &vertexDecl);
}