Blending of 3D meshes on white background

Started by
-1 comments, last by archwndas 15 years, 9 months ago
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.ambientFront[3] = meshAlpha; vMaterialColors.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 &lt; bfacetsnumber; i++) { facet = facetSet_<span style="font-weight:bold;">; 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.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 &#111;nes. 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 &#111;n this forum for you to see exactly what the problem is. Any ideas? Thanks in advance, Symeon.

This topic is closed to new replies.

Advertisement