Advertisement

d3d9 vertex buffer

Started by December 30, 2002 05:52 PM
1 comment, last by hibikikonzaki 21 years, 10 months ago
Ok, I have my vertex buffer set up right, the FVF struct set up and everything, but when I try to do a DrawPrimitive, nothing happens. I''ve scoured the DX9 docs and the books I''ve got, but nothing works. My init code and redering code is like this:
  

#define CUSTOMDRAGON_VERTEX (D3DFVF_XYZRHW|D3DFVF_DIFFUSE)

struct DRAGONVERTEX
{
	float x,y,z,rhw;
	DWORD DiffuseColor;
};

CDXGraphics::CreateVB()
{
	HRESULT r = 0;

	DRAGONVERTEX DVerts2[] = 
	{
		{ 150.0f,  50.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 0, 0 ), }, // x, y, z, rhw, color

		{ 250.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 255, 255, 0 ), },
		{  50.0f, 250.0f, 0.5f, 1.0f, D3DCOLOR_XRGB( 0, 0, 255 ), },
	};

	r = lpDevice->CreateVertexBuffer(sizeof(DRAGONVERTEX)*3,D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC,
									CUSTOMDRAGON_VERTEX,D3DPOOL_DEFAULT,
									&lpVB,NULL);
	if(FAILED(r))
	{
		assert(lpVB != NULL);
		Error_Message("Create Vertex Buffer");
		return(0);
	}

	VOID* pvVertices;
	if( FAILED( lpVB->Lock( 0, sizeof(DVerts2), (void**)&pvVertices, 0)))
		return(0);
	memcpy( pvVertices, &DVerts2, sizeof(DVerts2) );
	lpVB->Unlock();

	lpDevice->SetVertexShader(NULL);

	lpDevice->SetFVF(CUSTOMDRAGON_VERTEX);

	lpDevice->SetStreamSource(0,lpVB,0,sizeof(DRAGONVERTEX));

	assert(lpVB != NULL);

	return(1);
}

int Render()
{
	assert(D3DGraphics.lpDevice != NULL);
	if(FAILED(D3DGraphics.lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, 
										D3DCOLOR_XRGB(0,0,0), 1.0f, 0 )))
	{
		Error_Message("Clear\n");
		state = Exit;
	}

	D3DGraphics.lpDevice->BeginScene();
	if(FAILED(D3DGraphics.lpDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1)))
	{
		Error_Message("Draw Primitive\n");
		state = Exit;
	}
	D3DGraphics.lpDevice->EndScene();

	D3DGraphics.lpDevice->Present(NULL,NULL,NULL,NULL);

	return(1);
}
  
I''ve tried changing everything I could find. I''ve asserted everthing that might go wrong, but it runs and shuts down fine, but nothing is shown on screen. Hibiki Wheres the any key? www.geocities.com/dragongames123/home.html INSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:
HibikiWheres the any key?www.geocities.com/dragongames123/home.htmlINSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:
try putting these lines after the beginScene function and in this order:


  lpDevice->SetStreamSource(0,lpVB,0,sizeof(DRAGONVERTEX));lpDevice->SetVertexShader(NULL);	lpDevice->SetFVF(CUSTOMDRAGON_VERTEX);	  


or this:


  lpDevice->SetStreamSource(0,lpVB,0,sizeof(DRAGONVERTEX));lpDevice->SetVertexShader(CUSTOMDRAGON_VERTEX);	  




I also noticed:

  if(FAILED(D3DGraphics.lpDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0 )))  



The last parameter should be a Long according to DX8 docs. So try a 0L instead.


Sorry im not more helpful but im not onto DX9 yet !


Ant
>
Advertisement
I''ve tried all that... I''ve also been playing with RenderStates like lighting, culling, and stuff like that. I know the back buffer and everything is working right because I can change the color value and the screen will change colors. I know the vertex buffer is created right because there are no errors in the project file (I output them to a text file) and all my assertions pass.

Hibiki
Wheres the any key?
www.geocities.com/dragongames123/home.html

INSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:
HibikiWheres the any key?www.geocities.com/dragongames123/home.htmlINSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:

This topic is closed to new replies.

Advertisement