Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL render to texture - black screen
    primarykey
    data
    text
    <p>I am rendering to a frame buffer, and then I want to use that as a texture.</p> <p>I can save the frame buffer to a file using <code>glReadPixels</code> so I am sure that I am rendering OK.</p> <p>I can bind to fixed texture and render that OK.</p> <p>But I cannot bind to the frame buffer to render that in place of the fixed texture.</p> <pre><code> //setup: private void setupRenderToTexture() { fb = new int[numberOfBuffers]; depthRb = new int[numberOfBuffers]; renderTex = new int[numberOfBuffers]; texBuffer = new IntBuffer[numberOfBuffers]; // generate GLES20.glGenFramebuffers(fb.length, fb, 0); GLES20.glGenRenderbuffers(depthRb.length, depthRb, 0); GLES20.glGenTextures(renderTex.length, renderTex, 0); GLErrorHandler.checkGlError("glGenFramebuffers"); for (int i = 0; i &lt; fb.length; i++) { GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[i]); // generate color texture GLState.Instance.bindTexture(0, renderTex[i]); // parameters GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, // GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, // GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); // create it // create an empty intbuffer first? int[] fileData = new int[width * height]; texBuffer[i] = IntBuffer.wrap(fileData); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, width, height, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, texBuffer[i]); GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, renderTex[i], 0); // create render buffer and bind 16-bit depth buffer GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRb[i]); GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, width, height); GLErrorHandler.checkGlError("glRenderbufferStorage or above"); } GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); } </code></pre> <p>Use the frame buffer:</p> <pre><code>GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[0]); </code></pre> <p>Save the frame buffer (for testing):</p> <pre><code>GLES20.glReadPixels(sourceX, sourceY, width, height, GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, ib); </code></pre> <p>Then to render to screen:</p> <pre><code>GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, 0); GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, fb[0]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture); //some simple texture works but: GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, renderTex[0]); //frame buffer texture does not work </code></pre> <p>All I get is a black screen if I bind to <code>renderTex[0]</code></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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