I have a vertex array that has 8 vertices, every vertex is represented by two coordinates.
I have used glVertexPointer function to use this array in drawing with glDrawArray function.
void datasource()
{
GLfloat vertex1[]={ -1.000000, 0.500000, -0.700000, 0.500000, -1.000000, 0.800000, -0.700000, 0.800000, -0.400000, 0.500000, -0.100000, 0.500000, -0.400000, 0.800000, -0.100000, 0.800000 };
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 0, vertex1);
}
void display()
{
frame++;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDrawArrays(GL_LINES, 0, 2);
glutSwapBuffers();
glutPostRedisplay();
}
When I try to draw line using first two vertices, I do not see anything but it should appear horizontal line. What am I doing wrong?
What am I doing wrong?
Your data is on the stack of a function, you probably call to set the array pointer. Unfortunately as soon as the function returns it's stack frame gets deallocated and that pointer becomes invalid.
So either use a VBO to copy that data to a persistent OpenGL object first. Or allocate that memory on the heap or as a global variable.
Also you should call glEnableClientState and glVertexPointer right before the corresponding glDraw… function call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With