Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy depth test does not work in offscreen rendering for color pick?
    primarykey
    data
    text
    <p>I'm using coloring and off-screen rendering to implement a selection tool for QUADS on OpenGL. But the depth test seems to not work in the off-screen rendering and in certain angles and rotations, the QUAD behind the front one is selected. Any thoughts on how I should set up my Buffers and/or attachments? Does this problem have anything to do with my normals??? Or is just depth test?? I personally think it's depth test, I just can't get the damn thing working!!!</p> <p>Here is My init function for buffers:</p> <pre><code>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!"); } } </code></pre> <p>When I uncomment the "Comment 1" and "Comment 2" parts, I get a render buffer problem. But I've heard that I should attach "a render buffer to the GL_DEPTH_ATTACHMENT in addition to the color attachment." (Source: <a href="https://stackoverflow.com/questions/5751081/how-to-use-depth-testing-when-rendering-to-an-offscreen-buffer-then-onto-texture">Look at this Q</a>. I wonder How can I do that.</p> <p>Also, here is my usage code:</p> <pre><code>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); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload