OpenGL: glDrawElements doesn’t draw

opengl

I'm trying out the Vertex Arrays stuff but for some reason the glDrawElements command doesn't draw anything for me. I can draw using glBegin/glEnd and glDrawElements in between, but glDrawElements doesn't work. Here's a code snippet:

These arrays get set up in the constructor:

double points[100];
GLint indices[50];

for (int i=0; i < 50; i++){
    points[2*i] = radius * cos(i*2*PI/50);
    points[2*i + 1] = radius * sin(i*2*PI/50);
    indices[i] = i;
}

Working code using only the points array with glArrayElement:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glBegin(GL_POLYGON);
    for (int i=0; i < 50; i++){
        glArrayElement(i);
    }
    glEnd();
}

Also working code, using points array, specific indices accessed via indices array:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glBegin(GL_POLYGON);
    for (int i=0; i < 50; i++){
        glArrayElement(indices[i]);
    }
    glEnd();
}

NON-working code, attempting to use glDrawElements:

void GLCircle::draw()
{
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_DOUBLE, 0, points);

    glDrawElements(GL_POLYGON, 4, GL_INT, indices);
}

Any advice? It's not entirely necessary for me to use it at this point, but it's disturbing that it doesn't work…

Best Answer

The 2nd parameter of glDrawElements is count, so shouldn't 4 be the numbers of indices (50)?

Related Topic