Manipulate vertex from vertex buffer
Can somebody gave me the code on how to retrieve vertex already stored on a vertex buffer
thanks
Let's say you have a valid vertex buffer pVB.
and lets say u use the following vertex structure for storing vertices :
Struct Vertex
{
float x, y, z;
DWORD color;
}
void *p = (Vertex*)pVB->Lock();
p is a pointer to the first vertex structure in stored in VB
(the first vertex);
Now u can use p for manipulating the vertex like this :
p->x = 123;
p->y = 120
and so on...
p[1] - Second vertex
p[2] - Third vertex
.
.
.
u must unlock the VB after you done manipulating so use
pVB->Unlock();
Look at directx sdk for the definition of the lock and unlock functions for more understanding-
and lets say u use the following vertex structure for storing vertices :
Struct Vertex
{
float x, y, z;
DWORD color;
}
void *p = (Vertex*)pVB->Lock();
p is a pointer to the first vertex structure in stored in VB
(the first vertex);
Now u can use p for manipulating the vertex like this :
p->x = 123;
p->y = 120
and so on...
p[1] - Second vertex
p[2] - Third vertex
.
.
.
u must unlock the VB after you done manipulating so use
pVB->Unlock();
Look at directx sdk for the definition of the lock and unlock functions for more understanding-
Lock()'s actual prototype is this:
Lock(UINT OffsetToLock, UINT SizeToLock, VOID **ppbData, DWORD Flags);
Frequently, you can call it like this (to lock the entire buffer):
Vertex *lockedVerts = NULL;
pVB->Lock(0, 0, (VOID **)&lockedVerts, D3DLOCK_DISCARD);
However, since you said you want to just retrieve verts in the buffer, you probably want to use D3DLOCK_READONLY for the final parameter.
When you're done, Unlock() the VB and you're good to render from it again.
-Mezz
Lock(UINT OffsetToLock, UINT SizeToLock, VOID **ppbData, DWORD Flags);
Frequently, you can call it like this (to lock the entire buffer):
Vertex *lockedVerts = NULL;
pVB->Lock(0, 0, (VOID **)&lockedVerts, D3DLOCK_DISCARD);
However, since you said you want to just retrieve verts in the buffer, you probably want to use D3DLOCK_READONLY for the final parameter.
When you're done, Unlock() the VB and you're good to render from it again.
-Mezz
how can I know Vertex structure of a mesh, so I can access the vertexbuffer ?
I have a mesh. I need access to its vertexbuffer, but I have to know its vertexstructure to get a pointer to the vertexbuffer.
I have a mesh. I need access to its vertexbuffer, but I have to know its vertexstructure to get a pointer to the vertexbuffer.
Quote:
Vertex *lockedVerts = NULL;
When you create the mesh you also specify the flexible vertex format (FVF) from which u shold know which structure to use
for example :
Lets say you used D3DFVF_XYZ | D3DFVF_DIFFUSE
ur structure will look like this :
struct Vertex
{
float x, y, z;
DWORD color;
}
for example :
Lets say you used D3DFVF_XYZ | D3DFVF_DIFFUSE
ur structure will look like this :
struct Vertex
{
float x, y, z;
DWORD color;
}
If you created your mesh from a file or by using other function which not use FVF you can call the GetFVF() method of your mesh
interface (ID3DXMesh or ID3DXBaseMesh) and get the vertex FVF
interface (ID3DXMesh or ID3DXBaseMesh) and get the vertex FVF
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement