0

我在下面有这个圆柱体对象:

glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cylinder_mat);
cylinder();

哪里 static GLfloat cylinder_mat[] = {0.f, .5f, 1.f, 1.f}; 决定了我的圆柱体的颜色。

有没有办法使用 glMaterialfv 使对象透明?

4

1 回答 1

1

我想这个例子会为你澄清一点。

#include <GL/freeglut.h>

void init()
{
  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  glClearColor(1.0, 1.0, 1.0, 1.0);
}

void display(void)
{
  glClear(GL_COLOR_BUFFER_BIT);
  glLoadIdentity();

  glColor4f(0.5, 0.5, 0.5, 1.0);
  glutSolidCube(0.5);

  glTranslatef(-0.1, 0, 0);
  glEnable(GL_BLEND);
  glColor4f(1, 0, 0, 0.3);
  glutSolidCube(0.4);
  glDisable(GL_BLEND);

  glFlush();
}

int main(int argc, char *argv[])
{
  glutInit(&argc, argv);
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGBA);
  glutInitWindowSize(600,600);
  glutInitWindowPosition(200,50);
  glutCreateWindow("glut test");
  glutDisplayFunc(display);
  init();
  glutMainLoop();
  return 0;
}

请注意,这个例子非常非常简单。所以,它的主要目的只是为了演示如何使用 BLEND 函数。我不关心 DEPTH 移除或相机位置。

我使用此处发布的程序(如何在 OpenGL 中使用 alpha 透明度?)来构建这个程序。

于 2013-05-03T05:08:47.270 回答