Reputation: 6777
In my app, I have a red square (actually two triangles) that gets drawn onto the screen. However, if the user taps on the screen or moves their finger around, the drawing gets messed up and causes the square to start drawing in what seems to be random patterns. Any idea why this is happening? Code:
Triangle3D *triangles = malloc(sizeof(Triangle3D) * 2);
triangles[0].v1 = Vertex3DMake(x, y, -3.0);
triangles[0].v2 = Vertex3DMake(x+1.0, y-1.0, -3.0);
triangles[0].v3 = Vertex3DMake(x-1.0, y-1.0, -3.0);
triangles[1].v1 = Vertex3DMake(x-1.0, y-1.0, -3.0);
triangles[1].v2 = Vertex3DMake(x+1.0, y-1.0, -3.0);
triangles[1].v3 = Vertex3DMake(x, y-2.0, -3.0);
glLoadIdentity();
glClearColor(0.7, 0.7, 0.7, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glColor4f(1.0, 0.0, 0.0, 1.0);
glVertexPointer(3, GL_FLOAT, 0, triangles);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 18);
glDisableClientState(GL_VERTEX_ARRAY);
glClearColor(0.7, 0.7, 0.7, 1.0);
Upvotes: 0
Views: 215
Reputation: 29065
Looks like you're setting triangles[1].v1
3 times rather than setting triangles[1].v1, v2, & v3
.
Upvotes: 2
Reputation: 18428
The Triangle Strip's vetcies should be arranged like this graph.
The other forms.
Upvotes: 3