Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging level of opacity in OpenGL ES 2.0
    primarykey
    data
    text
    <p><strong>EDIT 1</strong>: Included shaders</p> <p><strong>EDIT 2</strong>: Included screen-shots</p> <p><strong>EDIT 3</strong>: Included screen-shot of original texture</p> <p><strong>EDIT 4</strong>:</p> <p><strong>EDIT 5</strong>: I think the problem is because my bitmaps have partially transparent pixels in them to start with, so I will ask a new question as the answer given here is correct for this question.</p> <p>On closer inspection, the problem doesn't quite appear to be resolved, colours aren't looking correct.</p> <pre><code>String strFShader = "precision mediump float;" + "uniform float Opacity;" + "varying vec2 v_texCoords;" + "uniform sampler2D u_baseMap;" + "void main()" + "{" + "gl_FragColor = texture2D(u_baseMap, v_texCoords);" + "gl_FragColor.a *= Opacity;"+ "}"; </code></pre> <p>And then in my rendering method:</p> <pre><code> //Enable and set mode GLES20.glEnable(GLES20.GL_BLEND); GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA); //Draw GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4); //Disable GLES20.glDisable(GLES20.GL_BLEND); </code></pre> <p>So, at max transparency (0.0), it's all good, i.e. nothing gets drawn. However at any other level it's not quite right, For example, at zero transparency (opacity set to 1.0), this is what I get:</p> <p>![enter image description here][1]</p> <p>But it should actually look like this:</p> <p>![enter image description here][2]</p> <p>Colours looks a little too dark and, (on the original image), the ever so slightly dark edge is really pronounced.</p> <p>I'm assuming it's something to do with the blending mode? Basically I'm simply after the effect one might get in photoshop when changing the opacity of one layer over another. Any other suggestions would be very helpful.</p> <p>I also tried the solution found here:</p> <p><a href="https://gamedev.stackexchange.com/questions/7260/opengl-es-basic-fragment-shader-help-with-transparency">https://gamedev.stackexchange.com/questions/7260/opengl-es-basic-fragment-shader-help-with-transparency</a></p> <p>But I get the same results?</p> <p>Thanks :-)</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