1
votes

I'm trying to draw translucent polygons using GLKit, but with no luck. So I was wondering if it's even possible to have translucent polygons in GLKit in the first place, since I know it's not supported in the standard implementation of OpenGL; but can be mimicked using custom shaders. But since GLKit compiles it's own shader, I need to know if I should continue to use GLKit or use my own custom shader. My code is below:

// setup states
glEnable(GL_BLEND);
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

self.effect.texture2d0.enabled   = GL_FALSE;
self.effect.colorMaterialEnabled = GL_TRUE;
self.effect.transform.modelviewMatrix = self.modelMatrix;

glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribColor);

[self.effect prepareToDraw];

// draw triangles
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &_vertices[0].pos);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE, sizeof(LineVertex), &_vertices[0].color);

glDrawArrays(GL_TRIANGLES, 0, _vertexCount);

Thanks in advance.

2
Just to be clear, do you definitely mean translucency, or transparency? - Tim
translucency - I know how to make a polygon either opaque or transparent; but I can't figure out how to get it to have 0.5 alpha properly. The problem really comes from having two 0.5 alpha polygons overlapping each other that does not produce a 1.0 alpha intersection. - Basil Al-Dajane
Transparent doesn't imply invisible, things can be partially transparent. Translucency implies a blurring or diffusion of the light behind the translucent object. Translucency is probably a difficult technique to achieve in OpenGL, while transparency (fully or partial) is supported quite well. The problem you describe sounds like a transparency problem. - Tim
thanks Tim for setting me in the right direction; will update this post after some research - Basil Al-Dajane

2 Answers

1
votes

Your question is confusing, but it sounds like you're having transparent objects drawing over each other?, if that's the case, use

glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);

in stead of what you got there.

and check that things like your depth testing or stencil testing (unlikely but possible) isn't preventing things from being drawn...

1
votes

The problem turned out that I had glEnable(GL_DEPTH_TEST) somewhere earlier, which stopped two polygons at alpha 0.5 creating an intersection with alpha 1.0.