PDA

View Full Version : drawElements with gl.POINTS



anvaka
05-23-2012, 05:47 PM
Hey guys, I'm trying to render two points using drawElements() API, but I'm getting only one rendered on my MBP 13", with Intel HD Graphics 3000 384 MB card. Chrome and FF. I don't see any errors neither in dev console nor in webgl inspector.

I must be missing something very obvious. Can someone help please?

Here is the test (http://goo.gl/KrUW4) page.

Shaders:


// vertex shader:
attribute vec3 aVertexPos;

void main(){
gl_Position = vec4(aVertexPos.xy, 0, 1);
gl_PointSize = 32.0;
}

// fragment shader:
precision mediump float;

void main(){
gl_FragColor = vec4(0., 1., 0., 1.);
}


And JS:


var program = webgl.createProgram(vs, fs),
vertexPositionAttributeLocation = gl.getAttribLocation(program, 'aVertexPos'),
verticesPositionsBuffer = gl.createBuffer(),
verticesPositions = new Float32Array([0, 0.5, 0, 0, 0, 0]),

verticesIndecesBuffer = gl.createBuffer(),
verticesIndeces = new Float32Array([0, 1]);

gl.useProgram(program);

gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, verticesIndecesBuffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, verticesIndeces, gl.STATIC_DRAW);

gl.bindBuffer(gl.ARRAY_BUFFER, verticesPositionsBuffer);
gl.bufferData(gl.ARRAY_BUFFER, verticesPositions, gl.STATIC_DRAW);
gl.enableVertexAttribArray(vertexPositionAttribute Location);
gl.vertexAttribPointer(vertexPositionAttributeLoca tion, 3, gl.FLOAT, false, 0, 0);

gl.drawElements(gl.POINTS, 2, gl.UNSIGNED_SHORT, 0);

percocetpenguin
05-31-2012, 12:15 PM
Have you tried using drawArrays?
Also, when I view your test page, I see both elements.
Are you using osx or windows?