Sign in to follow this  

Using Vertex Buffers: Can I do this?

This topic is 4843 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
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 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
Nah, thats not it. I can't seem to figure it out, and considering how simple this is, I don't realize why I am doing it this hard way, when I can just do it in 5 minutes using ID3DXSprite...sometimes, just easier to cut your losses and move on I guess :)

Share this post


Link to post
Share on other sites

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