PDA

View Full Version : initializing cubemap texture



Beau
12-06-2006, 03:47 AM
Hello,

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] = {
GL_TEXTURE_CUBE_MAP_POSITIVE_X,
GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
};
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_CUBE_MAP);
glBindTexture(GL_TEXTURE_CUBE_MAP,0);

LTGA face;
int i;
for (i=0; i<6; i++) {

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

glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

GLint cm = glGetUniformLocation(p, "cm");
glUniform1f(cm, 0);but the shader always outputs black.
What could be wrong?

Relic
12-06-2006, 04:28 AM
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.

Beau
12-06-2006, 05:35 AM
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:

Relic
12-06-2006, 07:43 AM
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.

Humus
12-06-2006, 08:39 AM
> 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.

Relic
12-06-2006, 03:35 PM
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.

Beau
12-08-2006, 12:13 AM
Hi,

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