Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

The Alchemist

yes... another topic about drawindexprimitive problems

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

i realy feel bad for posting this, you people probabily already full of post about indexbuffers, but this one is making me mad for weeks and i ran out of resources >_< well my problem is quite simple... drawprimitive works... no errors, no problems in the debug output... but it dont draws anything... rendering from the vb directly with drawprimitive works... so is definidely a problem with the ib well heres the parts of my source that involves the ib creation of ib

if( FAILED(d3ddevice->CreateIndexBuffer(3*sizeof(short),D3DUSAGE_WRITEONLY,
		return FAIL;
	void *index;
	if( FAILED( indexBuffer->Lock(0,0,(BYTE**)&index,0)))
		return FAIL;
	memcpy(index,tileindex, sizeof(index));
redenring code
RESULT Graphics::Render()
	D3DXMATRIX matWorld;
	D3DXMATRIX matView;
	D3DXMatrixLookAtLH( &matView, &D3DXVECTOR3( 0.0f, 0.0f,100.0f ),
                                  &D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),
                                  &D3DXVECTOR3( 0.0f, 1.0f, 0.0f ) );
	d3ddevice->SetTransform( D3DTS_VIEW, &matView );
	D3DXMATRIX matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f );
	d3ddevice->SetTransform( D3DTS_PROJECTION, &matProj );
	d3ddevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(100,100,100), 1.0f, 0L );
	d3ddevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
	d3ddevice->SetStreamSource( 0,tileBlocks, sizeof(Vertex) );
	for(int i = 1;i < model->allObjectsLenght;i++)
		int x = model->allObjects[i]->x;
		int y = model->allObjects[i]->y;

		d3ddevice->SetTransform( D3DTS_WORLD, &matWorld);
		d3ddevice->SetTransform( D3DTS_WORLD, &matWorld );

	d3ddevice->Present( NULL, NULL, NULL, NULL );
model->allObjects->x; and model->allObjects[i]->y; are just ints... andthey work when using DrawPrimitive so thats not the problem any help is apreciated thx in advance [edited by - The Alchemist on December 16, 2003 7:51:39 AM] [edited by - The Alchemist on December 16, 2003 12:17:12 PM]

Share this post

Link to post
Share on other sites
memcpy(index,tileindex, sizeof(index));

Try changing that.

sizeof(void*) is 4. that will just copy two indices. that is if your indices are 2 bytes, which it looks like they are becuase you''re using the INDEX16 format.

:::: [ Triple Buffer ] ::::

Share this post

Link to post
Share on other sites
Could we see your indices? The code looks okay, if a bit odd. If it works with DrawPrimitive, you'll need indices of 0,1,2 to have the same winding order (for culling to work the same).

Things of note:

1. 3*sizeof(short) -- Why have a fixed size, when
2. sizeof(index) -- you know how big you really want it. Granted this is test code, but with such a minor change to code it would automatically work for any number of indices, such as your likely next test, quads.

Is index the actual array, or is it a pointer, and you're going to end up copying only 2 of your 3 indices as a result?

3. D3DCLEAR_TARGET -- did you mean to not clear Z? I'm not sure if you have Z enabled, but if it's filled with junk you may not see your object.

4. d3ddevice->SetTransform( D3DTS_WORLD, &matWorld ) -- the second one, the one after you draw, is useless.

There are some other oddities, which I'll assume are just because it's quick test code.

edit: Ah! Previous poster beat me. Didn't notice he'd actually shown us what the index variable was. Yeah, definately not the actual index array. use 3*sizeof(short) if your tileindex is a pointer. If it's actually an array, local to the function, or global, use sizeof(tileindex) for the reason I presented above.

[edited by - namethatnobodyelsetook on December 16, 2003 1:07:51 PM]

Share this post

Link to post
Share on other sites
YAy it worked!!!

thats the worse part of learning something new, you never seems to check the old part of your code >_<

but only having two indices copyed woulndt cause DrawIndexedPrimitive to fail? like... not enough vertexes for the primitive type of thing?

thx for help!

[edited by - The Alchemist on December 16, 2003 2:34:12 PM]

Share this post

Link to post
Share on other sites
Only if it didn''t happen to be valid. Lets assume it''s cleared to 0 for you... now your indices are 0,1,0. A perfectly valid degenerate triangle... BTW, you never mentioned if you''d tried fixing your memcpy, and if there are more problems, or if it''s fixed. Your memcpy IS a problem the way it is now.

Share this post

Link to post
Share on other sites

  • 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!