c++ - OpenGL : Is There Any Way To Use glMaterialfv( ) to Create a Transparent/Translucent Object? -
i have 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};
dictates color of cylinder.
is there anyway use glmaterialfv in way make object transparent?
i guess example clarify bit 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 example very, simplicist. so, main purpose demostrate how use blend functions. did not take care depth removal or camera position.
i used program posted here (how use alpha transparency in opengl?) construct one.
Comments
Post a Comment