Exemplo n.º 1
0
HRESULT Kinect::InitVB()
{
	//InitMesh();

	float u, v;
	u = 640.0f / 1024.0f;
	v = 480.0f / 1024.0f;
	/// »ï°¢ÇüÀ» ·»´õ¸µÇϱâÀ§ÇØ ¼¼°³ÀÇ Á¤Á¡À» ¼±¾ð
	CUSTOMVERTEX vertices[] =
	{
		{ -6.4f, -4.8f, 0.0f, 0, v },
		{ -6.4f, 4.8f, 0.0f, 0, 0 },
		{ 6.4f, -4.8f, 0.0f, u, v }, // x, y, z, color
		{ 6.4f, 4.8f, 0.0f, u, 0 },

	};
	/// Á¤Á¡¹öÆÛ »ý¼º
	/// 3°³ÀÇ »ç¿ëÀÚÁ¤Á¡À» º¸°üÇÒ ¸Þ¸ð¸®¸¦ ÇÒ´çÇÑ´Ù.
	/// FVF¸¦ ÁöÁ¤ÇÏ¿© º¸°üÇÒ µ¥ÀÌÅÍÀÇ Çü½ÄÀ» ÁöÁ¤ÇÑ´Ù.
	if (FAILED(g_pDevice->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_MANAGED, &m_pVB, NULL)))
	{
		return E_FAIL;
	}



	/// Á¤Á¡¹öÆÛ¸¦ °ªÀ¸·Î ä¿î´Ù. 
	/// Á¤Á¡¹öÆÛÀÇ Lock()ÇÔ¼ö¸¦ È£ÃâÇÏ¿© Æ÷ÀÎÅ͸¦ ¾ò¾î¿Â´Ù.
	VOID* pVertices;
	if (FAILED(m_pVB->Lock(0, sizeof(vertices), (void**)&pVertices, 0)))
		return E_FAIL;
	memcpy(pVertices, vertices, sizeof(vertices));
	m_pVB->Unlock();

	CUSTOMVERTEX Groundvertices[] =
	{
		{ 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_pDevice->CreateVertexBuffer(4 * sizeof(CUSTOMVERTEX),
		0, D3DFVF_CUSTOMVERTEX,
		D3DPOOL_MANAGED, &m_RectVB, NULL)))
	{
		return E_FAIL;
	}
	VOID* psVertices;
	if (FAILED(m_RectVB->Lock(0, sizeof(Groundvertices), (void**)&psVertices, 0)))
		return E_FAIL;
	memcpy(psVertices, Groundvertices, sizeof(Groundvertices));
	m_RectVB->Unlock();

	m_ballcreate = 0.0f;



	return S_OK;
}
Exemplo n.º 2
0
/************************************************************
Init

Sets the bounds, tesselation, hieght of the water plane
and allocates triangulated mesh;
************************************************************/
void WaterField::Init(float xmin, float xmax, float ymin, float ymax, int xdivs, int ydivs, float height, float elasticity, float viscosity, float tension, float blendability, bool textureMode)
{
	myXmin = xmin;
	myYmin = ymin;
	myXmax = xmax;
	myYmax = ymax;
	myXdivs = xdivs;
	myYdivs = ydivs;
	myHeight = height;
	
  m_xdivdist = (float)(myXmax - myXmin) / (float)myXdivs;
	m_ydivdist = (float)(myYmax - myYmin) / (float)myYdivs;

	m_viscosity = viscosity;
	m_elasticity = elasticity;
	m_tension = tension;
  m_blendability = blendability;
  m_textureMode = textureMode;

	myPoints = new WaterPoint*[xdivs];
	for(int i = 0; i < xdivs; i++)
	{
	 myPoints[i] = new WaterPoint[ydivs];
	 for(int j = 0; j < ydivs; j++)
	 {
		myPoints[i][j].height = 0;
		myPoints[i][j].velocity = 0;
    myPoints[i][j].color = 0xFF808080;
    myPoints[i][j].avecolor = 0xFF000000;
	 }
	}

	//Create the vertex buffer from our device
  if (m_textureMode)
  {
    g_pd3dDevice->CreateVertexBuffer(2 * myYdivs *  sizeof(TEXTUREDVERTEX),
                                               0, 
                                               D3DFVF_TEXTUREDVERTEX,
                                               D3DPOOL_DEFAULT, 
                                               &g_pVertexBuffer,
                                               NULL);
  }
  else
  {
    g_pd3dDevice->CreateVertexBuffer(2 * myYdivs*  sizeof(COLORVERTEX),
                                               0, 
                                               D3DFVF_COLORVERTEX,
                                               D3DPOOL_DEFAULT, 
                                               &g_pVertexBuffer,
                                               NULL);    
  }

}
Exemplo n.º 3
0
// 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();

}
Exemplo n.º 4
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() ;
}
Exemplo n.º 5
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();

}
Exemplo n.º 6
0
BOOL FSCreateDynamic2dVertexBuffer(RENDEROBJECT *renderObject, int numVertices)
{
//	assert (numVertices < 10000);

	assert (renderObject->lpVertexBuffer == NULL);

// this is not good cause LEVELRENDEROBJECT is of a diff size...
//	memset(renderObject, 0, sizeof(RENDEROBJECT));

	renderObject->vbLocked = 0;

	LastError = lpD3DDevice->CreateVertexBuffer(
		numVertices * sizeof(TLVERTEX), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, D3DFVF_TLVERTEX,
		D3DPOOL_DEFAULT, (LPDIRECT3DVERTEXBUFFER9*)&renderObject->lpVertexBuffer, NULL
	);

	//LastError = lpD3DDevice->CreateVertexBuffer(numVertices * sizeof(TLVERTEX), 0, D3DFVF_TLVERTEX, D3DPOOL_MANAGED, &renderObject->lpVertexBuffer, NULL);
	if (FAILED(LastError))
	{
		DebugPrintf("can't create vertex buffer\n");
		return FALSE;
	}

	return TRUE;
}
Exemplo n.º 7
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);
}
Exemplo n.º 8
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;
}
Exemplo n.º 9
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;
}
Exemplo n.º 10
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() ;
}
Exemplo n.º 11
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;
}
Exemplo n.º 12
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;
}
Exemplo n.º 13
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;
}
Exemplo n.º 14
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;
}
Exemplo n.º 15
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;
}
Exemplo n.º 16
0
//頂点バッファをインデックスバッファを生成
void Vertices::CreateBuffer(LPDIRECT3DDEVICE9 pD3DDevice, DWORD Usage, D3DPOOL Pool)
{
	Release(); //頂点バッファとインデックスバッファを解放

	//頂点バッファを作成
	if (vectorD3DVERTEX.size())
	{
		pD3DDevice->CreateVertexBuffer(vectorD3DVERTEX.size() * sizeof(D3DVERTEX), Usage, D3DVERTEX::FVF, Pool, &pVertexBuffer, NULL);
		if (pVertexBuffer) //頂点バッファの作成に成功した場合
		{
			LPVOID pBuffer; //バッファの内容を示すポインタ
			pVertexBuffer->Lock(0, 0, &pBuffer, 0); //バッファをロック
			memcpy(pBuffer, &vectorD3DVERTEX.at(0), vectorD3DVERTEX.size() * sizeof(D3DVERTEX)); //頂点配列の内容をバッファへコピー
			pVertexBuffer->Unlock(); //バッファのロック解除
		}
	}

	//インデックスバッファを作成
	if (vectorIndex.size())
	{
		pD3DDevice->CreateIndexBuffer(vectorIndex.size() * sizeof(WORD), Usage, D3DFMT_INDEX16, Pool, &pIndexBuffer, NULL);
		if (pIndexBuffer) //インデックスバッファの作成に成功した場合
		{
			LPVOID pBuffer; //バッファの内容を示すポインタ
			pIndexBuffer->Lock(0, 0, &pBuffer, 0); //バッファをロック
			memcpy(pBuffer, &vectorIndex.at(0), vectorIndex.size() * sizeof(WORD)); //インデックス配列の内容をバッファへコピー
			pIndexBuffer->Unlock(); //バッファのロック解除
		}
	}

	return;
}
Exemplo n.º 17
0
// @brief  : コンストラクタ
// @param  : ポリゴンの大きさ
//         : テクスチャ座標の位置
//         : テクスチャ
//         : 親クラス
//         : 描画するのか?
//--------------------------------------------------------------------
SpriteDx9::SpriteDx9( const Quad &_pol_size, const Quad &_tex_size,
            const Texture &_tex,
            IDraw *_parent, bool _is_draw ) :
    Sprite(_pol_size,_tex_size,_tex,_parent,_is_draw)
{
    HRESULT hr;
    LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device;

    hr = device->CreateVertexBuffer(
        sizeof(VERTEX) * 4,
        D3DUSAGE_WRITEONLY, // 使用方法
        VERTEX_FVF,         // フォーマット
        D3DPOOL_MANAGED,    // バッファを保持するメモリクラスを指定
        &m_VertexBuffer,    // 頂点バッファのポインタ
        NULL
    );

    VERTEX *vtx;
    m_VertexBuffer->Lock(0,0,(void**)&vtx,0);
    for( auto i = 0 ; i < 4 ; ++i )
    {
        vtx[i].pos.z = 0.0f;
    }
    m_VertexBuffer->Unlock();

    SetPolygonQuad(_pol_size);
    SetTextureQuad(_tex_size);
}
Exemplo n.º 18
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;
}
Exemplo n.º 19
0
//デフォルトコンストラクタ
Object::Object()
{
	// ポイントスプライトのバッファの初期化
	if (FAILED(d3dDevice->CreateVertexBuffer(10000 * sizeof(Vertex3), D3DUSAGE_WRITEONLY, VERTEX3_FVF, D3DPOOL_MANAGED, &pointBuffer, nullptr)))
		DebugAlert("頂点バッファが\n作成できませんでした。");

	// フォントの初期化
	D3DXCreateFont(d3dDevice,
		32,							// 文字の高さ
		16,							// フォントの文字の幅
		FW_NORMAL,					// フォントのウェイト
		0,							// 要求されるミップレベルの数
		false,						// 斜体フォントの場合はtrue
		0,							// 文字セット
		0,							//出力精度
		DEFAULT_QUALITY,			//出力品質
		DEFAULT_PITCH || FF_DONTCARE,	//フォントのピッチとファミリ
		"",							//フォントの書体
		&font);


	DebugLog("オブジェクトを生成しました\n");

	Initialize();
}
Exemplo n.º 20
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;
}
Exemplo n.º 21
0
LptaD3DDynamicBuffer::LptaD3DDynamicBuffer(
    LPDIRECT3DDEVICE9 d3ddev, 
    lpta::VERTEX_TYPE vertexType,
    unsigned int maxVertices, unsigned int maxIndices,
    lpta::LptaSkin::SKIN_ID skinId) : 
        vertexBuffer(nullptr), indexBuffer(nullptr), vertexType(vertexType),
        maxVertices(maxVertices), maxIndices(maxIndices), numVertices(0), numIndices(0),
        skinId(skinId)
{
    try {
        {
            HRESULT result = d3ddev->CreateVertexBuffer(ToStride(vertexType) * maxVertices, 
                USAGE, 0, D3DPOOL_DEFAULT, &vertexBuffer, nullptr);
            if (FAILED(result)) {
                throw std::runtime_error("failed to create vertex buffer");
            }
        }
        {
            HRESULT result = d3ddev->CreateIndexBuffer(sizeof(DWORD) * maxIndices,
                USAGE, D3DFMT_INDEX16, D3DPOOL_DEFAULT, &indexBuffer, nullptr);
            if (FAILED(result)) {
                throw std::runtime_error("failed to create index buffer");
            }
        }
    }
    catch (std::runtime_error) {
        if (nullptr != vertexBuffer) {
            vertexBuffer->Release();
        }
        if (nullptr != indexBuffer) {
            indexBuffer->Release();
        }
        throw D3DBufferAllocationFailure();
    }
}
Exemplo n.º 22
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);
}
Exemplo n.º 23
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;
		}
Exemplo n.º 24
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;
}
Exemplo n.º 25
0
//-----------------------------------------------------------------------------
// Name: A Vertex Buffer resembling the one from a very old version of 
//		 OGRE (Open Graphics Rendering Engine)
// Desc:
//-----------------------------------------------------------------------------
VertexBuffer::VertexBuffer(	int vertexSize, 
							int numVertices, 
							int usage, 
							LPDIRECT3DDEVICE9 pDev, 
							bool useSystemMemory)
{
	mVertexSize = vertexSize;
	m_numVertices = numVertices;
	mSizeInBytes = mVertexSize * numVertices;
	mUsage = usage;

    // Create the vertex buffer
    HRESULT hr = pDev->CreateVertexBuffer(
        mSizeInBytes, 
        usage, 
        0,
		useSystemMemory? D3DPOOL_SYSTEMMEM : D3DPOOL_DEFAULT, 
        &m_pVB,
        NULL);
    
	if( FAILED( hr ))
    {
		ERROR( "Failed to Create Buffer" );
    }
}
Exemplo n.º 26
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;
}
Exemplo n.º 27
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;
}
Exemplo 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();
}
Exemplo n.º 29
0
StaticPlane* StaticPlane::init() {
	LPDIRECT3DDEVICE9 device = ShaderDevise::device();

	device->CreateVertexBuffer(
		sizeof(CUSTOMVERTEX)*4,
		D3DUSAGE_WRITEONLY,
		D3DFVF_CUSTOMVERTEX,
		D3DPOOL_MANAGED,
		&vtx,
		NULL
		);

	float size = 10;
	CUSTOMVERTEX vtx[] = {
		CUSTOMVERTEX(D3DXVECTOR3(-size, 0,  size), D3DXVECTOR3(0, 1, 0), 0xffffffff, D3DXVECTOR2(0, 0)),
		CUSTOMVERTEX(D3DXVECTOR3( size, 0,  size), D3DXVECTOR3(0, 1, 0), 0xffffffff, D3DXVECTOR2(1, 0)),
		CUSTOMVERTEX(D3DXVECTOR3(-size, 0, -size), D3DXVECTOR3(0, 1, 0), 0xffffffff, D3DXVECTOR2(0, 1)),
		CUSTOMVERTEX(D3DXVECTOR3( size, 0, -size), D3DXVECTOR3(0, 1, 0), 0xffffffff, D3DXVECTOR2(1, 1))
	};

	D3DXVec3Cross(&vtx[0].nor, &(vtx[1].pos - vtx[0].pos), &(vtx[2].pos - vtx[0].pos));
	D3DXVec3Cross(&vtx[3].nor, &(vtx[2].pos - vtx[3].pos), &(vtx[1].pos - vtx[3].pos));
	D3DXVec3Normalize(&vtx[0].nor, &vtx[0].nor);
	D3DXVec3Normalize(&vtx[3].nor, &vtx[3].nor);

	void *data;
	this->vtx->Lock(0, sizeof(CUSTOMVERTEX)*4, &data, 0);
	memcpy(data, vtx, sizeof(CUSTOMVERTEX)*4);
	this->vtx->Unlock();
	return this;

}
Exemplo n.º 30
0
Arquivo: Main.cpp Projeto: 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;
}