Jump to content
  • Advertisement
Sign in to follow this  
ryt

How to access vertex buffer at render time?

This topic is 3681 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

In my setup (initialization) I created vertex buffer to hold 11 vertices and to set them 10 only. Like this:
	pDevice->CreateVertexBuffer(sizeof(vector3)*11,
		D3DUSAGE_DYNAMIC,
		vector3::FVF,
		D3DPOOL_DEFAULT,
		&pVertexBuffer,
		0);

	pVertexBuffer->Lock(0, sizeof(vector3)*10, (void**)&pVertices, 0);
	for(int i = 0; i < 10; i++)
	{
		pVertices._x = 1.0f;
		pVertices._y = 1.0f;
		pVertices._z = 1.0f;
		pVertices._color = D3DCOLOR_ARGB(255, 100, 255, 255);
	}
	pVertexBuffer->Unlock();

Than in render loop i set the 11 vertex, like this:
	pVertexBuffer->Lock(sizeof(vector3)*10, sizeof(vector3), (void**)&pVertices, 0);
	pVertices[10] = vector3(something, something, something, something);
	pVertexBuffer->Unlock();

	pDevice->BeginScene();
	pDevice->SetStreamSource(0, pBSplineVertexBuffer, 0, sizeof(vector3));
	pDevice->SetFVF(vector3::FVF);
	pDevice->DrawPrimitive(D3DPT_POINTLIST, 0, 11);
	pDevice->EndScene();

Program compiles ok, but when i run it program brakes and says that windows interupted program and that there is corruption of a heap.

Share this post


Link to post
Share on other sites
Advertisement
Turn on D3D Debugging. There is a shortcut to the DirectX control panel in the start menu directory. In there slide the slider to the right. You should get information dumped by D3D into the debug output window.

Share this post


Link to post
Share on other sites
in my vista i dont have dx icon in control panel, is there another way to set debugging in dx in vista

Share this post


Link to post
Share on other sites
In your Lock() call, you're requesting that you lock 1 vertex, from offset 10, so the pointer returned is the pointer to the 11th vertex.
You then access index 10 of that array, which is actually vertex index 21.

You want to access element 0 instead:
pVertices[0] = vector3(something, something, something, something);

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
In your Lock() call, you're requesting that you lock 1 vertex, from offset 10, so the pointer returned is the pointer to the 11th vertex.
You then access index 10 of that array, which is actually vertex index 21.

You want to access element 0 instead:
pVertices[0] = vector3(something, something, something, something);


I want to lock only 11-th vertex (theat is I think pVertices[10]) and leave others as they are. Why would i actually access vertex index 21? Probably 11

Share this post


Link to post
Share on other sites
You lock and fill pVertexBuffer but set pBSplineVertexBuffer as your stream source. Is that intentional? You don't mention pBSplineVertexBuffer elsewhere in your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by ryt

I want to lock only 11-th vertex (theat is I think pVertices[10]) and leave others as they are. Why would i actually access vertex index 21? Probably 11


You are locking the 11th vertex, so pVertices is now pointing to the 11th vertex.
You want to index it at pVertices[0]

Share this post


Link to post
Share on other sites
I changed pBSplineVertexBuffer into pVertexBuffer but i still get error.
To RabidDog: i want on purpuse access only pVertices[10] cos its the only vertex i want to change in time, other vertices do not move so i access them only in initialization

Maybe i need to set some flags in Lock() when i access (set) 10-th vertex.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!