Click here to Skip to main content
11,927,378 members (51,180 online)
Rate this:
Please Sign up or sign in to vote.
See more: C++ DirectX
the purpose is to create a mesh of teapot,get the vertices & index from it,and draw from the vertices and index
ID3DXMesh *Teapot;
dev->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0);
IDirect3DVertexBuffer9 *VertextBuffer;
IDirect3DIndexBuffer9 *IndexBuffer;
DWORD NumFaces=Teapot->GetNumFaces();
DWORD NumVertices=Teapot->GetNumVertices();
DWORD BytesPerVertex=Teapot->GetNumBytesPerVertex();
if(Teapot->GetVertexBuffer(&VertextBuffer)!=D3D_OK)MessageBox(NULL,TEXT("GetVertexBuffer() Failed!!"),TEXT(""),MB_OK);
if(Teapot->GetIndexBuffer(&IndexBuffer)!=D3D_OK)MessageBox(NULL,TEXT("GetIndexBuffer() Failed!!"),TEXT(""),MB_OK);
if(dev->SetStreamSource(0,VertextBuffer,0,BytesPerVertex)!=D3D_OK)MessageBox(NULL,TEXT("SetStreamSource() Failed!!"),TEXT(""),MB_OK);
if(dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVertices,0,NumFaces)!=D3D_OK)MessageBox(NULL,TEXT("DrawIndexedPrimitive() Failed!!"),TEXT(""),MB_OK);

everything's ok!Wonderful!!!
if I just delete the code "Teapot->DrawSubset(0);" at line 5th,the messagebox will tell me

DrawIndexedPrimitive() Failed!!

Just want to know WHY
WEll,English is my 2nd language so I'm not really good at it,but you know what I mean
Thank you
Posted 7-Feb-13 22:43pm
Fredrik Bornander 8-Feb-13 4:56am
What error is returned by SetStreamSource?
Aweiwei_ 11-Feb-13 0:09am
It works well.No error was reported.
Fredrik Bornander 11-Feb-13 2:28am
Sorry, I meant what error is reported by dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVertices,0,NumFaces)?
Aweiwei_ 12-Feb-13 8:13am
int err=dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVertices,0,NumFaces);

err come out to be -2005530516 (0x8876086c)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

My guess would be that's because there's nothing in the triange list without the call to DrawSubset(0)
Look at the documentation for DrawSubset to see why you would need to call it.
To me it implies in a Microsoft, 'we said it even though we didn't really say it' way that DrawSubset turns a mesh or part of a mesh into a triangle list to be rendered by DrawIndexedPrimitive.
Aweiwei_ 11-Feb-13 0:07am
from msdn:


The subset that is specified by AttribId will be rendered by the IDirect3DDevice9::DrawIndexedPrimitive method, using the D3DPT_TRIANGLELIST primitive type, so an index buffer must be properly initialized.

it seems that the DrawSubset call DrawIndexedPrimitive internal

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100