SFML community forums

Help => Graphics => Topic started by: JunkerKun on August 31, 2015, 10:14:21 pm

Title: OpenGL (3D) with transparency?
Post by: JunkerKun on August 31, 2015, 10:14:21 pm
Hello.
Now, this isn't exactly SFML related question but I bind textures to meshes by using sf::Texture->bind(), so...

The problem is: there is no transparency on PNG textures. Everything that is transparent draws as black color.
How do I fix it?
Title: Re: OpenGL (3D) with transparency?
Post by: Nexus on August 31, 2015, 10:25:34 pm
Do you use the alpha blend mode? Is blending enabled?

How do you draw?
Title: Re: OpenGL (3D) with transparency?
Post by: JunkerKun on August 31, 2015, 10:47:38 pm
Yes, I use both. (glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);).
The drawing is performed by passing vertex, texture and index arrays:

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMultMatrixf(camera->GetTransformationMatrix());

float position[4] = {-1,1,-1,0};
glLightfv(GL_LIGHT0, GL_POSITION, position);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glVertexPointer(3, GL_FLOAT, 0, &vertices.at(0));
glNormalPointer(GL_FLOAT, 0, &normals.at(0));
glTexCoordPointer(2, GL_FLOAT, 0, &tcoords.at(0));
glDrawElements(GL_TRIANGLES, indices.size(), GL_UNSIGNED_SHORT, &indices.at(0));

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);