Archived

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

Simple Question.

This topic is 5299 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 have a vertex buffer and an index buffer set up . Now , i want to render the triangles using an offset . I mean , if my index buffer is like this : 0 , 1 , 2 , 3 , 1 , 2 How do i render only the second triangle (that indices 3 , 1 , 2) specify in my DrawIndexedPrimitive Call ? I know this is just something as simple as setting an offset parameter but the parameter naming is not very helpful , nor the 1 line sdk explanation . Thx

Share this post


Link to post
Share on other sites
Get the DirectX help files - they have very thorough descriptions of all functions and their parameters, including DrawIndexedPrimitive. This help is also available on the Microsoft site - search on DrawIndexedPrimitive and you should find it.

Also, search the SDK examples for the functions you are using - I''ve figured out much from watching how the SDK examples work.

Share this post


Link to post
Share on other sites
The docs come in the SDK. I don''t know the file name, exactly (not at that system right now), but look through your SDK directories.

You could also try the Microsoft DirectX page at http://msdn.microsoft.com/library/default.asp?url=/nhp/default.asp?contentid=28000410 . You can download SDK stuff from there.

Share this post


Link to post
Share on other sites
Alright man, I''ll help you because I am the man , but understand that you are forever indebted to me for this.

Before I lay this brilliance on you, I have to tell you that you are being a little ignorant. The SDK is the best resource for programming with DirectX. Period. The answer is not only in there, but it''s also plain as day.

Ahem. Now that I''m done taking your chastity, here''s your answer.


HRESULT DrawIndexedPrimitive(
D3DPRIMITIVETYPE Type,
UINT MinIndex,
UINT NumVertices,
UINT StartIndex,
UINT PrimitiveCount
);

NumVertices
[in] The number of vertices indexed during this call, starting from BaseVertexIndex + StartIndex

StartIndex
[in] Location in the index array to start reading indices.



So for the example you provided, you would want StartIndex to be 3, NumVertices to be 3, and PrimitiveCount to be 1. Got it? Now go make Half-Life 3.

Share this post


Link to post
Share on other sites
> sad thing is i know how to do it and i haven''t used d3d since 5.0

Impressive! Especially considering that index buffers have only been around since DX8. Before that there was no need for a start index, you simply passed in a pointer to the first index.

Or is that what you mean?

Maybe the OP is using DX9 where it is somewhat more confusing, with the addition of the BaseVertexIndex parameter and the less than crystal clear description of what it means.

Try Tom Forsyth''s FAQ:

http://tomsdxfaq.blogspot.com/2002_05_01_tomsdxfaq_archive.html

Scroll down to Monday, May 27, 2002, "DrawIndexedPrimitive"

Share this post


Link to post
Share on other sites
It's an error code, it means delete the DirectX SDK off of your computer and go work at a gas station...

haha im just kidding, but damn how are you going to program with this API if you have to ask every single little question on a forum? "I'll have that fixed in a jiffy boss, as soon as someone replies..."

24 means you have an index in your array of indices that is '24' but you don't have a 24th vertex

[edited by - Funkymunky on June 6, 2003 9:54:48 AM]

Share this post


Link to post
Share on other sites
I DO HAVE more than 24 vertices in the Vertex Buffer ...
Funky : no , most time i don't even think of asking @ forum . Why ? Because if it is something i don't know i'd better learn it in detail . However , in this case , as i said it was AS SIMPLE AS SETTING A SINGLE PARAMETER . I knew it was that simple , i just couldn't remember + when you have some other bugs around i must be sure wich parameter it is so that debuging is easier . It's like KNOWING that your keys are inside the house , but not remembering exactly where . Do you ask members of ur family "Hey bro , did you see my keys " Or you go wasting 7 hours searching all the house and at the end learn that your mom borrowed them cause she lost hers ?

[edited by - MrNeedHelp on June 6, 2003 10:05:55 AM]

Share this post


Link to post
Share on other sites
I tracked down the problem . It is , that when i use DrawIndexedPrimitive using an index offset , when i set NumOfVertices to exactly the number of vertices that are used during this call , it fails . However , if i set NumOfVertices to the total number of vertices , then there is no problem.
Anyone know why this is the behaviour of this call ? I thought NumOfVertices was needed for internal buffer allocation and such ..

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Num vertices should be "Highest index used in this call" minus "lowest index used in this call" plus 1. It''s the number of vertices that hardware must transform, without being able to skip unused vertices, needed to perform this draw.

If your indices are 2 4 8, then num vertices = 8-2+1, or 7. Hardware may optionally not transform everything, but worst case is that you''ve asked hardware to transform 7 vertices to use 3 of them.

Share this post


Link to post
Share on other sites
Damn there's something wrong ...
i think i shouldnt be posting again on the same topic but i already spent 2 days and i cant fix it !.
I'm doing this :
Say i have 48 vertices and 132 indices.
I'm trying to render the data like this :
MyLovelyDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,24,0,16);
MyLovelyDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,12,48,14);
MyLovelyDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,12,90,14);
The First calls succeeds , but the second and third fail with this message :

Direct3D9: (ERROR) :Invalid index in the index stream: 24

Direct3D9: (ERROR) :DrawIndexedPrimitive failed.

Direct3D9: (ERROR) :Invalid index in the index stream: 36

Direct3D9: (ERROR) :DrawIndexedPrimitive failed.

Any clues ?

[edited by - MrNeedHelp on June 8, 2003 6:18:17 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Hi, did you manage to fix this?

I think the problem is in the parameters you are passing in the DIP call.

In the second call, if you look at the MinIndex and NumVertices values you''re passing in, you''re telling D3D that you are using a range of vertices from 0 (MinIndex) to 11 (NumVertices - 1). In your index buffer, you then reference vertex 24 which is outside of this range (0-11), hence D3D reporting that its come across an invalid index entry in the stream.

If your''re using the first 24 vertices for the first call, the next 12 for the second call and the last 12 for the third call, you want to use:

->DrawIndexPrimitive(D3DPT_TRIANGLELIST,0,0,24,0,16);
->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,24,12,48,14);
->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,36,12,90,14);

At least I think thats it! Apologies in advance if I''ve made a mistake here...

Share this post


Link to post
Share on other sites