1

I am completely new to opengl and need some help in drawing a texture with gradient applied over it.

Now I am drawing a texture with the following code:

glPushMatrix();
glBindTexture(GL_TEXTURE_2D,fcr.texture);
glTranslatef(trans, 0, 0);
glScalef(sc,sc,1.0);
glColor4f(1.0,1.0,1.0,0.4);
glDrawArrays(GL_TRIANGLE_STRIP,0,4);
glColor4f(1,1,1,1);

In the above code glColor4f(1.0,1.0,1.0,0.4); applies transparency to the drawn image. Now instead of a solid transparent color, I would like to apply a transparent gradient to the image so as to simulate the fading out effect.

Found this thread iPhone OpenGL - How to gradient fade out a texture?, which is the same as my question except I want the gradient to be applied to the main image itself instead of reflection. But I couldn't figure out the solution from answers given.

I guess I should use glTexEnvi, but then how to draw another image with the gradient?

Community
  • 1
  • 1
saiy2k
  • 1,852
  • 1
  • 23
  • 42
  • Do you mean fading out in time, or just like a left to right gradient where the left side is non-transparent and the right side is fully transparent (or top/bottom, topleft/bottomright, etc)? – Tim Apr 05 '12 at 16:54
  • dont need fading animations over time, but just static fading effect as u said.. – saiy2k Apr 06 '12 at 04:13

1 Answers1

1

Instead of calling glColor4f before drawing the quad, can you set a glColorPointer (or glVertexAttribPointer), such that each of the four vertices of your quad get a different alpha value?

i.e. RGBA values:

 (x,x,x,1)       (x,x,x,0)
     -----------------
     |               |
     |               |
     |               |
     |               |
     |               |
     |               |
     -----------------
  (x,x,x,1)      (x,x,x,0)

This would give you an alpha gradient from right to left.

Tim
  • 35,413
  • 11
  • 95
  • 121