webgl深度测试问题

weixin_41443034 2017-12-23 10:10:00
学习webgl发现一个问题
代码如下

var Geometry1 = new Object();
Geometry1.vertices = new Float32Array([
// Vertex coordinates and color(RGBA)
0.5, 0.4, -0.8, 1.0, 0.4, 0.4, // 黄色最后
-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, // 最前面蓝色
-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, //绿色中间
-0.5, -0.5, -0.4, 0.4, 1.0, 0.4,
0.5, -0.5, -0.4, 1.0, 0.4, 0.4,
]);
//顶点着色
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;'+
'}';
//像素着色
Geometry1.FSHADER_SOURCE =
'precision mediump float;'+
'varying vec4 v_Color;'+
'void main(){'+
'gl_FragColor = v_Color; '+
'}';
//下面是绘图代码
gl.clearColor(0,0,0,1);
gl.enable(gl.DEPTH_TEST);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);


gl.bindBuffer(gl.ARRAY_BUFFER,this.vertexBuffer);
gl.bufferData(gl.ARRAY_BUFFER,this.vertices,gl.STATIC_DRAW);

gl.enableVertexAttribArray(this.a_Position);
gl.enableVertexAttribArray(this.a_Color);

var Fsize = this.vertices.BYTES_PER_ELEMENT;
gl.vertexAttribPointer(this.a_Position,3,gl.FLOAT,false,Fsize*6,0);
gl.vertexAttribPointer(this.a_Color,3,gl.FLOAT,false,Fsize*6,Fsize*3);

gl.drawArrays(gl.TRIANGLES,0,Geometry1.vertices.length /6);
开启深度测试后 发现黄色居然在前面 就没有搞懂了 为什么是反的??
求大神解答 最好有相关资料
...全文
396 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

721

社区成员

发帖
与我相关
我的任务
社区描述
Cocos2d-x相关内容讨论专区
社区管理员
  • Cocos2d-x
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧