Jump to content
  • Advertisement
Sign in to follow this  
bobthebobert

Using Vertex Buffers: Can I do this?

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

What I wish to do is to use a circle for my players collision detection. I think I have it down, but to make sure I want to check it by drawing a circle on the screen to see if it matches up the person it represents. I am trying to create the vertex buffer for the points like this:
void aPlayer::PointRenderInit(IDirect3DDevice9 *g_d3d_device,IDirect3DVertexBuffer9 *VertexPoints) {
	D3DVERTEX Points[12];
	for (int arrCount=0;arrCount<12;++arrCount) {
                //PlayerPoints[0-11] are points in a circle I calculated earlier
		Points[arrCount].x=PlayerPoints[arrCount].X;
		Points[arrCount].y=PlayerPoints[arrCount].Y;
		Points[arrCount].z=1;
		Points[arrCount].color=D3DCOLOR_XRGB(100,100,100);
	}
	int vert_count=sizeof(Points)/sizeof(D3DVERTEX);
	int byte_count=vert_count*sizeof(D3DVERTEX);
	void *vertices;
	g_d3d_device->CreateVertexBuffer(byte_count,D3DUSAGE_WRITEONLY,trans_fvf,D3DPOOL_MANAGED,
		                             &VertexPoints,NULL);
	VertexPoints->Lock(0,0,&vertices,0);
	memcpy(vertices,VertexPoints,byte_count);
	VertexPoints->Unlock();
}


It doesn't seem to work, as soon as I start up my app it crashes. Is this a possible way to do what I want? [EDIT] That code doesn't give an error. It is just when I try to render it with this code it crashes:
	g_d3d_device->SetFVF(trans_fvf);
	g_d3d_device->SetStreamSource(0,Points,0,sizeof(D3DVERTEX));
    g_d3d_device->DrawPrimitive(D3DPT_POINTLIST,0,2);

Share this post


Link to post
Share on other sites
Advertisement
This line:

g_d3d_device->SetStreamSource(0,Points,0,sizeof(D3DVERTEX));

is wrong, your points array is no longer valid, instead it should be the vb.

Share this post


Link to post
Share on other sites
I'm sorry, the top part of code is from a class, the second isn't. Also, in the area where I used "Points", "g_d3d_device->SetStreamSource(0,Points,0,sizeof(D3DVERTEX));", Points is a VertexBuffer. Basically when I call PointRenderInit, I Points is the variable I pass to it.


IDirect3DVertexBuffer9 *Points=NULL;
Player.PointRenderInit(g_d3d_device,Points);



Sorry, used the same variable name and didn't clarify.


You mean try doing this Name?


g_d3d_device->CreateVertexBuffer(byte_count,D3DUSAGE_WRITEONLY,trans_fvf,D3DPOOL_MANAGED,
&VertexPoints,NULL);


to

g_d3d_device->CreateVertexBuffer(byte_count,D3DUSAGE_POINTS,trans_fvf,D3DPOOL_MANAGED,
&VertexPoints,NULL);



Doesn't fix it, and neither does doing "D3DUSAGE_POINTS | D3DUSAGE_WRITEONLY". Any one else got some tips?

Share this post


Link to post
Share on other sites
You are copying vertexpoints to vertices? with this line:
memcpy(vertices,VertexPoints,byte_count);
but the vertexpoints is the newly created buffer. I think you need to do this:
memcpy(vertices, points, byte_count);

The FVF is ok as far I can see.

Share this post


Link to post
Share on other sites
Ok, the next line in question I see is:
g_d3d_device->DrawPrimitive(D3DPT_POINTLIST,0,2);

do you have a loop to render all 12 points? this line will only draw 2.

Share this post


Link to post
Share on other sites
Ok, the last thing I see in this code is what Trip99 said earlier You need to change line:
g_d3d_device->SetStreamSource(0,Points,0,sizeof(D3DVERTEX));
to:
g_d3d_device->SetStreamSource(0,VertexPoints,0,sizeof(D3DVERTEX));

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!