Initializing cubemap texture


I’m trying to create an environmentmap shader with glsl but cannot get the cubemap loaded into the shader.

After initialization of the shader I create the cubemap with this code:

 static GLenum faceTarget[6] = {
  LTGA face;
  int i;
  for (i=0; i<6; i++) {

	glTexImage2D (faceTarget[i], 0, GL_RGB,face.GetImageWidth(), face.GetImageHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, face.GetPixels());


  GLint cm = glGetUniformLocation(p, "cm");
  glUniform1f(cm, 0);

but the shader always outputs black.
What could be wrong?

1.) Texture generation is replaced by vertex shaders, so if you have one, you need to write your own texture coord generation code inside it.
2.) Samplers are integers. You must use glUniform1i() to load the texture image unit id into your sampler (See OpenGL 2.1 spec page 82.)
3.) glUniform*() calls have no program parameter, they work on the currently active program, means they must be called after glUseProgram(yourProgram).
4.) Shaders use texture image units. There is no need to enable or disable the fixed pipeline texture units. That’s implicitly done by the shaders.

Add glGetError calls for debugging.

  1. removed it, but shouldn’t cause any problems
  2. fixed
  3. No problem, I am calling it after glUseProgram(…)
  4. removed it

Stil not working :confused:

5.) What’s your hardware and drivers?
6.) This renders something without the shader?
7.) With the shader, is your object rendered at all or do you see only a black screen? Try glClearColor(0.5f, 0.0f, 0.5f, 0.0f) dark magenta to see if you rendered black.
8.) Show your complete shader sources.
9.) What are the face.GetImageWidth() and face.GetImageHeight() for all six textures? (square power-of-two?)
10.) Do you see something if you just download single colored 1x1 textures? Use a different color per face, no black.
11.) What’s your glPixelStore(GL_UNPACK_ALIGNMENT)? Use 1! Mind the default is 4 and GL_RGB will only line up with multiple-of-4 sizes correctly, should show skewed images otherwise.

> glBindTexture(GL_TEXTURE_CUBE_MAP,0);

Try calling glGenTextures() to get a texture id or at least use 1. Zero is reserved and I’m not even sure if you can use it for texturing.

Zero is a valid texture “object” which is reserved for the immediate textures.
glBindTexture(_, 0) is the only way to switch back to that immediate texture once you really used a texture object id != 0.
It’s probably not what he wanted, but otherwise should just work.


thanks for all the suggestions.
It works now, the textures had a wrong format.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.