Click here to Skip to main content
Rate this: bad
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 21:43pm
Fredrik Bornander at 8-Feb-13 4:56am
What error is returned by SetStreamSource?
Aweiwei_ at 11-Feb-13 0:09am
It works well.No error was reported.
Fredrik Bornander at 11-Feb-13 2:28am
Sorry, I meant what error is reported by dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVertices,0,NumFaces)?
Aweiwei_ at 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_ at 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
0 OriginalGriff 319
1 _Amy 310
2 Nirav Prabtani 263
3 Sergey Alexandrovich Kryukov 210
4 Richard MacCutchan 125
0 OriginalGriff 7,889
1 Sergey Alexandrovich Kryukov 7,006
2 Maciej Los 4,014
3 Peter Leow 3,708
4 CHill60 2,762

Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 8 Feb 2013
Copyright © CodeProject, 1999-2014
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