Basil Al-Dajane
Basil Al-Dajane

Reputation: 427

GLKit Polygon Translucency

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.

Upvotes: 1

Views: 490

Answers (2)

Basil Al-Dajane
Basil Al-Dajane

Reputation: 427

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.

Upvotes: 1

lzl
lzl

Reputation: 469

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

Upvotes: 1

Related Questions