Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make this polygon render as a complete shape rather than a crescent?
    text
    copied!<p>I'm using the following javascript function to create an array of vertices to pass to a buffer when creating a shape. It should calculate the vertices of an n-sided regular polygon with the first vertex located at the origin. The buffers are then created and stored as properties on the shape object that was passed to the function.</p> <pre><code>var vertices = []; // Create each vertex by calculating the position of the new vertex relative // to the old then adding on to the old position // Begin by setting up the first vertex at the origin vertices [0] = 0.0; vertices [1] = 0.0; vertices [2] = 0.0; var oldX = 0.0; var oldY = 0.0; for (var i = 0; i &lt; shape.numberOfSides; i++) { var theta = i * 2 * Math.PI / shape.numberOfSides; var y = shape.sideLength * Math.sin(theta); var x = shape.sideLength * Math.cos(theta); y += oldY; x += oldX; var start = (i+1) * 3; vertices [start] = x; vertices [start + 1] = y; vertices [start + 2] = 0.0; oldX = x; oldY = y; } // Create a buffer and store the vertices on it shape.verticesBuffer = gl.createBuffer(); gl.bindBuffer(gl.ARRAY_BUFFER, shape.verticesBuffer); gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(vertices), gl.STATIC_DRAW); </code></pre> <p>This works absolutely fine for triangles, but for pentagons or above the shape is not complete - it looks like a crescent. I've included a screenshot below of the working triangle and a non-working hexagon, both created with the same function.</p> <p><a href="http://i39.tinypic.com/ndoj8z.png" rel="nofollow">http://i39.tinypic.com/ndoj8z.png</a></p> <p>Can anyone see what it is that I'm doing wrong?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload