Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenGL ES - using glDrawArrays()

Tags:

opengl-es

I am porting some code from OpenGL to the ES version. I am using glDrawArrays() to draw a triangle in conjuction with glVertexPointer(). However, it doesn't draw on the screen. The complete code is:

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 up the window, it clears with black, but doesn't draw anything. Can someone please spot what I am doing wrong? Thanks.

like image 413
Iceman Avatar asked Dec 28 '22 02:12

Iceman


1 Answers

I see no call to glEnableClientState(GL_VERTEX_ARRAY);. I also see glEnableClientState (GL_COLOR_ARRAY); but no call to glColorPointer(). Perhaps you wrote one when you meant the other?

like image 174
Michael Slade Avatar answered Jan 03 '23 14:01

Michael Slade