Archived

This topic is now archived and is closed to further replies.

JoCCo

Question About Vertexes

Recommended Posts

Hello, I posted a question about this two days ago, I didn''t get an answear, so I guess I was a bit unclear... I''m having troubles drawing a cube that I''ve imported from Worldcraft... I''ve now tried to define the Vertexes directly in the code, and I still get the same error, so I guess I''m not totally clear on Vertex drawing... Anyway, I''ll post a picture of my problem... Any help would be appreciated... This is my problem :

Share this post


Link to post
Share on other sites
Okay, I saw Engel using this in my beginning Direct3d game programming book, and I though I'd use the same technique... ( the createcube function )


    

struct CUSTOMVERTEX
{
D3DXVECTOR3 p;
D3DXVECTOR3 n;
FLOAT tu,tv;
};
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1)

#define FILL_CUBEVERTEX( v, vertex,normal, atu, atv ) \
{ v.p.x = vertex.x; v.p.y = vertex.y; v.p.z = vertex.z;
v.n.x = normal.x; v.n.y = normal.y; v.n.z = normal.z;
v.tu = atu; v.tv = atv;
}


void CreateSkyBox()
{
CUSTOMVERTEX cvSkybox[24];
nSkybox = 24;

D3DXVECTOR3 p1 = D3DXVECTOR3(-10.0f, 10.0f,-10.0f);
D3DXVECTOR3 p2 = D3DXVECTOR3( 10.0f, 10.0f,-10.0f);
D3DXVECTOR3 p3 = D3DXVECTOR3( 10.0f,-10.0f,-10.0f);
D3DXVECTOR3 p4 = D3DXVECTOR3(-10.0f,-10.0f,-10.0f);
D3DXVECTOR3 p5 = D3DXVECTOR3(-10.0f, 10.0f, 10.0f);
D3DXVECTOR3 p6 = D3DXVECTOR3(-10.0f,-10.0f, 10.0f);
D3DXVECTOR3 p7 = D3DXVECTOR3( 10.0f,-10.0f, 10.0f);
D3DXVECTOR3 p8 = D3DXVECTOR3( 10.0f, 10.0f, 10.0f);

// Define the normals for the cube

D3DXVECTOR3 n0( 0.0f, 0.0f,-10.0f ); // Front face

D3DXVECTOR3 n1( 0.0f, 0.0f, 10.0f ); // Back face

D3DXVECTOR3 n2( 0.0f, 10.0f, 0.0f ); // Bottom face

D3DXVECTOR3 n3( 0.0f,-10.0f, 0.0f ); // Top face

D3DXVECTOR3 n4( 10.0f, 0.0f, 0.0f ); // Left face

D3DXVECTOR3 n5(-10.0f, 0.0f, 0.0f ); // Right face


// Set up the vertices for the cube. Note: to prevent tiling problems,

// the u/v coords are knocked slightly inwards.


// Front face

FILL_CUBEVERTEX( cvSkybox[0], p1, n0, 0.01f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[1], p2, n0, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[2], p3, n0, 0.99f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[3], p4, n0, 0.01f, 0.99f );

// Back face

FILL_CUBEVERTEX( cvSkybox[4], p5, n1, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[5], p6, n1, 0.99f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[6], p7, n1, 0.01f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[7], p8, n1, 0.01f, 0.01f );

// Top face

FILL_CUBEVERTEX( cvSkybox[8], p5, n2, 0.01f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[9], p8, n2, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[10], p2, n2, 0.99f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[11], p1, n2, 0.01f, 0.99f );

// Bottom face

FILL_CUBEVERTEX( cvSkybox[12], p6, n3, 0.01f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[13], p4, n3, 0.01f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[14], p3, n3, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[15], p7, n3, 0.99f, 0.99f );

// Left face

FILL_CUBEVERTEX( cvSkybox[16], p2, n4, 0.01f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[17], p8, n4, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[18], p7, n4, 0.99f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[19], p3, n4, 0.01f, 0.99f );

// Right face

FILL_CUBEVERTEX( cvSkybox[20], p1, n5, 0.99f, 0.01f );
FILL_CUBEVERTEX( cvSkybox[21], p4, n5, 0.99f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[22], p6, n5, 0.01f, 0.99f );
FILL_CUBEVERTEX( cvSkybox[23], p5, n5, 0.01f, 0.01f );



DWORD m_dwSizeofVertices;

m_dwSizeofVertices = sizeof(CUSTOMVERTEX)*nSkybox;


if( FAILED( m_pd3dDevice->CreateVertexBuffer( m_dwSizeofVertices,
0, D3DFVF_CUSTOMVERTEX,
D3DPOOL_MANAGED, &m_pSkyVB ) ) )
return;

VOID* pIndices;

if( FAILED( m_pSkyVB ->Lock( 0, m_dwSizeofVertices, (BYTE**)&pIndices, 0 ) ) )
return;

memcpy( pIndices, cvSkybox, m_dwSizeofVertices);
m_pSkyVB->Unlock();


WORD cvSkyIndex[36];

nSkyInd=36;

int i=0;
// Set up the indices for the cube

cvSkyIndex[i++] = 0+0; cvSkyIndex[i++] = 0+1; cvSkyIndex[i++] = 0+2;
cvSkyIndex[i++] = 0+2; cvSkyIndex[i++] = 0+3; cvSkyIndex[i++] = 0+0;
cvSkyIndex[i++] = 4+0; cvSkyIndex[i++] = 4+1; cvSkyIndex[i++] = 4+2;
cvSkyIndex[i++] = 4+2; cvSkyIndex[i++] = 4+3; cvSkyIndex[i++] = 4+0;
cvSkyIndex[i++] = 8+0; cvSkyIndex[i++] = 8+1; cvSkyIndex[i++] = 8+2;
cvSkyIndex[i++] = 8+2; cvSkyIndex[i++] = 8+3; cvSkyIndex[i++] = 8+0;
cvSkyIndex[i++] = 12+0; cvSkyIndex[i++] = 12+1; cvSkyIndex[i++] = 12+2;
cvSkyIndex[i++] = 12+2; cvSkyIndex[i++] = 12+3; cvSkyIndex[i++] = 12+0;
cvSkyIndex[i++] = 16+0; cvSkyIndex[i++] = 16+1; cvSkyIndex[i++] = 16+2;
cvSkyIndex[i++] = 16+2; cvSkyIndex[i++] = 16+3; cvSkyIndex[i++] = 16+0;
cvSkyIndex[i++] = 20+0; cvSkyIndex[i++] = 20+1; cvSkyIndex[i++] = 20+2;
cvSkyIndex[i++] = 20+2; cvSkyIndex[i++] = 20+3; cvSkyIndex[i++] = 20+0;


///////////////////////////

///// Render()

//////////////////////////

// fill the Index buffer

DWORD m_dwSizeofIndices= 36;

// Create the index buffer

if( FAILED( m_pd3dDevice->CreateIndexBuffer( m_dwSizeofIndices,
0, D3DFMT_INDEX16,
D3DPOOL_MANAGED, &m_pSkyIB ) ) )
return;

VOID* pIndicesIB;
if( FAILED( m_pSkyIB->Lock( 0, m_dwSizeofIndices, (BYTE**)&pIndicesIB, 0 ) ) )
return;

memcpy( pIndicesIB, cvSkyIndex, m_dwSizeofIndices );
m_pSkyIB->Unlock();

return;

}








m_pd3dDevice->SetTexture( 0, m_pBackgroundTexture);
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_SELECTARG1 );
m_pd3dDevice->SetStreamSource( 0, m_pSkyVB, sizeof(CUSTOMVERTEX) );
m_pd3dDevice->SetVertexShader( D3DFVF_CUSTOMVERTEX );
m_pd3dDevice->SetIndices( m_pSkyIB, 0);

m_pd3dDevice->DrawPrimitive( D3DPT_LINELIST,
0,
nSkybox);



Edit : I just realised that I didn't explain why I don't use the Index Buffer, when I try to draw an IndexedPrimitive, it doesn't draw anything, could that have anything to do with me doing something wrong ?

[edited by - JoCCo on April 29, 2002 12:24:34 PM]

Share this post


Link to post
Share on other sites
i''m way too tired to read through that code, but what i saw of it, you set everything up with an indexbuffer, but you draw it using just a vertexbuffer. You are using a list, which means it''s going to read 2 vertices for every line, this means that to draw 2 lines, one from v1 to v2, one from v2 to v3, you would need to put v1,v2,v2,v3 in the vertexbuffer. Since you intended to use an indexbuffer, you probably haven''t done this. Fix that, and you''ll prbly be allright.


--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites
quote:
Original post by tok_junior
i''m way too tired to read through that code, but what i saw of it, you set everything up with an indexbuffer, but you draw it using just a vertexbuffer. You are using a list, which means it''s going to read 2 vertices for every line, this means that to draw 2 lines, one from v1 to v2, one from v2 to v3, you would need to put v1,v2,v2,v3 in the vertexbuffer. Since you intended to use an indexbuffer, you probably haven''t done this. Fix that, and you''ll prbly be allright.


--
MFC is sorta like the swedish police... It''s full of crap, and nothing can communicate with anything else.


That''s quite possible, but If I try to render using DrawIndexedPrimitive and my Index buffer it dosen''t render anything, why is that ?

Share this post


Link to post
Share on other sites
Well, to that i don''t have any easy answers.
Could be a number of things, first of all remove the
settexture and the texturestages. If you''ve set a texture that''s faulty or not loaded, you would get nothing.
Second, i don''t know what your call to drawindexedprimitive looks like, could be something wrong in there.
Third, i haven''t checked the setupcode for errors.
Fourth, you might want to turn of culling, using setrenderstate(D3DRSCULLMODE, D3DCULL_NONE) or whatever the RS is called =)


--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites

   

m_pd3dDevice->DrawIndexedPrimitive( D3DPT_LINELIST,
0,
nSkybox,
0, nSkyInd/3);


That's my DrawIndexedPrimitive, the Texture I'm using is the same as always, no problems with that.. Will try that thing about culling though..

Thank you...

Edit: Fixing some source formatting, looked awful...

[edited by - JoCCo on April 29, 2002 7:51:17 PM]

Share this post


Link to post
Share on other sites
It still looks awfull

using /3 looks a bit outofplace... /2 sounds much better, since you''re using 2 indices per line...



--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites
I noticed now you''ve got normals in the vertices...
I asume you''ve set them up correctly, got a light on, or turned lighting off? And if you''ve turned off lighting, that you''ve set a diffuse in the FVF? and that if you''re using lights, you''ve set up the material?
I would recommend adding a diffuse and running without lights atm. Texture and lighting is stuff you can add once you''ve got the basics up and running =)


--
MFC is sorta like the swedish police... It''''s full of crap, and nothing can communicate with anything else.

Share this post


Link to post
Share on other sites