[英]OpenGL : Is There Any Way To Use glMaterialfv( ) to Create a Transparent/Translucent Object?
I have this cylinder object below: 我在下面有这个圆柱体对象:
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, cylinder_mat);
cylinder();
Where static GLfloat cylinder_mat[] = {0.f, .5f, 1.f, 1.f};
其中static GLfloat cylinder_mat[] = {0.f, .5f, 1.f, 1.f};
dictates the color of my cylinder. 决定我圆柱体的颜色。
Is there anyway to use glMaterialfv in a way to make the object transparent? 无论如何,有没有使用glMaterialfv来使对象透明的方式?
I guess this example will clarify a bit for you. 我想这个例子将为您澄清一点。
#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;
}
Note that this example is very, very simplicist. 请注意,此示例非常简单。 So, its main purpose is just to demostrate how to use BLEND functions. 因此,其主要目的只是演示如何使用BLEND函数。 I did not take care about DEPTH removal or camera position. 我不关心深度的去除或相机的位置。
I used the program posted here ( How to use alpha transparency in OpenGL? ) to construct this one. 我使用这里发布的程序( 如何在OpenGL中使用alpha透明性? )来构造这一程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.