Sign in to follow this  
Player_0

Having problems drawing a cube...

Recommended Posts

Hello! Im loading the vertices from an obj file, Ive tested that part and its fine so here is some of the DX code.
	g_d3d9dev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

	VOID* vert;
	if(FAILED(g_d3d9dev->CreateVertexBuffer(f_Load->numverts*sizeof(CUSTOMVERTEX), 0,
		D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ))) return E_FAIL;
	
	if(FAILED(g_pVB->Lock(0, sizeof(vertices), (void**)&vert, 0)))return E_FAIL;
	memcpy(vert, vertices, sizeof(vertices));
	g_pVB->Unlock();

	g_d3d9dev->SetStreamSource(0, g_pVB, 0, sizeof(CUSTOMVERTEX));
	g_d3d9dev->SetFVF(D3DFVF_CUSTOMVERTEX);

	g_d3d9dev->BeginScene();
	D3DXMATRIXA16 matWorld;
	FLOAT fAngle = x/100.0f;
	D3DXMatrixRotationY( &matWorld, fAngle );
	g_d3d9dev->SetTransform( D3DTS_WORLD, &matWorld );
	D3DXVECTOR3 vEyePt( 0.0f, 0.0f, 4.0f );
	D3DXVECTOR3 vLookatPt( 0.0f, 0.0f, 0.0f );
	D3DXVECTOR3 vUpVec( 0.0f, 1.0f, 0.0f );
	D3DXMATRIXA16 matView;
	D3DXMatrixLookAtLH( &matView, &vEyePt, &vLookatPt, &vUpVec );
	g_d3d9dev->SetTransform(D3DTS_VIEW, &matView );
	D3DXMATRIXA16 matProj;
	D3DXMatrixPerspectiveFovLH( &matProj, 90, 1.0f, 1.0f, 100.0f );
	g_d3d9dev->SetTransform( D3DTS_PROJECTION, &matProj );

	g_d3d9dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);
	g_d3d9dev->EndScene();

	g_d3d9dev->Present(NULL, NULL, NULL, NULL);
x++;


And I know its messy =P f_Load is the file class numverts is the number of vertices theres 8 of them, two triangles for each face so 12 triangles in all. Did I miss something obvious? [Edited by - Coder on November 4, 2005 11:36:34 PM]

Share this post


Link to post
Share on other sites
Is this code in a render loop?

If so you are creating a Vertex Buffer every frame. Also you don't need to make a bunch of these calls every frame. But to your question what is the problem? Does anything show up? Does the screen clear to the color you set?

Share this post


Link to post
Share on other sites
A couple of things your might want to try.

1. Set the clear color to something other then white or black. This will let you see it with things render but not lit.

2. If something else has rendered then try turning off culling.

3. Post some more code from the loading of the verts

Share this post


Link to post
Share on other sites
Heres the code where I load it into the vertices array.


CUSTOMVERTEX vertices[8];
FileLoad *f_Load = new FileLoad;
IDirect3DDevice9* Init(HWND hwnd)
{
IDirect3D9* d3d9;
D3DCAPS9 caps;
f_Load->OpenSomething();
int x = 0;
for(vector<VERTEX3f>::iterator blah = f_Load->Vertices.begin(); blah != f_Load->Vertices.end(); blah++)
{
vertices[x].color = 0xff0000ff;
vertices[x].x = blah->x;
vertices[x].y = blah->y;
vertices[x].z = blah->z;
x++;
}




[Edited by - Coder on November 4, 2005 11:36:20 PM]

Share this post


Link to post
Share on other sites
I found out that if I change the 12 to anything under 5 I get a few triangles but they are all pointing in the wrong direction and arent connected.

g_d3d9dev->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 12);

Share this post


Link to post
Share on other sites
Ok Im pretty sure its the format of the vertices in the obj file. I was able to draw it with triangle strips so I think I have to reorder them for lists.

Thank you for you help Dean Johnson.

Share this post


Link to post
Share on other sites
ok, um, it looks pretty good, just yeah as Dean said, change the Clear color from like black to like orange or grey or blue or something that isn't black or white. Also, when you call g_d3d9dev->Clear(...), the third argument should be "D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER" Hope that helps.

[edit] well i geuss im too late, but you should still change the 3rd argument to what i said before [/edit]

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