Right so i have a transparency issue that i hope someone could explain? i should see the texture through the red square.
I created a bounding box around my obj (yes that textured cube is an obj ) however i noticed a transparency issue, so i removed all sides of the box bar the top. the top is a solid red with an alpha of 0.2.
originally i rendered another transparent box behind the red one and i could see that fine, just not the textured obj, which leads me to believe it is a conbination of my shader and glblend thats the issue.
so here is my code for my frag shader, if it doesnt have a texture (coord -98) then just do colour, i dont currently have a world light set so it never goes into the first part for textures
if (pass_Texture[0] <= -98.0 && pass_Texture[1] <= -98.0)
{
out_Color = pass_Color;
} else {
if(WorldLight.isWorldSource)
{
out_Color = texture(myTexture, pass_Texture) * pass_Color * (AmbientColor + DiffuseColor);
} else {
out_Color = texture(myTexture, pass_Texture) * pass_Color;
}
}
my bounding box (in this case just the red square) as you can see ive tried a variety of options
//glDisable(GL_DEPTH_TEST);
//glEnable(GL_CULL_FACE);
glEnable(GL_BLEND);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
glUniformMatrix4fv(shader->modelMatrixLocation, 1, GL_FALSE, &transform[0][0]);
glBindVertexArray(Cube->VAOID); // Bind our Vertex Array Object
glDrawArrays(GL_TRIANGLES, 0, Cube->points.size()); // Draw our square
glBindVertexArray(0); // Unbind our Vertex Array Object
glDisable(GL_BLEND);
//glDisable(GL_CULL_FACE);
//glEnable(GL_DEPTH_TEST);
and finally my obj which again ive tried a variety of blend options and depthtest options, most of it is my own code but didnt want to cut incase it was something else entirely that i missed
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
//glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glUniformMatrix4fv(shader->modelMatrixLocation, 1, GL_FALSE, &ModelMatrix[0][0]);
glBindVertexArray(VAIO); // Bind our Vertex Array Object
std::map<std::string, Group>::const_iterator itr;
for (itr = Groups.begin(); itr != Groups.end(); itr++)
{
Group gp = itr->second;
cMtl* mtl = &Materials[gp.Mtl];
if (mtl->MainTexture.loaded && !mtl->MainTexture.GeneratedBuffer)
{
if (mtl->MainTexture.TextType == SARAGAN_PNG)
{
mtl->MainTexture.GenerateAlphaBuffer();
} else {
mtl->MainTexture.GenerateBuffer();
}
}
if (mtl->MainTexture.loaded && mtl->MainTexture.GeneratedBuffer)
{
if (CurrentTextureID != mtl->MainTexture.TextureID)
{
CurrentTextureID = mtl->MainTexture.TextureID;
}
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, mtl->MainTexture.TextureID);
glDrawArrays(GL_TRIANGLES, gp.index, gp.Endindex); // Draw our square
}
}
glBindVertexArray(0); // Unbind our Vertex Array Object
glDisable(GL_BLEND);
for the love of me i cant seem to get the right combination, which to me suggests i dont really understand whats really going on here
if anyone could shed some light onto the situation then i would be very greatful
Kind Regards
Rob