Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


locking LPDIRECT3DVERTEXBUFFER9


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Anddos   Members   -  Reputation: 508

Like
0Likes
Like

Posted 11 February 2012 - 07:39 AM

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

Sponsor:

#2 SmoothEddy   Members   -  Reputation: 102

Like
0Likes
Like

Posted 11 February 2012 - 01:28 PM

Hi Anddos! It`s very simple if you to work in 3D:

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 Washu   Senior Moderators   -  Reputation: 5362

Like
0Likes
Like

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.

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


#4 Anddos   Members   -  Reputation: 508

Like
0Likes
Like

Posted 11 February 2012 - 07:19 PM

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

#5 SmoothEddy   Members   -  Reputation: 102

Like
1Likes
Like

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




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS