开发者

orthographic projection matrix in Opengl-es 2.0

float pfIdentity[] =
{
    -1.0f,0.0f,0.0f,0.0f,
    0.0f,1.0f,0.0f,0.0f,
    0.0f,0.0f,1.0f,0.0f,
    0.0f,0.0f,0.0f,1.0f
};

==================================================================================

    const char* pszVertShader = "\
    attribute highp vec4    myVertex;\
    uniform mediump mat4    myPMVMatrix;\
    invariant gl_Position;\
    void main(void)\
    {\
        gl_Position = myPMVMatrix * myVertex;\
}";

=====================================================================

for(int i = 0; i < 80000; ++i)
{
    glClear(GL_COLOR_BUFFER_BIT);
    int i32Location = glGetUniformLocation(uiProgramObject, "myPMVMatrix");
    glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity);
    glEnableVertexAttribArray(VERTEX_ARRAY)开发者_如何学编程;
    glVertexAttribPointer(VERTEX_ARRAY, 3, GL_FLOAT, GL_FALSE, 0, 0);
    glDrawArrays(GL_TRIANGLES, 0,i);
    eglSwapBuffers(eglDisplay, eglSurface);
}

return 0;
}

p.s : i am doing opengl-es in ubuntu 10.10 with kronos headers , its an emulator for opengl-es 2.0 in linux.


You don't have a projection at all. The Projection-Model-View matrix you're setting the myPMVMatrix uniform to is

float pfIdentity[] =
{
    -1.0f,0.0f,0.0f,0.0f,
    0.0f,1.0f,0.0f,0.0f,
    0.0f,0.0f,1.0f,0.0f,
    0.0f,0.0f,0.0f,1.0f
};

/* ... */

glUniformMatrix4fv( i32Location, 1, GL_FALSE, pfIdentity);

BTW: The idea of uniforms is, that you don't set them at each primitive iteration.

Anyway, this is a identity matrix, and since it's the only transformation applied it will just pass through the vertices as they are to the fragment stage. The solution for your problem is applying a orthographic projection to it, i.e. multiply that matrix with a ortho projection matrix and use the result of that operation instead. http://www.songho.ca/opengl/gl_projectionmatrix.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜