Hey,
I have some experience with openGl
Recently i dicided it would be fun to move over to Javascript+WebGL.
But for some reason i cant get anything to display on my screen.
I simplified my code to a 2d triangle but i still cant seem to get it to work.
i have been staring at this code for to long now and i hoped somebody
else might know what i am doing wrong.
// init canvas
m_gl.clearColor(0.1, 0.8, 0.1, 1.0);
m_gl.disable(m_gl.DEPTH_TEST);
// in loop
m_gl.clear(m_gl.COLOR_BUFFER_BIT);
m_gl.viewport(0, 0, m_width, m_heigth);
m_gl.disable(m_gl.DEPTH_TEST);
// Somewhere later.
var DDraw2dQuad = [];
var Draw2dQuad = function(x, y, width, hight, color)
{
/*m_gl.useProgram(DDraw2dQuad.program);*/
m_gl.bindBuffer(gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex);
m_gl.vertexAttribPointer(DDraw2dQuad.attrib_vertexposition, 2, m_gl.FLOAT, false, 0, 0);
m_gl.drawArrays(m_gl.TRIANGLE, 0, 3);
}
this.Draw2dQuad = Draw2dQuad;
Draw2dQuad.Init = function()
{
DDraw2dQuad.program = m_sm.GetProgram("2DCOLOR");
m_gl.useProgram(DDraw2dQuad.program);
DDraw2dQuad.attrib_vertexposition = m_gl.getAttribLocation(DDraw2dQuad.program, "aVertexPosition");
m_gl.enableVertexAttribArray(DDraw2dQuad.attrib_vertexposition);
DDraw2dQuad.buffer_vertex = m_gl.createBuffer();
m_gl.bindBuffer(m_gl.ARRAY_BUFFER, DDraw2dQuad.buffer_vertex);
var vertices = [
0.0, 1.0,
-1.0, -1.0,
1.0, -1.0
]; // Temponary
m_gl.bufferData(m_gl.ARRAY_BUFFER, new Float32Array(vertices), m_gl.STATIC_DRAW);
}
Shaders:
vertex
attribute vec2 aVertexPosition;
void main(void) {
gl_Position = vec4(aVertexPosition, 1.0, 1.0);
}
fragment
#ifdef GL_ES
precision highp float;
#endif
void main(void) {
gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0);
}
A complete version of my code can be found here http://cold.netburst.co.uk/webgl