Click here to Skip to main content
Sign Up to vote bad
good
See more: C++WindowsDirectX
Hello!!
 
I need to draw something in DirectX 9.
I am interested to work in a way that the coordinates will be adjusted to pixels, while (0,0) will be the TopLeft corner. Here is what I do:
 
RECT clientRect;
::GetClientRect(m_hWIN, &clientRect);
 
D3DXMATRIX matOrtho2D, matIdentity;    
 
D3DXMatrixOrthoOffCenterLH(&matOrtho2D, 0, clientRect.right, 0, clientRect.bottom, 0.0f, 1.0f);
D3DXMatrixIdentity(&matIdentity);
 
g_pDirect3D_Device->SetTransform(D3DTS_PROJECTION, &matOrtho2D);
g_pDirect3D_Device->SetTransform(D3DTS_WORLD, &matIdentity);
g_pDirect3D_Device->SetTransform(D3DTS_VIEW, &matIdentity);
 
This works fine, except the (0,0) is the BottomLeft corner. How can I change it?
Thanks!
Posted 26 Dec '12 - 20:11
Edited 26 Dec '12 - 20:12


2 solutions

DirectX uses the bottome left of the image as its origin, as described here[^].
  Permalink  
This should be added to the code:
D3DXMatrixTranslation(&matTranslate, 0, (float)clientRect.bottom, 0.0f);
D3DXMatrixRotationX(&matFlip, D3DXToRadian(180));
D3DXMATRIX matCoordTransform = matFlip * matTranslate;
 
g_pDirect3D_Device->SetTransform(D3DTS_WORLD, &matCoordTransform);
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 358
1 OriginalGriff 355
2 Arun Vasu 345
3 Maciej Los 208
4 Zoltán Zörgő 189
0 Sergey Alexandrovich Kryukov 9,755
1 OriginalGriff 7,559
2 CPallini 4,018
3 Rohan Leuva 3,362
4 Maciej Los 2,951


Advertise | Privacy | Mobile
Web01 | 2.6.130523.1 | Last Updated 27 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid