cubemapping with shaders


I just want to texturize objects which have cubemap texture coordinates with shaders.

Without shaders, this works well (all faces are rendered correctly), but with shaders, only 2 faces are correctly drawn (+Z and -Z), the others are badly rendered (many lines on the faces).

I was looking here: and on many other places, but did not found what I am doing wrong.

Here is the fragment shader:

uniform samplerCube sampler_cube;

void main(void)
   gl_FragColor = textureCube (sampler_cube, gl_TexCoord[0].stq);

Any idea why ? Thanks in advance.

Try this instead if you are using version >= 3.x:

gl_FragColor = texture(sampler_cube, gl_TexCoord[0]);

Can you show us your glBindTexture call for this too?

Also check your texture specification: I’ve found one driver in the past where cubemaps go NUTS unless you specify the faces in +x/-x/+y/-y/+z/-z order.

glfreak, it didn’t help (I’m not using gl >= 3.0).

mhagain, here it is (it’s a deduction from quite complicate code):

glBindTexture (target, id);

where target is GL_TEXTURE_CUBE_MAP (I ensured it). I also have kept the glEnable (GL_TEXTURE_CUBE_MAP). I tried to remove the latter but with no more luck.

Images are also loaded in the order you wrote.

From what I understand from your posts, it seems my code is right. Maybe as often there’s some kind of bug in my code, but since everything else works fine for texturing, and that it works well without shaders, I highly doubt.

The only other thing I can think of is about the uniforms. I send it as a simple integer. Is that enough ?

Some more precisions:

It works well when shaders are disabled and I use the old vertex pointer functions.
It works bad (only 2 faces are good) when shaders are enabled and I use vertex attributes.
It does not work at all (orange color that is the main color of the skybox image set) when shaders are enabled and I use old vertex pointer functions.

Looking at the spec, the terms used are {s, t, p, q}, so maybe you should be using “p” instead of “q”:

gl_FragColor = textureCube (sampler_cube, gl_TexCoord[0].stp);

unless you intend to use the 4th term of gl_TexCoord[0].

Well thanks a lot !

I knew that OpenGL used {s,t,r,q} but glsl complained about str does not exist, but didn’t complain about stq…

Thanks again, it is solved now !

PS: for example this page about glTexCoord:

yeah, the GLSL spec says it doesn’t use {s,t,r,q} as the OpenGL spec does, because “r” would collide with the “r” from {r, g, b, a}. And it doesn’t allow mix + matching of the different indexing terms.