Note that there are some explanatory texts on larger screens.

plurals
  1. POOpenGL, alpha blending with packed buffer and multiple textures
    primarykey
    data
    text
    <p>I'm drawing a fairly simple 2D scene containing only rectangles. I have one FloatBuffer into which I put X, Y, Z, R, G, B, A, U, and V data for each vertex. I draw using <code>glDrawArrays</code> and <code>GL_TRIANGLE_STRIP</code>, keeping the rectangles separate with degenerate vertices.</p> <p>To facilitate the use of multiple textures, I keep separate float arrays for each texture's draw calls. The texture is binded, the float array is put into the FloatBuffer, and I draw. Then the next texture is then binded and this continues until I have drawn all of my textures for this render.</p> <p>I use an Orthographic projection so I can use the Z coordinates and <code>GL_DEPTH_TEST</code> for setting depth independently of the draw order.</p> <p>To use alpha blending, every piece of advice on the internet seems to say:</p> <pre><code>GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); </code></pre> <p>This works fine per each texture's "draw", because I have the draw calls sorted in the buffer from back to front before drawing. I have no way to correctly draw texture2 under a partially transparent texture1 because of the depth test and texture1 being drawn before texture2. texture1 chops off the overlapping part of texture2 because the depth test says that texture1 is in front of texture2.</p> <p>The only ways I see around this are 1) only using 1 texture in the whole program, and 2) not using transparent textures. Neither of these are acceptable options.</p> <p>Basically, I need a way to have alpha blending without needing to sort back-to-front. Is this possible?</p>
    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.
    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