Languages

Menu
Sites
Language
To produce a perspective projection on Tizen.

Although it is claimed that Tizen2.3 support both OpenGL ES 1.1 and 2.0. The convenient tools to set the projection and do other transformation in OpenGL ES 1.1 are not introduced in by Tizen.

So Tizen2.3 indeed only support OpenGL ES 2.0 from Tizen Application user perspection. OpenGL ES 2.0 do not support those transformation tools anymore, developer need to do the transformation by themselves.

Let's talk about how to produce a perspective projection by multiply the vertice matrix with OpenGL transformation matrix.

To make the objects on the screen drawn like what we see in the real world, we need to produce the perspective projection by the frustum as below.

                               OpenGL Perspective Viewing Frustum

This frustum determines which objects or portions of objects will be clipped out. Also, it determines how the 3D scene is projected onto the screen. The Objects in the frustum can be seen and it will be shown smaller when it away from the near clipping plane. Assuming your device screen is just on the near clipping plane.

About the theory of how to construct the projection matrix, please reference the link below.

http://www.songho.ca/opengl/gl_projectionmatrix.html

Ultimately, we get the projection matrix of the frustum;

            OpenGL Perspective Projection Matrix and Inverse Matrixfor a general frustum,

                            l = left, r = right, b = bottom, t = top, n = zNear, f = zFar

In OpenGL ES 1.1, the tool to do this projection is the function glFrustum() which requires 6 parameters.

    glFrustum(left, right, bottom, top, zNear, zFar);

It is in fact a transforming on the current matrix which is the top of the OpenGL matrix stack.

In Tizen, we do the same transforming on the input matrix by following function.

    void view_set_frustum(float* result, const float left, const float right,
                const float bottom, const float top, const float near, const float far) {
            float diffx = right - left;
            float diffy = top - bottom;
            float diffz = far - near;
 
            if ((near <= 0.0f) || (far <= 0.0f) || (diffx <= 0.0f) || (diffy <= 0.0f)
                    || (diffz <= 0.0f))
                return;

            result[0] = 2.0f * near / diffx;
            result[1] = 0.0f;
            result[2] = 0.0f;
            result[3] = 0.0f;

            result[4] = 0.0f;
            result[5] = 2.0f * near / diffy;
            result[6] = 0.0f;
            result[7] = 0.0f;

            result[8] = (right + left) / diffx;
            result[9] = (top + bottom) / diffy;
            result[10] = -(near + far) / diffz;
            result[11] = -1.0f;

            result[12] = 0.0f;
            result[13] = 0.0f;
            result[14] = -2.0f * near * far / diffz;
            result[15] = 0.0f;
    }

There is an alternative representation to the frustum is;

Corresponding to this represenation, the tool function glPerspective() only requires 4 parameters.

      gluPerspective(fovy, aspect, zNear, zFar);

In Tizen, we replace it by function:

    void view_set_perspective(float* result, const float fovy,
                const float aspect, const float near, const float far) {
            float fovradian = fovy / 360.0f * M_PI;
            float top = tanf(fovradian) * near;
            float right = top * aspect;


            view_set_frustum(result, -right, right, -top, top, near, far);
    }

 

Responses

2 Replies
Jean Yang

Please refer to another topic about Homogeneous Coordinates, it's the mathematic foundation for perspective projection.

https://developer.tizen.org/forums/native-application-development/homogeneous-coordinates?tab=active

Jean Yang

Sorry, my mistatke!

Tizen 2.3 support both OpenGL ES 1.1 and OpenGL ES 2.0.

Defaultly, if you do not explicity declare the glview version to OpenGL-ES 1.1 as below sentence, the OpenGL version is deemed as OpenGL-ES 2.0.

   /* Create a GLView with an OpenGL-ES 1.1 context */
   obj = elm_glview_version_add(ad->win, EVAS_GL_GLES_1_X);

And defaultly, you create the GLView by following codes.

    /* Create and initialize GLView */
    gl = elm_glview_add(ad->conform);