Give alpha to an object OpenGL ES -


i new on opengl , want achieve give texture alpha 1.0 0.0

i has been searching , found "how load alpha in images" cant find how apply alpha object

i has been tried with:

gl.glenable(gl10.gl_alpha_test); alpha += 0.002f; if(alpha > 1) alpha = 1f; gl.glalphafunc(gl10.gl_equal, alpha); 

but doesnt work, how can give alpha value(to make effect of fade) object/texture?

this class

public class palabra {  public float posx = 0f; public float posy = 0f;  public float scalex = 2f; public float scaley = 2f;  public float alpha= 0.5f;  public state estado;  private floatbuffer vertexbuffer, texbuffer; // buffer vertex-array  private float[] vertices = { // vertices face 0.0f, 0.0f, 0.2f, // 0. left-bottom-front 2.1f, 0.0f, 0.2f, // 1. right-bottom-front 0.0f, 0.35f, 0.2f, // 2. left-top-front 2.1f, 0.35f, 0.2f // 3. right-top-front };  float[] texcoords = { // texture coords above face 0.00f, 0.0f, 1.0f, // a. left-bottom 1.00f, 0.0f, 1.0f, // b. right-bottom 0.00f, 0.2f, 1.0f, // c. left-top 1.00f, 0.2f, 1.0f // d. right-top };  public enum state {     miss, normal,great,awesome,perfect; }  public palabra(int a) {     // setup vertex-array buffer. vertices in float. float has 4 bytes     bytebuffer vbb = bytebuffer.allocatedirect(vertices.length * 4);     vbb.order(byteorder.nativeorder()); // use native byte order     vertexbuffer = vbb.asfloatbuffer(); // convert byte float     vertexbuffer.put(vertices); // copy data buffer     vertexbuffer.position(0); // rewind      // setup texture-coords-array buffer, in float. float has 4 bytes     // (new)      bytebuffer tbb = bytebuffer.allocatedirect(texcoords.length * 4);      tbb.order(byteorder.nativeorder());      texbuffer = tbb.asfloatbuffer();      texbuffer.put(texcoords);      texbuffer.position(0);      posx = (float) 0.00f;            switch(a)      {          case 0:              posy = (float) 1f;              break;          case 1:              posy = (float) 1.5f;              break;          case 2:              posy = (float) 2f;              break;          case 3:              posy = (float) 2.5f;              break;          case 4:              posy = (float) 3f;              break;      } }  public void draw(gl10 gl) {     gl.glmatrixmode(gl10.gl_modelview);     gl.glloadidentity();     gl.glpushmatrix();     gl.gltranslatef(posx, posy, 0f);     gl.glscalef(scalex, scaley, 0f);     scalex -= 0.02f;     scaley -= 0.02f;     posx += 0.02f;     if(scalex < 1)      {         scalex = 1f;         posx -= 0.02f;     }     if(scaley < 1) scaley = 1f;           gl.glmatrixmode(gl10.gl_texture);     gl.glloadidentity();      switch(this.estado)     {         case awesome:             gl.gltranslatef(0.0f, 0.2f, 0f);             break;         case great:             gl.gltranslatef(0.0f, 0.4f, 0f);             break;         case normal:             gl.gltranslatef(0.0f, 0.6f, 0f);             break;         case miss:             gl.gltranslatef(0.0f, 0.8f, 0f);             break;                   case perfect:              break;      }        gl.glfrontface(gl10.gl_ccw); // front face in counter-clockwise                                     // orientation     gl.glenable(gl10.gl_cull_face); // enable cull face     gl.glcullface(gl10.gl_back); // cull face (don't display)      gl.glenableclientstate(gl10.gl_vertex_array);     gl.glvertexpointer(3, gl10.gl_float, 0, vertexbuffer);     gl.glenableclientstate(gl10.gl_texture_coord_array); // enable                                                             // texture-coords-array                                                             // (new)     gl.gltexcoordpointer(3, gl10.gl_float, 0, texbuffer); // define                                                             // texture-coords                             // buffer (new)      gl.glenable(gl10.gl_blend);     gl.glblendfunc(gl10.gl_src_alpha, gl10.gl_one_minus_src_alpha);       // front     gl.glbindtexture(gl10.gl_texture_2d, textureloader.palabrasids[0]);      gl.gldrawarrays(gl10.gl_triangle_strip, 0, 4);      gl.gldisableclientstate(gl10.gl_texture_coord_array); // disable                                                             // texture-coords-array                                                             // (new)     gl.gldisableclientstate(gl10.gl_vertex_array);     gl.gldisable(gl10.gl_cull_face);     gl.gldisable(gl10.gl_blend);     gl.glpopmatrix(); } 

}

i made it!

that code

gl.glenable(gl10.gl_blend);     gl.glblendfunc(gl10.gl_src_alpha, gl10.gl_one_minus_src_alpha);     gl.glcolor4f(1f, 1f, 1f,alpha);     alpha -= 0.002f;     if(alpha < 0) alpha = 0f; 

Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

qt - How to embed QML toolbar and menubar into QMainWindow -