View more

View more

View more

### Image of the Day Submit

IOTD | Top Screenshots

### The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

# D3DXMatrixOrthoOffCenterLH replacement, 2D graphics without RHW

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1xtremeqg  Members

Posted 31 August 2007 - 02:28 PM

Quite often people face the problem of aligning texels with pixels. There are plenty documents found on the theory behind this, but few providing any solution other than "shift your vertices -0.5 upwards and -0.5 to the left. Many took this literally, and are doing this per vertex. Of course this will cause a severe performance penalty. Another approach would be by using the FVF_XYZRWH parameter (if you can call it that) to bypass all the transformation matrixes. This again translates to a performance penalty. Instead of using FVF_XYZRWH, it would be more beneficial to set your matrixes accordingly. An even better approach would be to include the -0.5 shift as well. When applying this to the projection matrix, you can take things even further by adjusting this matrix to function in a more logical sense. This will make 2D graphics (tile games, side scrollers, UI development) extremely easy. The following code is a modified version of the D3DXMatrixOrthoOffCenterLH library function.
void d3d_2d_ortho(D3DMATRIX * m, const float w, const float h, const float znear, const float zfar) {

ZeroMemory(m, sizeof(D3DMATRIX));

m->_11 = 2.0f / w;
m->_22 = 2.0f / -h;
m->_33 = 1.0f / (zfar - znear);
m->_41 = (w + 1.0f) / -w;
m->_42 = (h + 1.0f) / h;
m->_43 = znear / (znear - zfar);
m->_44 = 1.0;
}

Placing your textures is now as simple as drawing on your desktop. It will give you a simple canvas where the top left is 0, 0 and the bottom right equals w, h.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.