OpenGL-ES 可变纹理 Alpha(2D)?

发布于 2024-08-20 02:26:54 字数 905 浏览 7 评论 0原文

我有一个具有透明度的纹理(带有照明信息的白色三角形),但无法使其成为 alpha 变量

替代文本 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 的东西。

I have a texture with transparency (the white triangle with that lighting information), and just can't make it's alpha variable.

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

The drawing code, with the missing piece:

  //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); 

Could somebody please help me out with the appropriate lines of code?
Some glBlendFunc, or maybe glTextEnvi stuff I suppose.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不知在何时 2024-08-27 02:26:54

好吧,我明白了,即使我不明白我到底做了什么。

    //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);

但第二张地图不知何故“较弱”。

Ok, I got it even if I don't understand what I did exactly.

    //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);

I tried another way before...

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

...but the second map was somehow "weaker".

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文