Jumhyn
Jumhyn

Reputation: 6777

Drawing Issues in OpenGL ES

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

Answers (2)

Drew Hall
Drew Hall

Reputation: 29065

Looks like you're setting triangles[1].v1 3 times rather than setting triangles[1].v1, v2, & v3.

Upvotes: 2

AechoLiu
AechoLiu

Reputation: 18428

The Triangle Strip's vetcies should be arranged like this graph. TRIANGLE_STRIP

The other forms.

Figure 1

Upvotes: 3

Related Questions