2010-02-02 87 views
2

我有一个具有透明度的纹理(白色三角形和那个灯光信息),只是不能使它的变量变为OpenGL-ES变量纹理alpha(2D)?

alt text http://gotoandplay.freeblog.hu/files/alpha_help.png

绘图代码,与遗漏的部分:

//Place polygon vertices to the bottom left within the view. 
    glLoadIdentity(); 
    glTranslatef(centerX, centerY, 0); 

    //Draw "diffuse" layer. 
    glBindTexture(GL_TEXTURE_2D, spriteTexture[0]); //Bind. 
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

    //Offset during development only. 
    glLoadIdentity(); 
    glTranslatef(centerX-10, centerY+10, 0); 

    //Draw "specular" layer. 
    glActiveTexture(GL_TEXTURE0); 
    glBindTexture(GL_TEXTURE_2D, spriteTexture[1]); //Bind. 

    //Some smart alpha scaling code needs here... 

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

可能有人请帮助我适当的代码行? 一些glBlendFunc,或者glTextEnvi我想的东西。

+0

你能写出你想如何将两个纹理的值混合在一起的数学吗? (背景+三角形1 +三角形2)。或者,你是否想将两个纹理应用到同一个三角形? – Frogblast 2010-02-02 05:14:43

+0

三角形正被渲染到连接到纹理的单独帧缓冲区中。所以在这个单独的framebuffer背景是(0,0,0,0),trianlge 1是简单的alpha混合,就像第二个三角形(没有任何添加,调制等等)。你可以在我以前的问题中看到这些图像(如此生成的纹理):http://stackoverflow.com/questions/2173363/please-help-with-an-opengl-es-iphone-multi-texturing-2d-code – Geri 2010-02-02 10:29:24

回答

0

好吧,我知道了,即使我不明白我做了什么。

//Place polygon vertices to the bottom left within the view. 
    glLoadIdentity(); 
    glTranslatef(centerX, centerY, 0); 

//--1 

     //Draw "diffuse" layer. 
     glActiveTexture(GL_TEXTURE0); 
     glBindTexture(GL_TEXTURE_2D, spriteTexture[0]); //Bind. 

      //Blending. 
      glBlendFunc(GL_ONE, GL_ONE); 

     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

//--2 

     //Draw "specular" layer. 
     glBindTexture(GL_TEXTURE_2D, spriteTexture[1]); //Bind. 

      //Blending. 
      glColor4f(opacity, opacity, opacity, opacity); 
      glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA); 

     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

我尝试过另一种方式......

glColor4f(1.0f, 1.0f, 1.0f, opacity); 
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 

...但第二张图是有点 “弱”。