Question

I know that normalised coordinates should be -1 (Left) and +1 (Right) and -1 (Bottom) and +1 (Top)

like this:

enter image description here

But after applying this:

From my onSurfaceChanged method

GLES20.glViewport(0, 0, width, height);
float ratio = (float) width / height;
Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

//The above line can be replaced with:
//Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
//But I get the same results with either frustumM or otrhoM

And this in my onDrawFrame method

Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

(I then pass mMVPMatrix into my custom class's draw method where it is rotated and translated).

But, my co-ordinates seem to change - this is roughly what happens:

enter image description here

As you can see, the x co-ordinates are altered somewhat, -1 and +1 are no longer the edges of the screen (on the device I'm using at the moment, the outer edges become -1.7 and +1.7)

Y coordinates remain unchanged.

Would appreciate if someone could point out where I'm going wrong? I need it to be -1 through +1 like it should be.

Thanks

Was it helpful?

Solution

To my eyes it appears correct. If your screen is not a square, then are you sure you want your x axis to be stretched so it behaves like a square screen? Because if you do that, then if you tell OpenGL to draw a square, it will appear as a rectangle on the screen instead if you don't have your x axis edges be larger than your y axis edges when your screen width is wider than your screen height, as suggested by the image. That's why you pass your ratio to the projection, so it knows how to draw things properly.

What is happening when you draw a regular square on the screen? Is it appearing as a square or a rectangle?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top