I've got some experience with OGL and decided to check out DirectX & D3D.
Orthographic mode works fine for me, but I can't get the matrices to DO anything (world, view, proj).
I've tried following the "tutorials" in the DirectX sdk manual to the letter, and the matrices are constructed correctly (as seen in debugger), but they aren't actually changing my render at all and I can't figure out what else I'm missing.
Graphics constructor (D3D initialization):
Graphics::Graphics(HWND hWnd)
{
if( NULL == ( mD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
throw E_FAIL;
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory( &d3dpp, sizeof(d3dpp) );
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = D3DFMT_UNKNOWN;
if( FAILED( mD3D->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &mD3DDevice ) ) )
throw E_FAIL;
text = new Text(this->mD3DDevice);
}
Graphics Render method:
void Graphics::Render()
{
mD3DDevice->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
mD3DDevice->BeginScene();
// draw shit
D3DXMATRIX perspmatrix;
D3DXMatrixPerspectiveFovLH(&perspmatrix, 3.14159 / 3, 4.f / 3.f, 0.1f, 100.f);
mD3DDevice->SetTransform(D3DTS_PROJECTION, &perspmatrix);
D3DXVECTOR3 eye(0.f, 0.f, -5.f), at(0.f, 0.f, 1.f), up(0.f, 1.f, 0.f);
D3DXMATRIX viewmatrix;
D3DXMatrixLookAtLH(&viewmatrix, &eye, &at, &up);
mD3DDevice->SetTransform(D3DTS_VIEW, &viewmatrix);
D3DXMATRIX* world = new D3DXMATRIX();
D3DXMatrixTranslation(world, 200.f, 20.f, .0f);
graphics->mD3DDevice->SetTransform(D3DTS_WORLD, world);
currentState->Render();
text->Render();
mD3DDevice->EndScene();
mD3DDevice->Present( NULL, NULL, NULL, NULL );
}
currentState->Render() (called during the graphics class render loop, inside beginscene and endscene)
void PlayState::Render()
{
graphics->mD3DDevice->SetStreamSource( 0, mVB, 0, sizeof(CUSTOMVERTEX) );
graphics->mD3DDevice->SetFVF( D3DFVF_CUSTOMVERTEX );
graphics->mD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
graphics->mD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 4, 2 );
graphics->mD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 8, 2 );
graphics->mD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 12, 2 );
}
text->Render() (called during the graphics class render loop, inside beginscene and endscene)
void Text::Render()
{
std::map<std::string, Message>::iterator it = mMessages.begin();
std::map<std::string, Message>::iterator end = mMessages.end();
while (it != end)
{
mFont->DrawText(0, //pSprite
it->second.message, //pString
-1, //Count
&(it->second.rect), //pRect
DT_LEFT|DT_WORDBREAK, //Format,
it->second.color); //Color
++it;
}
}
I'd really appreciate any help - I have the feeling I'm missing 1 method to set some system setting or something like that.
[Edited by - c0uchm0nster on May 30, 2008 1:52:29 AM]