my simple triangle appears in black

Started by
3 comments, last by TheSeb 18 years, 7 months ago
Hi, When i use DrawPrimitiveUP my triangle appears in color but if i use DrawIndexedPrimitive it's in black :-( I have a radeon X700. If you want to see a specific piece of code please tell me.

D3DFORMAT format=D3DFMT_A8R8G8B8;//D3DFMT_R5G6B5; 
	
	//IDirect3DDevice9 *d3dDevice=NULL;
	HRESULT hResult;

    //met à zéro tout les champs du pointeur sur structure
    ZeroMemory(&presentParameters,sizeof(D3DPRESENT_PARAMETERS));

	presentParameters.BackBufferCount= 1;  //We only need a single back buffer
    presentParameters.MultiSampleType=D3DMULTISAMPLE_NONE; //No multi-sampling
    presentParameters.MultiSampleQuality=0;                //No multi-sampling
    presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;  // Throw away previous frames, we don't need them
	presentParameters.hDeviceWindow = *hWndD3d;  //This is our main (and only) window
    presentParameters.Flags=0;            //No flags to set
    presentParameters.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT ;// D3DPRESENT_RATE_DEFAULT; //Default Refresh Rate
    presentParameters.PresentationInterval=D3DPRESENT_INTERVAL_IMMEDIATE; // D3DPRESENT_INTERVAL_DEFAULT; limite le frame rate au refresh rate
    presentParameters.BackBufferFormat=format;   







direct3dApp::direct3dApp()
{
	D3dDevice=NULL;
	myIDirect3DDevice9=NULL ;
	D3dDevice = Direct3DCreate9(D3D_SDK_VERSION);
	myFVF=D3DFVF_XYZRHW|D3DFVF_DIFFUSE;
	VBpointer=NULL ;

	vertexData[0].x=200.0f ;
	vertexData[0].y=200.0f ;
	vertexData[0].z=1.0f ;
	vertexData[0].rhw=1.0f ;
	vertexData[0].color=0x00EE0000 ;

	vertexData[1].x=400.0f ;
	vertexData[1].y=200.0f ;
	vertexData[1].z=1.0f ;
	vertexData[1].rhw=1.0f ;
	vertexData[1].color=0x0000EE00 ;

	vertexData[2].x=300.0f ;
	vertexData[2].y=400.0f ;
	vertexData[2].z=1.0f ;
	vertexData[2].rhw=1.0f ;
	vertexData[2].color=0x000000EE ;





Advertisement
i add these pieces of code if it can help you :

void direct3dApp::init(){	void *vbContent;	void *ibContent;	myIDirect3DDevice9->CreateVertexBuffer(3*sizeof(vertexStruct),                                       D3DUSAGE_WRITEONLY,//paramètre le plus performant                                       myFVF,                                       D3DPOOL_MANAGED,   //"fond commun"                                       &VBpointer,        //pointer to vb                                       NULL);     	VBpointer->Lock(0, 0, &vbContent, 0);//Locks a range of vertex data and obtains a pointer to the vertex buffer memory				memcpy(vbContent, //Destination			   vertexData,        //Source               3*sizeof(vertexStruct)); //Amount of data to copy	VBpointer->Unlock() ;		long int tabIndices[]={1, 2, 3};		myIDirect3DDevice9->CreateIndexBuffer(sizeof(tabIndices), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, 										  D3DPOOL_MANAGED, &IBpointer, NULL) ;	IBpointer->Lock(0, 0, &ibContent, 0);		memcpy(ibContent, tabIndices, sizeof(tabIndices) );	IBpointer->Unlock() ;	makeViewMatrix() ;	makeProjectionMatrix() ;	makeWorldMatrix() ;}


void direct3dApp::rendering(){	/*if(myIDirect3DDevice9 != NULL)     { */		//MessageBox(NULL, "toto", NULL, NULL);	//const void *data = vertexData;	myIDirect3DDevice9->Clear(0,  //Number of rectangles to clear, we're clearing everything so set it to 0                          NULL, //Pointer to the rectangles to clear, NULL to clear whole display                          D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER|D3DCLEAR_STENCIL, //What to clear.  We don't have a Z Buffer or Stencil Buffer                          D3DCOLOR_ARGB(0, 0, 0, 255),                          1.0f,  //Value to clear ZBuffer to, doesn't matter since we don't have one                          0 );					myIDirect3DDevice9->BeginScene() ;					myIDirect3DDevice9->SetStreamSource(0,                   //StreamNumber                                 VBpointer,           //StreamData                                 0,                   //OffsetInBytes                                 sizeof(vertexStruct)); //Stride 		myIDirect3DDevice9->SetFVF(myFVF);		myIDirect3DDevice9->SetIndices(IBpointer);		myIDirect3DDevice9->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, //PrimitiveType                               0, 0, 3, 0,                               1);      //PrimitiveCount			/*myIDirect3DDevice9->DrawPrimitiveUP(D3DPT_TRIANGLELIST,        //PrimitiveType												1,                //PrimitiveCount												data,                   //pVertexStreamZeroData												sizeof(vertexStruct));  //VertexStreamZeroStride*/

myIDirect3DDevice9->EndScene() ;
myIDirect3DDevice9->Present(NULL, NULL, NULL, NULL);

So, if I'm understanding your post correctly - where you'd get a correctly positioned and coloured triangle with a DrawPrimitiveUP call you're getting a black triangle with DrawIndexedPrimitive - with the only difference being that the colour is missing (the shape/size is identical?)

Have you checked the debug runtime to see if it's complaining of anything (see my signiture if you aren't familiar with this)?

Usually a lack-of-colour is due to an incorrect FVF (your's appears to be okay) or badly configured lighting/materials (again, shouldn't be a problem with the code you posted). Have you double checked the parameters for your DrawIndexedPrimitive() call? I don't have my documentation to hand, but it's quite easy to muddle up those parameters and get odd results.

Finally - you don't have any texure blending/operations or pixel/vertex shaders active that might be affecting the result do you?

hth
Jack

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

If DrawIndexedPrimitive fails, does DrawPrimitive? If DrawPrimitive works, does DrawIndexedPrimitiveUP?
i have found ! it was because my indices didn't start from 0 (it started from 1)

This topic is closed to new replies.

Advertisement