2 years ago

#57887

test-img

Androidcoder

How close to zNear can safely push user interface objects for a projection matrix in OpenGL 3.2

I would like to place my user interface elements for an 3D OpenGL game as close as possible to the near clipping plane without them being cut off. For example, with this declaration

Matrix.frustumM(mRenderer.mProjectionMatrix, 0, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 32.0f);

images start rendering at a z value of -1.0, at least theoretically. In practice I find I have to place an object slightly behind this for the draw to show, and the amount depends on the user device. For example, to draw a square that fills the screen I might use:

final float[] squarePositionInterfaceData = {
            -1.0f, 1.0f, -1.0078125f,
            -1.0f, -1.0f, -1.0078125f,
            1.0f, 1.0f, -1.0078125f,
            -1.0f, -1.0f, -1.0078125f,
            1.0f, -1.0f, -1.0078125f,
            1.0f, 1.0f, -1.0078125f
};

This actually draws slightly smaller as it's not quite on the near z plane of -1.0f. I find if I use -1.0 for the z placement, however, the object doesn't draw at all. I also find I have to push objects back slightly for Matrix.orthoM declarations, although with those there is no distortion as distance isn't taken into account in sizing the draw.

Is there a standard distance used to place objects as close as possible to the near z clipping plane without being cut off for the vast majority of user devices?

android

graphics

3d

opengl-es

z-axis

0 Answers

Your Answer

Accepted video resources