I have a triangle rendering , what i want to do is lock it and access the 3 vertex points, how can i do this?
4 replies to this topic
Sponsor:
#2 Members - Reputation: 102
Posted 11 February 2012 - 01:28 PM
Hi Anddos! It`s very simple if you to work in 3D:
If you to work in 2D just changle D3DFVF_XYZ -> D3DFVF_XYZRHW
Regards!
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 );
If you to work in 2D just changle D3DFVF_XYZ -> D3DFVF_XYZRHW
Regards!
"Windows programming is like going to the dentist: You know it’s good for you, but no one likes doing it." - Andre LaMothe
#3 Senior Moderators - Reputation: 3117
Posted 11 February 2012 - 02:31 PM
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.
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.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX
#5 Members - Reputation: 102
Posted 11 February 2012 - 09:56 PM
At first I am not smoothey for you - I am SmoothEddy... At second can you add a little own mind?
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();
"Windows programming is like going to the dentist: You know it’s good for you, but no one likes doing it." - Andre LaMothe






