mummey
05-23-2006, 10:27 AM
Could you provide more information? Like snippets of the code in question?
Cozmo
05-23-2006, 12:08 PM
Sure:
//////////This is the setup function i use to setup the buffers
bool Setup()
{
//
// Create vertex and index buffers.
//
device->CreateVertexBuffer(
8 * sizeof(Vertex),
D3DUSAGE_WRITEONLY,
Vertex::FVF,
D3DPOOL_MANAGED,
&vb,
0);
device->CreateIndexBuffer(
36 * sizeof(WORD),
D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_MANAGED,
&ib,
0);
Vertex* vertices;
vb->Lock(0, 0, (void**)&vertices, 0);
// vertices of a unit cube
vertices[0] = Vertex(-2.0f, -1.0f, -1.0f);
vertices[1] = Vertex(-1.0f, 1.0f, -1.0f);
vertices[2] = Vertex( 1.0f, 1.0f, -1.0f);
vertices[3] = Vertex( 1.0f, -1.0f, -1.0f);
vertices[4] = Vertex(-1.0f, -1.0f, 0.0f);
vertices[5] = Vertex(-1.0f, 1.0f, 0.0f);
vertices[6] = Vertex( 1.0f, 1.0f, 0.0f);
vertices[7] = Vertex( 1.0f, -1.0f, 0.0f);
vb->Unlock();
// define the triangles of the cube:
WORD* indices = 0;
ib->Lock(0, 0, (void**)&indices, 0);
// front side
indices[0] = 0; indices[1] = 1; indices[2] = 2;
indices[3] = 0; indices[4] = 2; indices[5] = 3;
// back side
indices[6] = 4; indices[7] = 6; indices[8] = 5;
indices[9] = 4; indices[10] = 7; indices[11] = 6;
// left side
indices[12] = 4; indices[13] = 5; indices[14] = 1;
indices[15] = 4; indices[16] = 1; indices[17] = 0;
// right side
indices[18] = 3; indices[19] = 2; indices[20] = 6;
indices[21] = 3; indices[22] = 6; indices[23] = 7;
// top
indices[24] = 1; indices[25] = 5; indices[26] = 6;
indices[27] = 1; indices[28] = 6; indices[29] = 2;
// bottom
indices[30] = 4; indices[31] = 0; indices[32] = 3;
indices[33] = 4; indices[34] = 3; indices[35] = 7;
ib->Unlock();
D3DXVECTOR3 position(2.0f, 6.0f, 0.0f);
D3DXVECTOR3 target(-1.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMATRIX V;
D3DXMatrixLookAtLH(&V, &position, &target, &up);
device->SetTransform(D3DTS_VIEW, &V);
//
// Set the projection matrix.
//
D3DXMATRIX proj;
D3DXMatrixPerspectiveFovLH(
&proj,
D3DX_PI * 0.5f, // 90 - degree
(float)width / (float)height,
1.0f,
1000.0f);
device->SetTransform(D3DTS_PROJECTION, &proj);
//
// Switch to wireframe mode.
//
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
return true;
}
//////////This is the display function which renders the cube
void Display(float timeDelta)
{
D3DXMATRIX Rx, Ry;
D3DXMatrixRotationX(&Rx, 3.14f / 6.0f);
static float y = 0.0f;
D3DXMatrixRotationY(&Ry, y);
y += timeDelta;
if( y >= 6.28f )
y = 0.0f;
D3DXMATRIX p = Rx * Ry;
device->SetTransform(D3DTS_WORLD, &p);
device->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(255,255,255),1.0f,0);
device->BeginScene();
device->SetStreamSource(0, vb, 0, sizeof(Vertex));
device->SetIndices(ib);
device->SetFVF(Vertex::FVF);
// Draw cube.
device->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12);
device->EndScene();
device->Present(0,0,0,0);
}
Cozmo
05-24-2006, 01:08 PM
Besides I'm having some trouble releasing the buffers (I already know why, I guess), and I'm not checking the device capabilities because I was eager to run the app.
CGTalk Moderation
05-24-2006, 01:08 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.