user2110239
user2110239

Reputation: 134

Draw invisible triangle openGL ES 2.0 without using shader

I want to draw Invisible triangle in OpenGL ES 3.0. I thought making the Alpha channel Zero will do it. Here is how I am passing my triangle vertices:

In my constructor I am using intialising my Triangle vertices:

final float[] triangle2VerticesData = {
            // X, Y, Z, 
            // R, G, B, A
            -0.5f, -0.25f, 0.0f, 
            1.0f, 1.0f, 0.0f, 0.0f,      // Alpha is zero

            0.5f, -0.25f, 0.0f, 
            0.0f, 1.0f, 1.0f, 0.0f,      // Alpha is zero

            0.0f, 0.559016994f, 0.0f, 
            1.0f, 0.0f, 1.0f, 0.0f};     // Alpha is zero

Extra Information:

In onSurfaceCreated:

GLES20.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
// ... Creating and attaching shaders, creating veiw matrix using Lookat

In onDrawFrame:

GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);
// ... performaing simple rotation and passing MVP to shaders

In Shaders:

final String vertexShader = "uniform mat4 u_MVPMatrix; \n"

      + "attribute vec4 a_Position;     \n"     
      + "attribute vec4 a_Color;        \n"                   

      + "varying vec4 v_Color;          \n"     

      + "void main()                    \n"     
      + "{                              \n"
      + "   v_Color = a_Color;          \n"      

      + "   gl_Position = u_MVPMatrix   \n"     
      + "               * a_Position;   \n"                                                                          
      + "}                              \n";        
    final String fragmentShader =
        "precision mediump float;       \n"     

      + "varying vec4 v_Color;          \n"               
      + "void main()                    \n"     
      + "{                              \n"
      + "   gl_FragColor = v_Color;     \n"               
      + "}    

I am able to change color of the triangle with playing R G B values. BUT when A(Alpha) is set to 1.0f or 0.0f Does not produce any change in transperancy/invisiblity? Can anyone tell me where I am goin wrong?

Upvotes: 0

Views: 600

Answers (1)

user8709
user8709

Reputation: 1352

If you want the triangle to be completely invisible, simply don't render it. This is the best approach for performance, and with a little extra logic, should be easy to accomplish.

If you want some transparency, i.e. not completely invisible, then be sure to enable blending. (Plenty of information online about how to do blending. Too much to explain in a post.)

GLES20.glEnable(GLES20.GL_BLEND);

after rendering your transparent objects,

GLES20.glDisable(GLES20.GL_BLEND);

Upvotes: 1

Related Questions