2

I'm new with OpenGLES and I was trying to draw a rectangle with alpha but alpha not being effected on screen. Please help me to figure out where I'm out of the line.

GLES10.glEnableClientState(GL10.GL_VERTEX_ARRAY);
GLES10.glClear(GL10.GL_COLOR_BUFFER_BIT);
GLES10.glColor4f(0.5f, 0.5f, 0.5f, 0.1f);  <-- NOT Working , please help 0.1 alpha not taken   
GLES10.glPushMatrix();GLES10.glEnableClientState(GL10.GL_VERTEX_ARRAY);
GLES10.glVertexPointer(
        3,
        GL10.GL_FLOAT,
        0,
        RendererImpl.makeFloatBuffer(new float[] { -160.0f, -100.0f,
                0.0f, 160.0f, -100.0f, 0.0f, 160.0f, 100.0f, 0.0f,
                    -160.0f, 100.0f, 0.0f }));
GLES10.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, 4);
GLES10.glDisableClientState(GL10.GL_VERTEX_ARRAY);
GLES10.glPopMatrix();
GLES10.glFlush();
Tim
  • 35,413
  • 11
  • 95
  • 121
  • "alpha not being effected on screen" . Please explain what you think this means? What are you expecting? Alpha doesn't mean anything unless you're doing some kind of blending or alpha testing. – Tim Jun 24 '12 at 04:47
  • in general one uses the alpha , that supposed be transparent . color supposed to lose the opacity . .I supposed to see background as well. which I can't see here . and I don't have idea about blending, I saw that but looks like would be used with texture . and alpha testing , I used that , making the color complete transparent or untouched . I'm too less knowledgeable to explain more that this . if you can help me to get a tutorial on alpha testing , which I did not find (searched but) , I will try to figure it out if that is the issue – Kamlesh Gupta Jun 24 '12 at 05:11

1 Answers1

5

If you want your objects that you draw to be transparent, then you first must enable blending.

Draw your background first, then set these options:

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Then try to draw your transparent object as you have done above.

Tim
  • 35,413
  • 11
  • 95
  • 121
  • I don't want to draw a Texture . I want to draw a colored Rectangle with alpha means opacity . – Kamlesh Gupta Jun 24 '12 at 05:17
  • Sorry, it should work exactly the same for a flat color or texture. I said texture when I really meant 'primitive'. Try the code, it should work. @KamleshGupta – Tim Jun 24 '12 at 05:21
  • It works and thank u a lot ...Any Idea about good open gl es tutorial please – Kamlesh Gupta Jun 24 '12 at 05:27