Reputation: 429
I have spent quite some time and effort trying to figure out how to draw a line in opneGL es on the iPhone. Here is my code
myMagicVertices[0] = -0.5;
myMagicVertices[1] = -0.5;
myMagicVertices[2] = 2.0;
myMagicVertices[3] = 2.0;
glDrawElements(GL_LINE_STRIP, 2, GL_UNSIGNED_BYTE, myMagicVertices);
But all I see on the screen is a blank screen. I am at my wits end. Can any body point me to the right dirrection
Upvotes: 2
Views: 8362
Reputation: 7400
the last argument of glDrawElements() should be a list of indices into your vertex list, not the vertices themselves. You also need to tell OpenGL about you list of vertices.
the code should look something like this:
float vertices[] = {-0.5f, -0.5f, 0.5f, 0.5f};
unsigned int indices[] = {0, 1};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawElements(GL_LINES, 2, GL_UNSIGNED_INT, indices);
edit: I think this would also work:
float vertices[] = {-0.5f, -0.5f, 0.5f, 0.5f};
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertices);
glDrawArrays(GL_LINES, 0, 2);
Upvotes: 3