Matthew
Matthew

Reputation: 3946

OpenGL ES 1.0 GLU Ortho Projection not rendering basic triangle

I am attempting a 2d layer ontop of my 3d world using android's OpenGL 1.0 ES.

I have a triangle that renders fine when I use 3d perspective but is not rendering when I try to do it with a 2d ortho projection. The below code renders the triangle correctly.

    public void prepareLayerPerspective(GL10 gl)
    {
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluPerspective(gl,45, (float)(1080/1920f),0.1f, 700f);

        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

However, when I attempt to set it up as a Orth projection like this

    public void prepareLayerPerspective(GL10 gl)
    {
        gl.glMatrixMode(GL10.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluOrtho2D(gl,0f,500f,0f,700f);

        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
    }

there are no triangles.

Here is the code used to actually draw the triangles: (but remember, the triangles do render correctly with the perspective frustrum set)

    public void drawFrame(GL10 gl)
    {
        super.drawFrame(gl);

        gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
        gl.glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
        gl.glVertexPointer(3, GL10.GL_FLOAT,0,triangleVB);
        gl.glDrawArrays(GL10.GL_TRIANGLES,0,3);
    }

Here is the constructor to the Triangle class. (scale = 1.0f)

    public Triangle(float scale)
    {
        float triangleCoords[] = {
                -1.0f*scale, -1.0f*scale, 0,
                0.0f, 1.0f*scale, 0,
                1.0f*scale, -1.0f*scale, 0
        };

        ByteBuffer vbb = ByteBuffer.allocateDirect(triangleCoords.length*4);

        vbb.order(ByteOrder.nativeOrder());
        triangleVB = vbb.asFloatBuffer();
        triangleVB.put(triangleCoords);
        triangleVB.position(0);

        rotation = 0.0f;
    }

Upvotes: 0

Views: 82

Answers (1)

kyasbal
kyasbal

Reputation: 1182

As I pointed out on the comment, the specified frustum was so big.

If there were a vertex at (700,0,0) with the frustum you specified, the vertex will be located on left bottom of the display.

Upvotes: 1

Related Questions