Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Blending of 3D meshes on white background

This topic is 3630 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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_; 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!