Sign in to follow this  
16bit_port

rendering issue

Recommended Posts

It's suppose to be a body. It only renders the outline of it for some odd reason. description of your image What could be causing this? I don't have any lighting or anything... //////d3d9 init
d3d = Direct3DCreate9( D3D_SDK_VERSION );

///// Verifying HAL support
   D3DDISPLAYMODE mode;
   d3d->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &mode );

   HAL_Support = d3d->CheckDeviceType( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, mode.Format, mode.Format, true );

//////// Grab device information
   D3DPRESENT_PARAMETERS d3dpp;
   ZeroMemory( &d3dpp, sizeof(d3dpp) );
   d3dpp.Windowed = TRUE;
   d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
   d3dpp.hDeviceWindow = hWnd;

HRESULT result = d3d->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING, &d3dpp, &d3ddev );


////// render
d3ddev->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 40, 100), 1.f, 0 );

d3ddev->BeginScene();

for( unsigned i = 0; i < ListOfObjects.size(); i++ )
{
	Object& Obj = ListOfObjects[i];
	for( unsigned j = 0; j < Obj.ListOfAssets.size(); j++ )
	{
		Asset &_Asset = Obj.ListOfAssets[j];

		for( unsigned k = 0; k < _Asset.ListOfMeshes.size(); k++ )
		{
			Mesh_D3D9 &_Mesh = _Asset.ListOfMeshes[k];
			d3ddev->SetStreamSource( 0, _Mesh.VertexBuffer, 0, sizeof(Vertex_D3D9) );
			d3ddev->SetIndices( _Mesh.IndexBuffer );
			d3ddev->SetVertexDeclaration( _Mesh.VertexDecl );

			int num_tris = _Mesh.NumIndices() / 3;
			d3ddev->DrawIndexedPrimitive( D3DPT_TRIANGLELIST, 0, 0, _Mesh.NumVertices(), 0, num_tris );
		}
	}
}

d3ddev->EndScene();

d3ddev->Present( NULL, NULL, NULL, NULL );	//swaps buffers


class Vertex_D3D9
{
   public:
	D3DXVECTOR3 Position;
	D3DXVECTOR3 Normal;
};


class Mesh_D3D9 : Mesh
{
	public :
		////////// Constructor, Destructor
			Mesh_D3D9();
			virtual ~Mesh_D3D9();

		////////// Member Variables
			IDirect3DVertexBuffer9* VertexBuffer;
			IDirect3DIndexBuffer9* IndexBuffer;

			D3DVERTEXELEMENT9 *declaration;
			IDirect3DVertexDeclaration9 *VertexDecl;

			Vertex_D3D9 *Vertices;

		////////// Methods
			inline DWORD NumDeclarationElements(){ return _NumberDeclarationElements; }

	private :
		/////////// Member Variables
			DWORD _NumberDeclarationElements;
};

void CreateAndLockVertexBuffer( Mesh_D3D9 &_Mesh )
{
	HRESULT result = d3ddev->CreateVertexBuffer( _Mesh.NumVertices() * sizeof( Vertex_D3D9 ), D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &_Mesh.VertexBuffer, 0 );


	void *Vertices = NULL;
	result = _Mesh.VertexBuffer->Lock( 0, 0, (void**)&Vertices, 0 );

        memcpy( Vertices, _Mesh.Vertices, sizeof( MVV::Vertex_D3D9 ) * _Mesh.NumVertices() );

	result = _Mesh.VertexBuffer->Unlock();
}


void CreateAndLockIndexBuffer( Mesh_D3D9 &_Mesh )
{
	HRESULT result = d3ddev->CreateIndexBuffer( _Mesh.NumIndices() * sizeof( DWORD ), D3DUSAGE_DYNAMIC, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &_Mesh.IndexBuffer, 0 );

	void *Indices = NULL;
	result = _Mesh.IndexBuffer->Lock( 0, 0, (void**)&Indices, 0 );

	memcpy( Indices, _Mesh.Indices, sizeof( DWORD ) * _Mesh.NumIndices() );

	result = _Mesh.IndexBuffer->Unlock();
}


void InitializeDeclarationElements( Mesh_D3D9 &_Mesh )
{
	_Mesh._NumberDeclarationElements = 3;
	_Mesh.declaration = new D3DVERTEXELEMENT9[ _Mesh._NumberDeclarationElements ];

	_Mesh.declaration[0].Stream = 0;
	_Mesh.declaration[0].Offset = 0;
	_Mesh.declaration[0].Type = D3DDECLTYPE_FLOAT3;
	_Mesh.declaration[0].Method = D3DDECLMETHOD_DEFAULT;
	_Mesh.declaration[0].Usage = D3DDECLUSAGE_POSITION;
	_Mesh.declaration[0].UsageIndex = 0;

	_Mesh.declaration[1].Stream = 0;
	_Mesh.declaration[1].Offset = 12;
	_Mesh.declaration[1].Type = D3DDECLTYPE_FLOAT3;
	_Mesh.declaration[1].Method = D3DDECLMETHOD_DEFAULT;
	_Mesh.declaration[1].Usage = D3DDECLUSAGE_NORMAL;
	_Mesh.declaration[1].UsageIndex = 0;

	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].Stream = 0xFF;
	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].Offset = 0;
	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].Type = D3DDECLTYPE_UNUSED;
	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].Method = 0;
	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].Usage = 0;
	_Mesh.declaration[ _Mesh._NumberDeclarationElements - 1 ].UsageIndex = 0;
}


Share this post


Link to post
Share on other sites
It looks like the model is being clipped by the near plane (bad), and also has backface culling off (normal)

It could be the opposite (far plane clipping, and the model is being frontface culled instead)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this