A few things:
First you need to add gl_PointSize = 1.0; to your vertex shader to tell webgl the size of your gl.POINT .
Secondly, the coordinate you are passing in is the center of each pixel, not the top left corner of each pixel, so
function drawOneBlackPixel( gl, x, y ) {
- Is this what you want.
The working code is here: http://codepen.io/anon/pen/pgBjBy .
Bonus question: what you need to do is manual memory management gl.buffer (gasp) so that you can do gl.drawArrays( gl.POINTS, 0, x ); to draw x points. For example, if you want to draw 3 points in (0,0) (1,1), (2,2), then you need to do gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0.5, 0.5, 1.5, 1.5, 2.5, 2.5], gl.STATIC_DRAW) , and then gl.drawArrays(gl.POINTS, 0, 3);
For example, you can first allocate a Float32Array with a number of 4 points, and whenever you call drawOneBlackPixel , first set Float32Array to [p1x, p1y, 0,0,0,0,0,0] and on the next drawOneBlackPixel it set the array in [p1x, p1y, p2x, p2y, 0,0,0,0] and so on. Of course, you need to handle other things, such as zooming in and copying the Float32Array as needed, and loading the Float32Array onto the GPU as you make changes. The way you handle the erasure of dots also needs to be remembered.