我正在使用着色和离屏渲染在 OpenGL 上实现 QUADS 的选择工具。但是深度测试似乎在离屏渲染和某些角度和旋转下不起作用,选择了前面那个后面的QUAD。关于如何设置缓冲区和/或附件的任何想法?这个问题和我的法线有什么关系???还是只是深度测试??我个人认为这是深度测试,我就是无法让该死的东西工作!!!
这是我的缓冲区初始化函数:
public void init(final GL2 gl) {
// setup
gl.glGenFramebuffers(frameBufferIds.capacity(), frameBufferIds);
gl.glGenRenderbuffers(renderBufferIds.capacity(), renderBufferIds);
gl.glBindRenderbuffer(GL2.GL_RENDERBUFFER, renderBufferIds.get(0));
//
ViewPort viewPort = ViewPort.getCurrent(gl);
gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_RGBA, viewPort.getWidth(), viewPort.getHeight());
/**
* Comment 1
*/
// gl.glRenderbufferStorage(GL2.GL_RENDERBUFFER, GL2.GL_DEPTH_COMPONENT, viewPort.getWidth(), viewPort.getHeight());
// attach the render buffer to color attachment point
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferIds.get(0));
gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_COLOR_ATTACHMENT0, GL2.GL_RENDERBUFFER, renderBufferIds.get(0));
/**
* Comment 2
*/
// gl.glFramebufferRenderbuffer(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT, GL2.GL_RENDERBUFFER, renderBufferIds.get(0));
//
if (gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER) != GL2.GL_FRAMEBUFFER_COMPLETE) {
System.out.println("Render Buffer problem!");
}
}
当我取消注释“注释 1”和“注释 2”部分时,出现渲染缓冲区问题。但我听说我应该将“除了颜色附件之外的渲染缓冲区附加到 GL_DEPTH_ATTACHMENT”。(来源:看看这个 Q。我想知道我该怎么做。
另外,这是我的使用代码:
gl.glDisable(GL2.GL_DITHER);
// 1. render in offscreen
init(gl);
gl.glEnable(GL2.GL_DEPTH_TEST);
offscreenRender(gl, selectionType);
// 2. read pixel
gl.glReadBuffer(GL2.GL_DEPTH_ATTACHMENT);
gl.glReadBuffer(GL2.GL_COLOR_ATTACHMENT0);
gl.glReadPixels((int) (pos.x - pickWidth / 2), (int) (viewPort.getHeight() - pos.y - pickWidth / 2), pickWidth, pickWidth, GL2.GL_RGBA, GL2.GL_FLOAT, pointSelectionPixels);