启用深度测试后没反应呢?v3.16

m_Program = new GLProgram;
m_Program->initWithFilenames("shader/gldemo.vsh", "shader/gldemo.fsh");
m_Program->link();
//set uniform locations
m_Program->updateUniforms();
        
//创建和绑定vao
glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
    
    //创建和绑定vbo
    glGenBuffers(1, &vertexVBO);
    glBindBuffer(GL_ARRAY_BUFFER, vertexVBO);
    
    auto size = Director::getInstance()->getVisibleSize();
    float vertercies[] = {
                        0,0,0.5,   //第一个点的坐标
                        -1, 1,0.5,   //第二个点的坐标
                        -1, -1,0.5,//第三个点的坐标
                        -0.3,0,0.8,   //第一个点的坐标
                        1, 1,0.8,   //第二个点的坐标
                        1, -1,0.8,//第三个点的坐标
        
                        };
    
    float color[] = { 1, 0,0, 1,  1,0,0, 1, 1, 0, 0, 1,
                    0, 1,0, 1,  0,1,0, 1, 0, 1, 0, 1};
    
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertercies), vertercies, GL_STATIC_DRAW);
    //获取vertex attribute "a_position"的入口点
    GLuint positionLocation = glGetAttribLocation(m_Program->getProgram(), "a_position");
    //打开入a_position入口点
    glEnableVertexAttribArray(positionLocation);
    //传递顶点数据给a_position,注意最后一个参数是数组的偏移了。
    glVertexAttribPointer(positionLocation, 3, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
    
    //set for color
    glGenBuffers(1, &colorVBO);
    glBindBuffer(GL_ARRAY_BUFFER, colorVBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(color), color, GL_STATIC_DRAW);
    
    GLuint colorLocation = glGetAttribLocation(m_Program->getProgram(), "a_color");
    glEnableVertexAttribArray(colorLocation);
    glVertexAttribPointer(colorLocation, 4, GL_FLOAT, GL_FALSE, 0, (GLvoid*)0);
    
    //for safty
    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);

可以正常显示出图像

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glClearDepth(1.0f);
    

    
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LESS);

启动深度测试后,红三角为什么还在下面呢?

@zhangxm @drelaptop 你知道吗?

Please use english in future, it is an english forum.

Since v3.x, engine uses commands to render things. The commands are executed in Renderer::render(). Now you uses gl commands directly, but it can not word correctly with renderer.

The gl commands you wrote are executed before render works, but the real draw commands are done in renderer. So when draw commands are executed, the state set by

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);

is changed.