i'm fairly new to OpenGL and came across this problem: I am trying to render multiple semi-transparent cubes which are inside of each other and some faces in the back of the cubes just get cut out. It also depends from where im looking inside the cube (see the gif).
https://i.imgur.com/bL4U8BS.gifv
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, transparentTexture);
for (int i = 0; i < CacheSizeInfo.size(); ++i)
{
int totalCacheSize = CacheSizeInfo[i][0]* CacheSizeInfo[i][1]* CacheSizeInfo[i][2];
std::vector<float> Cachecolor = { CacheColorInfo[i][0], CacheColorInfo[i][1], CacheColorInfo[i][2]};
int cacheOffset = (renderIndex / totalCacheSize) * totalCacheSize;
mat4 translationMatrix = glm::translate(mat4(1.0f), modelMatrices[cacheOffset]);
glUniformMatrix4fv(glGetUniformLocation(shaderID, "translation"), 1, GL_FALSE, &translationMatrix[0][0]);
glUniform3fv(glGetUniformLocation(shaderID, "color"), 1, &Cachecolor[0]);
glBindVertexArray(CacheVAOInfo[i]);
glDrawArrays(GL_TRIANGLES, 0, CacheVertexCountInfo[i]);
glBindVertexArray(0);
}
}
mat4 translationMatrix = glm::mat4(1.0f);
glUniformMatrix4fv(glGetUniformLocation(shaderID, "translation"), 1, GL_FALSE, &translationMatrix[0][0]);
glUniform3fv(glGetUniformLocation(shaderID, "color"), 1, &matColor[0]);
glBindVertexArray(VAO_Matrix);
glDrawArrays(GL_TRIANGLES,0, mainMatSize*3);
glBindVertexArray(0);
First I enable the Depth Test and set it to GL_LESS. Then I bind the transparent texture. After that, in the for loop, I render the green matrix and after that, outside of the loop, the white one.