OpenGL ES - using glDrawArrays ()

I am transferring some code from OpenGL to the ES version. I use glDrawArrays () to draw a triangle in conjunction with glVertexPointer(). However, he does not draw on the screen. Full code:

void init(void) 
{
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glShadeModel (GL_FLAT);
}

void display(void)
{
    glEnableClientState (GL_COLOR_ARRAY);
    glClear (GL_COLOR_BUFFER_BIT);
    glColor4f (0.0, 0.0, 1.0, 1.0);
    glLoadIdentity ();           


    glTranslatef(0, 0, -20);


    const GLfloat triVertices[] = { 
        0.0f, 1.0f, 0.0f, 
        -1.0f, -1.0f, 0.0f, 
        1.0f, -1.0f, 0.0f 
    };

    glVertexPointer(3, GL_FLOAT, 0, triVertices);
    glDrawArrays(GL_TRIANGLES, 0, 3);
    glDisableClientState(GL_VERTEX_ARRAY);
    glFlush ();
}

void reshape (int w, int h)
{
    glViewport (0, 0, (GLsizei) w, (GLsizei) h); 
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity ();
    glFrustum (-1.0, 1.0, -1.0, 1.0, 1.5, 20.0);
    glMatrixMode (GL_MODELVIEW);
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize (400, 400); 
    glutInitWindowPosition (100, 100);
    glutCreateWindow (argv[0]);
    init ();
    glutDisplayFunc(display); 
    glutReshapeFunc(reshape);
    glutMainLoop();
    return 0;
}

GLUT opens a window, it is cleared in black, but draws nothing. Can anyone understand what I'm doing wrong? Thank.

+3
source share
1 answer

I do not see the call glEnableClientState(GL_VERTEX_ARRAY);. I also see glEnableClientState (GL_COLOR_ARRAY);, but do not call on glColorPointer(). Perhaps you wrote one when you meant the other?

+9
source

All Articles