Sign in to follow this  

DrawIndexedPrimitive troubleshooting

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

Hey people, I'm using DrawIndexedPrimitive to draw a cube. The cube draws fine when I use one call to the method to draw it all. However, I want to draw each surface serperately so I can apply a different texture to each face. I've read what the MSDN has to say on the method but can't seem to get my head around the concept. I can get one plane to draw fine, but no others. Could anyone provide a little more light on this method? The indexed buffer contains 36 references to the vertex buffer, 6 for each side and I'm using D3DPT_TRIANGLELIST. I hope I've made myself clear, Thanks in advance.

Share this post


Link to post
Share on other sites
Ok, I've figured out how to draw each side individually and thus I can apply a different texture for each face. I kinda just stumbled onto the answer though and I'm not sure exactly why it works. I'm still having trouble understanding 3 of the parameters - BaseVertexIndex, MinIndex and StartIndex, what they do and how they are different from each other.

I do have another problem now however. The reason I wanted to apply different textures to each side of the cube is that I'm trying to construct a skybox. The skybox is now rendering fine, except when I place the camera within the box. When i do this, none of the sides seem to show up. i don't think its a problem with my viewport, perhaps it has something to do with backface culling, although I'm not sure why, when the face should be facing the camera. Any help on the above parameters and getting my cube to display when the camera is situated within it would be great.

Cheers.

Share this post


Link to post
Share on other sites
Quote:
Original post by GambitSnax
I'm still having trouble understanding 3 of the parameters - BaseVertexIndex, MinIndex and StartIndex, what they do and how they are different from each other.

Have you read Rendering from Vertex and Index Buffers in the SDK? (Programming Guide -> Getting Started -> Direct3D Rendering -> Rendering Primitives).

Quote:
Original post by GambitSnax
When i do this, none of the sides seem to show up. i don't think its a problem with my viewport, perhaps it has something to do with backface culling, although I'm not sure why, when the face should be facing the camera.

Sounds like back face culling to me [smile]

Triangles implicitly have a "winding order" making them either clockwise or counter clockwise. With this in mind, looking at the triangles from different sides determines if it is front or back facing.

You haven't specified which language you're using, but in C++ you can use IDirect3DDevice9::SetRenderState() with D3DRS_CULLMODE set to D3DCULL_NONE. However, ideally, you need to reverse the order of your vertices so that they are "front facing" from inside the cube. Simply changing the indices for each triangle should do this.

hth
Jack

Share this post


Link to post
Share on other sites
This is a pretty cool description of the arguments for DrawIndexedPrimitive(), link was in the forum faqs.

http://blogs.msdn.com/jsteed/articles/185681.aspx


If you're using hlsl you can specify the cullmode (and other renderstates) when you specify your techniques and passes

Quote:

technique someTechnique
{
pass P0
{ ...

CullMode = CCW; // for counter clock-wise
ZWriteEnable = true;
ColorWriteEnable = 0;
}
}


[edit:spelling error]

[Edited by - bennyW on December 17, 2005 11:03:52 PM]

Share this post


Link to post
Share on other sites
Ahhh thanks for the help guys, things seem to be working now :)
That article on vertex buffers was especially useful.

In terms of the back face culling problem, before I render the cube now, I switch the culling mode to CW and once it is rendered switch it back to CCW. It seemed like the simple solution, almost a little too simple. Is there a reason I should switch readily between culling modes technically, or is it simply bad practise?

Share this post


Link to post
Share on other sites
In general, you'll want to keep your cullmodes consistent, unless you need to change it for a specific reason like rendering shadow volumes or something.

Check that the winding order in your models are consistent with each other.
Sounds like your cube has a ccw winding order.

You might find it easier to address this in your index buffer:

ex.
indexbuffer = {v0,v1,v2}
has the opposite winding order of
indexbuffer{v0,v2,v1}

Share this post


Link to post
Share on other sites

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