unneeded triangles

10 views
Skip to first unread message

merve t

unread,
Jun 24, 2011, 4:36:17 AM6/24/11
to webgl-d...@googlegroups.com
Hi,
i have a data array like this:

0,-1,0,0,-2,0,1,-2,0,2,0,0,1,- 1,0,2,-1,0,0,-1,0,1,-1,0,1,-2, 0

i need to give number to these coordinats to tell my problem:

0=     0,-1,0,
1=    0,-2,0,
2=    1,-2,0,
3=    2,0,0,
4=    1,-1,0,
5=    2,-1,0,
6=    0,-1,0,
7=   1,-1,0,
8=    1,-2,0


i want only see the triangles
0,1,2 // first three vertices
3,4,5 // second three vertices
6,7,8 // third three vertices

but i see

0,1,2
3,4,5
6,7,8

as i expected, BUT also see as UNNEEDED:

2,3,4

5,6,7

i have tried so far in an initbuffers() function:

shapeVertexPositionBuffer = gl.createBuffer();
        gl.bindBuffer(gl.ARRAY_BUFFER, shapeVertexPositionBuffer);

shapeVertexIndexBuffer = gl.createBuffer();
        var indexData = [0,1,2,3,4,5,6,7,8];
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, shapeVertexIndexBuffer);
shapeVertexIndexBuffer.itemSize = 3;
        shapeVertexIndexBuffer.numItems = indexData.length/3;

i can see only one triangle,
i tried also:

        gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(indexData), gl.STATIC_DRAW);
        shapeVertexIndexBuffer.itemSize = 1;
        shapeVertexIndexBuffer.numItems = indexData.length;

i see unneeded triangles.

i do not know what to do to tell webgl to get only 012,345 and 678
thanks for any response

Daniel Koch

unread,
Jun 24, 2011, 6:58:41 AM6/24/11
to webgl-d...@googlegroups.com
Can we see your draw command?

It sounds like you are drawing with TRIANGLE_STRIP instead of with TRIANGLES.

Hope this helps,
Daniel
---
                        Daniel Koch -+- dan...@transgaming.com
Senior Graphics Architect -+- TransGaming Inc.  -+- www.transgaming.com

merve t

unread,
Jun 24, 2011, 7:07:51 AM6/24/11
to webgl-d...@googlegroups.com
hi thanks for urgent reply,
i tried with triangles and it is working now, there is no unneeded triangles but now there are missing triangles, like triangle holes in the objects.
here is my drawscene code:

function drawScene() {
        gl.viewport(0, 0, gl.viewportWidth, gl.viewportHeight);
        gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
 
        mat4.perspective(45, gl.viewportWidth / gl.viewportHeight, 0.1, 100.0, pMatrix);
 
        mat4.identity(mvMatrix);
   
        mat4.translate(mvMatrix, [0.0, 0.0, -75.0]);
       
    mat4.multiply(mvMatrix, moonRotationMatrix);
        gl.bindBuffer(gl.ARRAY_BUFFER, shapeVertexPositionBuffer);
        gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, shapeVertexPositionBuffer.itemSize, gl.FLOAT, false, 0, 0);
 
        gl.bindBuffer(gl.ARRAY_BUFFER, shapeVertexColorBuffer);
        gl.vertexAttribPointer(shaderProgram.vertexColorAttribute, shapeVertexColorBuffer.itemSize, gl.FLOAT, false, 0, 0);
 
    gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, shapeVertexIndexBuffer);
        setMatrixUniforms();
    gl.drawElements(gl.TRIANGLES, shapeVertexIndexBuffer.numItems, gl.UNSIGNED_SHORT, 0);
    }

2011/6/24 Daniel Koch <dan...@transgaming.com>
Reply all
Reply to author
Forward
0 new messages