OpenGL在启用深度测试时不会丢弃我的碎片
OpenGL is not discarding my fragments when depth testing is enabled
我正在用wxWidgets 3.1.3编写OpenGL渲染器。我可以看到隐藏在我的模型后面的碎片,但即使它们应该被遮挡,它们也面向我。将我的碎片着色器设置为显示深度表明深度设置正确,并且我的znear=0.1和zfar=100。
这是我的OpenGL初始化代码:
this->m_glcontext = new wxGLContext(this);
this->SetCurrent(*this->m_glcontext);
std::remove(ENGINECANVAS_LOG_PATH);
glewExperimental = GL_TRUE;
glewInit();
glLoadIdentity();
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);;
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
glDebugMessageCallback(MessageCallback, 0);
this->Bind(wxEVT_PAINT, &EngineCanvas::Paint, this);
this->Render();
这是我的渲染循环:
glViewport(0, 0, (GLint)this->GetSize().x, (GLint)this->GetSize().y);
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
this->m_active_camera->GenPerspMat((float)canvas->GetSize().x, (float)canvas->GetSize().y);
this->m_active_camera->GenViewMat();
for (size_t i = 0; i < this->models.size(); i++)
{
this->models.at(i)->GenPosMat();
this->models.at(i)->shader_program->Select(); //selects shader program
this->m_active_camera->SetUniforms(this->models.at(i)->shader_program);
this->models.at(i)->SetUniforms();
glBindVertexArray(this->models.at(i)->vao);
for (size_t j = 0; j < this->models.at(i)->vertex_buffers_count.size(); j++)
{
glBindBuffer(GL_ARRAY_BUFFER, this->models.at(i)->vertex_buffers.at(j));
glDrawArrays(this->models.at(i)->triangle_mode, 0, this->models.at(i)->vertex_buffers_count.at(j));
}
}
glFlush();
this->SwapBuffers();
片段着色器:
#version 400 core
layout(location = 0) out vec4 frag_out;
in vec3 vpos;
void main()
{
frag_out = vec4(vec3(gl_FragCoord.z).xyz, 1.0f);
}
我的碎片在NVIDIA显卡上被丢弃得很好,但在两台不同的笔记本电脑和我的集成图形上测试会产生这个错误。我的几何体本身渲染正确。回调不会返回任何错误(回调正在工作(。所有卡至少支持OpenGL 4.0(在我的着色器和GLCanvas参数中指定(。
感谢Rabbid76,
我需要在wxGLCanvas的参数中指定深度缓冲区。我需要使用wxGLAttributes类并传递它,而不是在提供int数组的wiki示例中。
wxGLAttributes args;
args.PlatformDefaults().Depth(24).Stencil(8).RGBA().DoubleBuffer().EndList();
现在我知道该去哪里看了,这在wxWidgets提供的金字塔样本中有记录。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- C++我的数学有什么问题,为什么我的代码不能正确循环
- 我的字符计数代码计算错误.为什么
- 为什么我的C#代码在调用回C++COM直到Task时会暂停.等待/线程.加入
- cmake在我的项目中所需的所有静态库都不成功
- 为什么我的代码在输出中增加了93天
- 我的简单if-else语句是如何无法访问的代码
- 为什么我的for循环不能正确获取argv
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- 0-1背包代码中的错误.我的代码中有什么错误
- 当我的阵列太大时出现分段错误
- 如何确认我的constexpr表达式实际上已经在编译时执行
- 为什么二进制搜索在我的测试中不起作用
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 当我在main中声明了我的2d数组时,为什么我的程序会退出
- OpenGL在启用深度测试时不会丢弃我的碎片
- 为什么我的 std::ref 无法按预期工作?
- 使用 ' ios::sync_with_stdio(0)' 测试运行时的差异时,为什么我的输出是碎片化的?
- 我应该使用什么c++ STL类来减少由大量小分配引起的碎片