简体   繁体   中英

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);

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

The other forms.

图1

看起来你设置triangles[1].v1 3倍,而不是设置triangles[1].v1, v2, & v3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM