Imagination PowerVR SDK Blog

Mat4::Ortho() example


#1

Hello,
I’m using the 3_00_00_06 SDK from TI for OMAP3530.  I have a simple gles2 app with a shader which works fine using a projection matrix.  I can rotate my model 45 degrees and get expected results.  When I use a PVRT::Mat4::Ortho() I end up with an unsatisfying blank screen.  In other words,

// this works:
float aspect = screenWidth/screenHeight;
bool bRotate = false;
PVRT::Mat4::PerspectiveFovFloatDepthRH(PI/6.0, aspect, 1.0, PVRT::Mat4::OGL, bRotate);

// this doesn’t work:
float NEAR_CLIP=10.0;
float FAR_CLIP=-10.0;
PVRT::Mat4::Ortho(screenWidth/-2.0, screenHeight/2.0, screenWidth/2.0, screenHeight/-2.0, NEAR_CLIP, FAR_CLIP, PVRT::Mat4::OGL, bRotate);

Is there an example app which uses an orthographic projection?  A grep in the SDK sources didn’t turn up anything.

Another data point: when I just use a rotation matrix of .001 degrees around the Y axis, (no additional perspective or ortho matrix) I get a thin vertical block of pixels suggesting depth clipping is against me.  I assume this will go away once proper near/far planes are set.

Thanks!


#2

Perspective has another “scale” factory. So if you have small triangle created with size around 1.0f it will be as 1px in screen in Ortho mode.





Try to use -1, 1, 1, -1 for left, top, right, bottom, and you will get similar result to Perspective ( considering scale ).





But if you want Ortho for creating HUD, you will need to scale up your objects.





You asked also for exmaple, Ortho is used in Water Demo.



#3

Hi michax.  Thanks for your reply.

I was not able to find source for the water or sailboat demo in the SDK nor elsewhere, but I had another look at using PVRTMatrixOrthoRHF() and it seems to be doing what I need.  I started with the 02_HelloTriangle example in the GLES2 training, passed the matrix generated by  PVRTMatrixOrthoRHF() to glUniformMatrix4fv() instead of the identity matrix and got expected results.






#4

Please post further if you encounter any difficulties. Incidentally, the Water demo should be here, in the SDK:

SDKPackageDemosWater


#5

Thanks you for your sharing ! It need for me to understand about ortho
 I’m studying about it

Wink