Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
the purpose is to create a mesh of teapot,get the vertices & index from it,and draw from the vertices and index
C++
ID3DXMesh *Teapot;

D3DXCreateTeapot(dev,&Teapot,NULL);

Teapot->DrawSubset(0);

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);

dev->BeginScene();
if(dev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,NumVertices,0,NumFaces)!=D3D_OK)MessageBox(NULL,TEXT("DrawIndexedPrimitive() Failed!!"),TEXT(""),MB_OK);

dev->EndScene();
dev->Present(0,0,0,0);


everything's ok!Wonderful!!!
But
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
Comments
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

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.
 
Share this answer
 
Comments
Aweiwei_ 11-Feb-13 0:07am    
from msdn:

Remarks

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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900