[JOGL] Displaying a skybox

Hello everyone,
This is my very first time in hear so sorry in advance if I forgot anything ^^

I’m currently working on a 3D game in java and I’ve chosen to work with the library JOGL. The reason of this new topic is that I’m currently stuck on the problem of displaying a skybox :

  • I managed to display a cube which is not textured,
  • The cube is displaying in the background, so the depth test is correctly disabled for rendering the skybox,
  • But the cube is always black :frowning:

My fragment shader looks like this :

#version 400

in vec3 textureCoordinates;

out vec4 outColor;

uniform samplerCube textureCubemap;
//uniform sampler2D textureCubemap; -> used when I wanna test my shader with a classic 2D texture

void main (void) {
    // The following line demonstrates that the coordinates are correctly used for sampling the texture
    //outColor = vec4(textureCoordinates, 1);

    // The following line permits to test the shader with a classic 2D texture
    //outColor = texture(textureCubemap, textureCoordinates.xy);

    // The following line is intended to work with a texture cubemap (but always displays a black cube)
    outColor = vec4(texture(textureCubemap, textureCoordinates).xyz, 1);
}

In Java, here’s my code for rendering the cubemap with a 3D texture (so this is the code that is not working) :

private void bufferData(GL3 gl) {
    // Setting the texture handler
    if (!isBinded) {
        int[] ids = new int[1];
        gl.glGenTextures(1, ids, 0);
        textureCubeMapHandler = ids[0];
        isBinded = true;
    }

    // Activating and buferring the texture
    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(GL.GL_TEXTURE_CUBE_MAP, textureCubeMapHandler);
    gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MAG_FILTER, GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_MIN_FILTER, GL.GL_NEAREST);
    gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_CUBE_MAP, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);

    // Buffering the X faces textures
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, positiveX.getInternalFormat(), positiveX.getWidth(),
            positiveX.getHeight(), 0, positiveX.getPixelFormat(), positiveX.getPixelType(),
            positiveX.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, negativeX.getInternalFormat(), negativeX.getWidth(),
            negativeX.getHeight(), 0, negativeX.getPixelFormat(), negativeX.getPixelType(),
            negativeX.getBuffer());

    // Buffering the Y faces textures
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, positiveY.getInternalFormat(), positiveY.getWidth(),
            positiveY.getHeight(), 0, positiveY.getPixelFormat(), positiveY.getPixelType(),
            positiveY.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, negativeY.getInternalFormat(), negativeY.getWidth(),
            negativeY.getHeight(), 0, negativeY.getPixelFormat(), negativeY.getPixelType(),
            negativeY.getBuffer());

    // Buffering the Z faces textures
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, positiveZ.getInternalFormat(), positiveZ.getWidth(),
            positiveZ.getHeight(), 0, positiveZ.getPixelFormat(), positiveZ.getPixelType(),
            positiveZ.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, negativeZ.getInternalFormat(), negativeZ.getWidth(),
            negativeZ.getHeight(), 0, negativeZ.getPixelFormat(), negativeZ.getPixelType(),
            negativeZ.getBuffer());

    gl.glUniform1i(FxManager.textureCubemapHandler, 0);
}

And for the comparison, here’s the code I use to display the cubemap with a 2D texture (which is the code that is working) :

private void buffer2dData(GL3 gl) {
    // Setting the texture handler
    if (!isBinded) {
        int[] ids = new int[1];
        gl.glGenTextures(1, ids, 0);
        textureCubeMapHandler = ids[0];
        isBinded = true;
    }

    // Activating and buffering the texture
    gl.glActiveTexture(GL.GL_TEXTURE0);
    gl.glBindTexture(GL.GL_TEXTURE_2D, textureCubeMapHandler);
    gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, texture2d.getInternalFormat(), texture2d.getWidth(),
            texture2d.getHeight(), 0, texture2d.getPixelFormat(), texture2d.getPixelType(),
            texture2d.getBuffer());
    gl.glGenerateMipmap(GL.GL_TEXTURE_2D);
    gl.glUniform1i(FxManager.textureCubemapHandler, 0);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
}

With only those lines of code, can anyone manage to see what may be wrong in my code for rendering with a 3D texture ? I was thinking about some parameterization missing (GL.GL_TEXTURE_WRAP_R doesn’t exist and I don’t know why 'cos I saw this int in a lot of examples on the net) but maybe it could come from another problem.

Don’t hesitate to ask more information if needed and thanks in advance for any help.