I am trying to render a 3D scene in the background behind an interface of 2D buttons. I also want to be able to hit test the boxes vs the mouse very easily. What is the easiest way to do this? I was thinking that I could just change the projection, viewing, and world matrices after having rendered the perspective scene to fitting an orthographic projection but this doesn't seem to work. For some reason I can't get the second set of stuff to render. Basically my current approach is rendering like this:
*Setup perspective cam*
*Render perspective background scene*
*Setup orthographic cam*
*Render orthographic interface scene*
Is there anything else I need to do to get this to work? How am I going to hit test the buttons? I'm setting my matricies with this function:
[SOURCE]
D3DXMATRIX mPerspective, mView, mWorld;
D3DXVECTOR3 vEye, vAt, vUp;
vEye.x = 0.0;
vEye.y = 0.0;
vEye.z = 0.0;
vAt.x = 0.0;
vAt.y = 0.0;
vAt.z = 1.0;
vUp.x = 0.0;
vUp.y = 1.0;
vUp.z = 0.0;
D3DXMatrixOrthoLH(&mPerspective, 10.0f, 10.0f, 1.0, 10.0);
CBase::m_pDevice->SetTransform(D3DTS_PROJECTION, &(D3DMATRIX)mPerspective);
D3DXMatrixIdentity(&mWorld);
CBase::m_pDevice->SetTransform(D3DTS_WORLD, &(D3DMATRIX)mWorld);
D3DXMatrixLookAtLH(&mView, &vEye, &vAt, &vUp);
CBase::m_pDevice->SetTransform(D3DTS_VIEW, &(D3DMATRIX)mView);
[/SOURCE]
and I'm trying to render a sample box with this setup code:
[SOURCE]
if(FAILED(CBase::m_pDevice->CreateVertexBuffer(sizeof(TextureVertex_t)*6, D3DCREATE_HARDWARE_VERTEXPROCESSING,
D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1, D3DPOOL_DEFAULT,
&m_pButton, NULL))) {
return false;
}
TextureVertex_t *pVertices;
if(FAILED(m_pButton->Lock(0, 0, (void **)&pVertices, 0))) {
return false;
}
pVertices[0].x = 0.0f;
pVertices[0].y = 0.0f;
pVertices[0].z = 0.0f;
pVertices[0].u = 0.0f;
pVertices[0].v = 0.0f;
pVertices[1].x = BUTTON_SIZEX;
pVertices[1].y = 0.0f;
pVertices[1].z = 0.0f;
pVertices[1].u = 1.0f;
pVertices[1].v = 0.0f;
pVertices[2].x = 0.0f;
pVertices[2].y = BUTTON_SIZEY;
pVertices[2].z = 0.0f;
pVertices[2].u = 0.0f;
pVertices[2].v = 1.0f;
pVertices[3].x = 0.0f;
pVertices[3].y = BUTTON_SIZEY;
pVertices[3].z = 0.0f;
pVertices[3].u = 0.0f;
pVertices[3].v = 1.0f;
pVertices[4].x = BUTTON_SIZEX;
pVertices[4].y = 0.0f;
pVertices[4].z = 0.0f;
pVertices[4].u = 1.0f;
pVertices[4].v = 0.0f;
pVertices[5].x = BUTTON_SIZEX;
pVertices[5].y = BUTTON_SIZEY;
pVertices[5].z = 0.0f;
pVertices[5].u = 1.0f;
pVertices[5].v = 1.0f;
for(int i=0; i<6; i++) {
pVertices.dDiffuse = D3DCOLOR_ARGB(125, 0, 255, 255);
}
if(FAILED(m_pButton->Unlock())) {
return false;
}
[/SOURCE]
and then I'm rendering that vertex buffer with this code:
[SOURCE]
//CBase::m_pDevice->SetTexture(0, NULL);
CBase::m_pDevice->SetStreamSource(0, m_pButton, 0, sizeof(TextureVertex_t));
CBase::m_pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_TEX1);
CBase::m_pDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
[/SOURCE]
Does it have something to do with me not giving it a texture to put on it? I'm sort of stuck. Thanks for the help in advance.
OpenGL Revolutions http://students.hightechhigh.org/~jjensen/