Advertisement Jump to content
Sign in to follow this  

my simple triangle appears in black

This topic is 4885 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

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

	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

	myIDirect3DDevice9=NULL ;
	D3dDevice = Direct3DCreate9(D3D_SDK_VERSION);
	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 ;

Share this post

Link to post
Share on other sites
i add these pieces of code if it can help you :

void direct3dApp::init()
void *vbContent;
void *ibContent;
D3DUSAGE_WRITEONLY,//paramètre le plus performant
D3DPOOL_MANAGED, //"fond commun"
&VBpointer, //pointer to vb
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,
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->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);

Share this post

Link to post
Share on other sites
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?


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!