cubemap gl.glTexImage2D texture

hi

its a little thing i am looking for .
i play with cubemapping for some litte effects,
i load my textures and nowi want to copy them into:

    ...
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL.GL_RGBA,
            imageSize, imageSize, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE,
            texture[nr]<-error   );
   ...

how do i bind my textures (texture[nr]) into the glTextImage2d
to use them with cubemapping?

thanks :slight_smile:

You only create one texture and upload image data 6 times.
To activate the cubemap just activate the only texture you created.
Have a look at this working code brick:


    id = createOpenGLID();

    // Bind this texture to its id
    gl.glBindTexture(texType, id);

    gl.glTexParameteri(texType, GL.GL_TEXTURE_MIN_FILTER, minFilter);
    gl.glTexParameteri(texType, GL.GL_TEXTURE_MAG_FILTER, magFilter);
    gl.glTexParameteri(texType, GL.GL_TEXTURE_WRAP_S, wrapMode_s);
    gl.glTexParameteri(texType, GL.GL_TEXTURE_WRAP_T, wrapMode_t);
    gl.glTexParameteri(texType, GL.GL_TEXTURE_WRAP_R, wrapMode_r);
    if(anisotropicFiltering != 0)
      gl.glTexParameterf(texType, GL.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropicFiltering);

    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, posxData.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, posyData.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, poszData.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, negxData.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, negyData.getBuffer());
    gl.glTexImage2D(GL.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, internalFormat, width, height, 0, internalFormat, pixelFormat, negzData.getBuffer());

Remember that you have to use a specific texture matrix to generate “correct” reflections using the cubemap:
(the texType is “GL.GL_TEXTURE_CUBE_MAP”)


    gl.glEnable(texType);
    gl.glBindTexture(texType, id);

    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_COMBINE);
    gl.glTexEnvfv(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_COLOR, refl.getValues(), 0);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_COMBINE_RGB, GL.GL_INTERPOLATE);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_SRC0_RGB, GL.GL_TEXTURE);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_OPERAND0_RGB, GL.GL_SRC_COLOR);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_SRC1_RGB, GL.GL_PREVIOUS);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_OPERAND1_RGB, GL.GL_SRC_COLOR);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_SRC2_RGB, GL.GL_CONSTANT);
    gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_OPERAND2_RGB, GL.GL_SRC_ALPHA);

    gl.glGetDoublev(GL.GL_MODELVIEW_MATRIX, mvmatrix);

    double[] tex = texmatrix.array();
    double[] mv = mvmatrix.array();

    tex[0] = mv[0];
    tex[1] = mv[4];
    tex[2] = mv[8];
    tex[3] = mv[12];

    tex[4] = mv[1];
    tex[5] = mv[5];
    tex[6] = mv[9];
    tex[7] = mv[13];

    tex[8] = mv[2];
    tex[9] = mv[6];
    tex[10] = mv[10];
    tex[11] = mv[14];

    tex[12] = -mv[0]*mv[3] -mv[4]*mv[7] -mv[8]*mv[11];
    tex[13] = -mv[1]*mv[3] -mv[5]*mv[7] -mv[9]*mv[11];
    tex[14] = -mv[2]*mv[3] -mv[6]*mv[7] -mv[10]*mv[11];
    tex[15] = mv[15];

    gl.glMatrixMode(GL.GL_TEXTURE);
    gl.glLoadMatrixd(texmatrix);
    gl.glMatrixMode(GL.GL_MODELVIEW);