Sign in to follow this  

locking LPDIRECT3DVERTEXBUFFER9

This topic is 2166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a triangle rendering , what i want to do is lock it and access the 3 vertex points, how can i do this?

Share this post


Link to post
Share on other sites
Hi Anddos! It`s very simple if you to work in 3D:

[CODE]
LPDIRECT3DVERTEXBUFFER9 m_pWallVB;
struct WALLVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu, tv;
static const DWORD FVF;
};
const DWORD WALLVERTEX::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;
p_d3d_Device->CreateVertexBuffer( 3*sizeof(WALLVERTEX),D3DUSAGE_WRITEONLY, D3DFVF_XYZ | D3DFVF_NORMAL| D3DFVF_TEX1| D3DFVF_TEXCOORDSIZE2(0), D3DPOOL_MANAGED, &m_pWallVB, NULL );
WALLVERTEX* v;
m_pWallVB->Lock( 0, 0, (void**)&v, 0 );
v[0].p = D3DXVECTOR3( -2.0f, 3.0f, 25.0f );
v[0].n = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
v[0].tu = 0.0f;
v[0].tv = 0.0f;
v[1].p = D3DXVECTOR3( 2.0f, 3.0f, 25.0f );
v[1].n = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
v[1].tu = 1.0f;
v[1].tv = 0.0f;
v[2].p = D3DXVECTOR3( 2.0f, 0.0f, 25.0f );
v[2].n = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );
v[2].tu = 1.0f;
v[2].tv = 1.0f;
m_pWallVB->Unlock();
//------------------------------------------------------
//Next step draw triangle
p_d3d_Device->SetFVF( D3DFVF_XYZ | D3DFVF_NORMAL| D3DFVF_TEX1| D3DFVF_TEXCOORDSIZE2(0) );
p_d3d_Device->SetStreamSource( 0, m_pWallVB, 0, sizeof(WALLVERTEX) );
p_d3d_Device->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 );
[/CODE]

If you to work in 2D just changle D3DFVF_XYZ -> D3DFVF_XYZRHW

Regards!

Share this post


Link to post
Share on other sites
First off, why do you want to lock the buffer?
If your goal is to update the positions of the vertices, then this would be more appropriately done using matrices. You can lock the buffer, assuming you created it with the appropriate usage flags, using the IDirect3DVertexBuffer9::Lock method. Also depending on your flags you may be able to read, or only write to the resultant pointer. Generally speaking: reading from resources is slow, if you need to "read" its typically better to have a local copy for that, and then simply update the vertex buffer. This doesn't work, though, if you're using the GPU to write data, but that's generally more of a D3D10+ issue.

Share this post


Link to post
Share on other sites
smoothey, i was looking for an example on how to lock it and retrieve the 3 points, not when you are creating the triangle :)

Share this post


Link to post
Share on other sites
At first I am not smoothey for you - I am SmoothEddy... At second can you add a little own mind?

[CODE]
m_pWallVB->Lock( 0, 0, (void**)&v, 0 );
float x = v[0].p.x ;
float y = v[0].p.y ;
float z = v[0].p.z ;
...................
m_pWallVB->Unlock();
[/CODE]

Share this post


Link to post
Share on other sites

This topic is 2166 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this