D3D Ortho mode

Started by
8 comments, last by mess 21 years, 7 months ago
Where can i find some info on this? im trying to desin a console, and dont know how to go about it. thanks
Advertisement
The DirectX SDK Help file.

Look up D3DXMatrixOrthoLH in the index, for starters.
I made two functions in my render class Go3D() and Go2D().

Whenever i call Go2D() my scene disaperas, can somone check if i am going in ortho mode correctly?

thanks

void CRender::Go3D()
{
D3DXMatrixIdentity(&m_matProj);
D3DXMatrixPerspectiveFovLH( &m_matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_matProj );
}

void CRender::Go2D()
{
D3DXMatrixOrthoLH(&m_matProj, m_pWindow->m_Width, m_pWindow->m_Height, 0.0f, 1.0f);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &m_matProj);

}

[edited by - mess on September 15, 2002 12:01:11 AM]
I haven't checked you parameters, but on a different note, it will be slightly more efficient if you create the matrices on initialization and just call SetTransform() in these functions.

Also, there is no reason to call D3DXMatrixIdentity before D3DXMatrixPerspective...

Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces"

[edited by - CrazedGenius on September 15, 2002 12:11:01 AM]
Author, "Real Time Rendering Tricks and Techniques in DirectX", "Focus on Curves and Surfaces", A third book on advanced lighting and materials
http://24.43.48.130/b/Gatigy/CRender.cpp

thats my code if u can take a look gimme some pointers too.

thanks alot
I''ll take a look at your code a little later, but don''t forget to disable the z-buffer when you go into 2D mode, and enable it when you go into 3D mode.
I disabled it, and the quad still disapears when i move my camera.


//o-----------------------------------------------------------------------------------o
//| Go into 3d mode
//|
//o-----------------------------------------------------------------------------------o

void CRender::Go3D()
{
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );
D3DXMatrixIdentity(&m_matProj);
D3DXMatrixPerspectiveFovLH( &m_matProj, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &m_matProj );
}

//o-----------------------------------------------------------------------------------o
//| Go into ortho mode
//|
//o-----------------------------------------------------------------------------------o

void CRender::Go2D()
{
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );
D3DXMatrixIdentity(&m_matProj);
D3DXMatrixOrthoLH(&m_matProj, m_pWindow->m_Width, m_pWindow->m_Height, 1.0f, 1.0f);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &m_matProj);
}
don''t forgett to reset your view/world matrices...
don''t forgett to reset your view/world matrices...

btw. you can also do the 2d-part with transformed vertices, if you don''t need matrix math... -> i.e. D3DFVF_XYRRHW
Okay, i changed the code a bit, now im not seeing anything, just a blank screen, please help

thanks

//o-----------------------------------------------------------------------------------o
//| Go into 3d mode
//|
//o-----------------------------------------------------------------------------------o

void CRender::Go3D()
{
D3DXMATRIX Identity;
D3DXMATRIX Matrix3D;
D3DXMatrixIdentity(&Identity);

m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_TRUE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, TRUE );

D3DXMatrixPerspectiveFovLH( &Matrix3D, D3DX_PI/4, 1.0f, 1.0f, 1000.0f );
m_pd3dDevice->SetTransform( D3DTS_PROJECTION, &Matrix3D );

m_pd3dDevice->SetTransform(D3DTS_WORLD, &Identity);
m_pd3dDevice->SetTransform(D3DTS_VIEW, &Identity);
}

//o-----------------------------------------------------------------------------------o
//| Go into ortho mode
//|
//o-----------------------------------------------------------------------------------o

void CRender::Go2D()
{
D3DXMATRIX Identity;
D3DXMATRIX Matrix2D;
D3DXMatrixIdentity(&Identity);

m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
m_pd3dDevice->SetRenderState( D3DRS_ZWRITEENABLE, FALSE );

D3DXMatrixOrthoLH(&Matrix2D, m_pWindow->m_Width, m_pWindow->m_Height, 5.0f, 1000.0f);
m_pd3dDevice->SetTransform(D3DTS_PROJECTION, &Matrix2D);

m_pd3dDevice->SetTransform(D3DTS_WORLD, &Identity);
m_pd3dDevice->SetTransform(D3DTS_VIEW, &Identity);
}

This topic is closed to new replies.

Advertisement