about the render sequence
hi all,I am a chinese student, and a beginner of the game program.
I want to know how can i render the objects accordding to the depth of objects.
It means render the object(depth:0.5f)first,and then render the object(depth:10.0f).
the code is here:
stD3DVertex objData1[] =
{
{-0.3f, -0.4f, 0, D3DCOLOR_XRGB(255,255,255), 0, 1},
{0.3f, -0.4f, 0, D3DCOLOR_XRGB(255,255,255), 1, 1},
{0.3f, 0.4f, 0, D3DCOLOR_XRGB(255,255,255), 1, 0},
{0.3f, 0.4f, 0, D3DCOLOR_XRGB(255,255,255), 1, 0},
{-0.3f, 0.4f, 0, D3DCOLOR_XRGB(255,255,255), 0, 0},
{-0.3f, -0.4f, 0, D3DCOLOR_XRGB(255,255,255), 0, 1}
};
stD3DVertex objData2[] =
{
{-0.3f, -0.4f,0.3f, D3DCOLOR_XRGB(255,255,255), 0, 1},
{0.3f, -0.4f, 0.3f, D3DCOLOR_XRGB(255,255,255), 1, 1},
{0.3f, 0.4f, 0.3f, D3DCOLOR_XRGB(255,255,255), 1, 0},
{0.3f, 0.4f, 0.3f, D3DCOLOR_XRGB(255,255,255), 1, 0},
{-0.3f, 0.4f, 0.3f, D3DCOLOR_XRGB(255,255,255), 0, 0},
{-0.3f, -0.4f, 0.3f, D3DCOLOR_XRGB(255,255,255), 0, 1}
};
void RenderScene()
{
// Clear the backbuffer.
g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
// Begin the scene. Start rendering.
g_D3DDevice->BeginScene();
D3DXMatrixRotationY(&g_rotation2,g_angle);
// Build the world matrix and update angle.
g_worldMatrix =g_rotation2;
g_angle += 0.01f;
if(g_angle >= 360) g_angle = 0.0f;
// Set the world matrix.
//g_D3DDevice->SetTransform(D3DTS_WORLD, &g_worldMatrix);
// Apply the view (camera).
g_D3DDevice->SetTransform(D3DTS_VIEW, &g_ViewMatrix);
g_D3DDevice->SetTexture(0, g_Texture);
g_D3DDevice->SetStreamSource(0, g_VertexBuffer2,
0, sizeof(stD3DVertex));
g_D3DDevice->SetFVF(D3DFVF_VERTEX);
g_D3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
// Draw square.
g_D3DDevice->SetTexture(0, g_Texture);
g_D3DDevice->SetStreamSource(0, g_VertexBuffer1,
0, sizeof(stD3DVertex));
g_D3DDevice->SetFVF(D3DFVF_VERTEX);
g_D3DDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
// End the scene. Stop rendering.
g_D3DDevice->EndScene();
// Display the scene.
g_D3DDevice->Present(NULL, NULL, NULL, NULL);
}
thanks for telling me。appreciate it。
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement