Sign in to follow this  
archwndas

OpenGL Blending of 3D meshes on white background

Recommended Posts

Hi guys, I have written a 3D mesh viewer. The way it works is that it reads the coordinates of the points of a set of triangles and then it renders them using OpenGL-classics. Now the problem is when I am trying to make the object transparent so I can see inside. When the background is black everything is fine. When the object's alpha value goes to zero the object disappears. However, when the background is white the object disappears immediately before I move the slider which changes the alpha value. The code I am using is the following: if (meshMode == TRANSPARENT) { glEnable(GL_BLEND); glDepthMask(GL_FALSE); glBlendFunc(GL_SRC_ALPHA, GL_ONE); for (color = 0; color < colorsnumber; color++) { vMaterialColors[color].ambientFront[3] = meshAlpha; vMaterialColors[color].diffuseFront[3] = meshAlpha; } } // if we do not desire to hide the boundary mesh (meshMode == HIDE) if (meshMode != HIDE) { glBegin(GL_TRIANGLES); for (i = 0; i < bfacetsnumber; i++) { facet = facetSet_[i]; marker = bfacetmarkerlist[facet]; e1 = bfacetlist[3*facet + 0]; e2 = bfacetlist[3*facet + 1]; e3 = bfacetlist[3*facet + 2]; v1 = pointlist + 3*e1; v2 = pointlist + 3*e2; v3 = pointlist + 3*e3; // we need minimum marker in case of negative markers color = vColorIPalette[marker-minimummarker]; vMaterialColors[color].switchOn(); // calculate normal of the triangle with vertices v1,v2,v3 normal_at(normalspointout, v1, v2, v3, norm); glNormal3dv(norm); if (normalspointout) { glVertex3dv(v1); glVertex3dv(v2); glVertex3dv(v3); } else { glVertex3dv(v2); glVertex3dv(v1); glVertex3dv(v3); } } glEnd(); } Now I tried to change the first lines related to the blending to: glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); This works nicely with white background and black background. However some of the mesh triangles appear with darker color than the other ones. As a result you do not see a transparent cube as you see in the first case, but a transparent cube of which some parts are rendered darker and give the feel that somebody has painted those parts of the cube with a darker color or something like the cube is made of different materials here or there. I do not know how to attach pictures on this forum for you to see exactly what the problem is. Any ideas? Thanks in advance, Symeon.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this