Home > other >  Webgl depth test problems
Webgl depth test problems

Time:09-20

Learning webgl found a problem
The code below

Var Geometry1=new Object ();
Geometry1. Are=new Float32Array ([
//Vertex coordinates and color (RGBA)
0.5, 0.4, 0.8, 1.0, 0.4, 0.4,//yellow last
0.5, 0.4, 0.8, 1.0, 1.0, 0.4,
0.0, 0.6, 0.8, 1.0, 1.0, 0.4,

0.0, 0.5, 0.2, 0.4, 0.4, 1.0, and the front//blue
0.6, 0.5, 0.2, 0.4, 0.4, 1.0,
0.6, 0.5, 0.2, 1.0, 0.4, 0.4,

0.0, 0.5, 0.4, 0.4, 1.0, 0.4,//middle green
0.5, 0.5, 0.4, 0.4, 1.0, 0.4,
0.5, 0.5, 0.4, 1.0, 0.4, 0.4,
]);
//vertex shader
Geometry1. VSHADER_SOURCE=
'attribute vec4 a_Position; + '
'attribute vec4 a_Color; + '
'varying vec4 v_Color; + '
//'uniform mat4 u_mat; + '
'void main () {+'
//'gl_Position=u_mat * a_Position; + '
'gl_Position=a_Position; + '
'v_Color=a_Color; + '
'} ';
//pixel shader
Geometry1. FSHADER_SOURCE=
'precision mediump float; + '
'varying vec4 v_Color; + '
'void main () {+'
'gl_FragColor=v_Color; + '
'} ';
//below is drawing code
Gl. ClearColor (0,0,0,1);
Gl. The enable (gl. DEPTH_TEST);
Gl. The clear (gl) COLOR_BUFFER_BIT | gl. DEPTH_BUFFER_BIT);


Gl. BindBuffer (gl ARRAY_BUFFER, enclosing vertexBuffer);
Gl. BufferData (gl ARRAY_BUFFER, enclosing are drawn, gl. STATIC_DRAW);

Gl. EnableVertexAttribArray (enclosing a_Position);
Gl. EnableVertexAttribArray (enclosing a_Color);

Var Fsize=this. Are. BYTES_PER_ELEMENT;
Gl. VertexAttribPointer (enclosing a_Position, 3, gl, FLOAT, false, Fsize * 6, 0).
Gl. VertexAttribPointer (enclosing a_Color, 3, gl, FLOAT, false, Fsize * 6, Fsize * 3);

Gl. DrawArrays (gl. TRIANGLES, 0, Geometry1, are drawn. The length/6);
Open depth after tests found yellow actually in front of counter is no understand why??
O great god answer it is better for relevant information
  • Related