shaders with samplerCube -> all is black

hi all! I have a problem, all shaders that use a samplerCube map look totally black, I don´t know if it is a problem of my opengl version (2.1.2), my drivers, the compiler (NVIDIA 1.2 Cg compiler) or what…

thanks!

The problem is in your mind: what do you expect to hear giving so little information?

As you seem to have more than one shader, did any of them work before you changed the platform?

Anyway, post your shader CG code plus textures & shader initialization code.

none of them works, for example, the simplest shader:

[vertex]
varying vec3 vnorm;

void main ()
{
vnorm = gl_NormalMatrix * gl_Normal;
gl_Position = ftransform();
}

[fragment]
varying vec3 vnorm;
uniform samplerCube texcube;

void main ()
{
vec3 norm = normalize(vnorm);
vec4 frag = textureCube(texcube, norm);

gl_FragColor = frag;

}

glUniform1i(getUniLoc(progBolas, “texcube”), bola[0].material.idMapaCubico);

getUniformLocation inside getUniLock returns 0, so i thinks it is ok.

also i initialize cube map as follows

glEnable(GL_TEXTURE_CUBE_MAP);
glGenTextures(1, &idMapaCubico);

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);

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

//glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_MODULATE);

glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(1));

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(2));

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(3));

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(4));

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(5));

glBindTexture(GL_TEXTURE_CUBE_MAP,idMapaCubico);
glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_EXT, 0, GL_RGB8,
tx.getWidth(), tx.getHeight(), 0, GL_RGB, GL_UNSIGNED_BYTE, tx.getData(6));
glDisable(GL_TEXTURE_CUBE_MAP);

glEnable(GL_TEXTURE_CUBE_MAP);

this is relevant to fixed function only, you dont need it

glUniform1i(getUniLoc(progBolas, “texcube”), bola[0].material.idMapaCubico);

you are supposed to initialize sampler with the number of the texture unit your texture is bound to, not name of the texture itself

  1. What is in the logs for shaders compilation & linking?
  2. Show your shader activation code (where you bind this texture, activate the shader & drawing something)
  3. Try just writing vnorm to the output color in the fragment shader. Do you see anything in this case?

minor: you don’t need to glEnable/Disable (GL_TEXTURE_CUBE_MAP) when using shaders

idMapaCubico is the value returned by glGenTextures() so it is ok

  1. Logs are ok, no error or warning is displayed

2.I draw simply calling a list:

glUseProgram(progBolas);
glCallList(lista);
glUseProgram(0);

do i need glBindTexture(GL_TEXTURE_CUBE_MAP_EXT, material.idMapaCubico) before calling the list?? i thought not, i have tested it and the result is the same…

varying vec3 vnorm;
uniform samplerCube texcube;

void main ()
{
vec3 norm = normalize(vnorm);
vec4 frag = textureCube(texcube, norm);

gl_FragColor = vec4(vnorm, 1.0);

}

the result is this one:

the cube map used is the first here:
http://www.codemonsters.de/home/content.php?show=cubemaps

  1. Your cubemap texture has to be bound to the GL_TEXTURE_CUBE_MAP_EXT binding point when draw command is executed. So, in general case, you should bind it every time you draw something using it. Alternatively, you can include this binding into the display list you use for drawing.

minor: AFAIK, you don’t need to bind it each time before a side is filled with data.

Try the following:
-disable filtering (set nearest in both)
-set wrapping to CLAMP

Also, we somehow have to be sure you load correct data into the cubemap. Check your image loading routine at least…

glUniform1i(getUniLoc(progBolas, “texcube”), bola[0].material.idMapaCubico);

idMapaCubico is the value returned by glGenTextures() so it is ok

This is exactly what is incorrect.
You should do following:


glActiveTexture(GL_TEXTURE3)
glBindTexture(GL_TEXTURE_CUBE_MAP, idMapaCubico);
glUniform1i(getUniLoc(progBolas, "texcube"), 3)

third tex unit picked arbitrarily in the example

You are correct, kyle.
I wonder how I missed it in discussion…

ohhhh!! thank you all guys! that was the problem… i thought I need pass the texture id to the shader… really thanks!