# 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.

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627664
• Total Posts
2978522
• ### Similar Content

• Both functions are available since 3.0, and I'm currently using glMapBuffer(), which works fine.
But, I was wondering if anyone has experienced advantage in using glMapBufferRange(), which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
• By xhcao
Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness.
• By cebugdev
hi guys,
are there any books, link online or any other resources that discusses on how to build special effects such as magic, lightning, etc. in OpenGL? i mean, yeah most of them are using particles but im looking for resources specifically on how to manipulate the particles to look like an effect that can be use for games,. i did fire particle before, and I want to learn how to do the other 'magic' as well.
Like are there one book or link(cant find in google) that atleast featured how to make different particle effects in OpenGL (or DirectX)? If there is no one stop shop for it, maybe ill just look for some tips on how to make a particle engine that is flexible enough to enable me to design different effects/magic
let me know if you guys have recommendations.
• By dud3
How do we rotate the camera around x axis 360 degrees, without having the strange effect as in my video below?
Mine behaves exactly the same way spherical coordinates would, I'm using euler angles.
Tried googling, but couldn't find a proper answer, guessing I don't know what exactly to google for, googled 'rotate 360 around x axis', got no proper answers.

References:
Code: https://pastebin.com/Hcshj3FQ
The video shows the difference between blender and my rotation:

• By Defend
I've had a Google around for this but haven't yet found some solid advice. There is a lot of "it depends", but I'm not sure on what.
My question is what's a good rule of thumb to follow when it comes to creating/using VBOs & VAOs? As in, when should I use multiple or when should I not? My understanding so far is that if I need a new VBO, then I need a new VAO. So when it comes to rendering multiple objects I can either:
* make lots of VAO/VBO pairs and flip through them to render different objects, or
* make one big VBO and jump around its memory to render different objects.
I also understand that if I need to render objects with different vertex attributes, then a new VAO is necessary in this case.
If that "it depends" really is quite variable, what's best for a beginner with OpenGL, assuming that better approaches can be learnt later with better understanding?

• 10
• 10
• 12
• 22
• 13