本文整理汇总了C++中LPDIRECT3DDEVICE9::CreateVertexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DDEVICE9::CreateVertexBuffer方法的具体用法?C++ LPDIRECT3DDEVICE9::CreateVertexBuffer怎么用?C++ LPDIRECT3DDEVICE9::CreateVertexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DDEVICE9
的用法示例。
在下文中一共展示了LPDIRECT3DDEVICE9::CreateVertexBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: InitVB
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;
}
示例2: Init
/************************************************************
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);
}
}
示例3: 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();
}
示例4: InitVB
// 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() ;
}
示例5: intBuffers
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();
}
示例6: FSCreateDynamic2dVertexBuffer
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;
}
示例7: initVertexData
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);
}
示例8: InitGeometry
//-----------------------------------------------------------------------------
// 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;
}
示例9: InitVB
// 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;
}
示例10: InitVertexBuffer
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() ;
}
示例11: InitVB
//-----------------------------------------------------------------------------
// 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;
}
示例12: initializeObj
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;
}
示例13: InitVB
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;
}
示例14: init_vertex_buffer
//------------------------------------------------------------------------------
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;
}
示例15: InitGeometry
//-----------------------------------------------------------------------------
// 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;
}