I've recently been converting my 3D hobby project from using old-school fixed-function pipeline to nice shiny new shaders. I have the proverbial spinning, textured cube as the guinea-pig.
However I've come up against a brick-wall with an odd problem that I can't seem to diagnose: the cube is there and rotating as it ever was, but I get the same 'flat' colour rather than my nice texture image on each face of the cube.
I've debugged, checked and re-checked my code against various tutorials, threads on this forum, other forums, etc. but can't find anything that helps - yet I'm obviously doing
something wrong.
I'm 99% certain that the code that loads and creates the shader and it's associated parameters is working because:
- the colour that I see is actually part of the texture image (I suspect it's 0,0 but can't be certain)
- if I use a different texture image I get a different colour
- if I hack the fragment shader to use some randomly chosen texture coordinate I get a different colour, ditto if I hard-code the colour
- I still have the fixed-function implementation, if I 'switch off' the shader and re-introduce the older code everything works perfectly, so I don't believe it's a problem with the code that loads the texture (and I switch off glEnable for textures for the shader version)
- I've managed to avoid the (apparently) common mistake of using the texture ID in the shader parameter rather than the texture
unit.
So I'm left thinking that I'm doing something wrong in the GLSL code, so here it is:
Vertex shader:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| #version 330
layout(location = 0) in vec3 pos; layout(location = 1) in vec3 normal; layout(location = 2) in vec2 coords;
uniform mat4 pvm;
out vec2 tc;
void main() { gl_Position = pvm * vec4( pos, 1 ); tc = coords; } |
Fragment shader:
1 2 3 4 5 6 7 8 9 10 11 12
| #version 330
uniform sampler2D tex;
in vec2 tc;
out vec4 fragColour;
void main() { fragColour = texture( tex, tc ); } |
I've fiddled with the GLSL code, changed the version number, tried
varying rather than in/out for the texture coords, used
in rather than 3.x style
location attributes - no difference.
I'm not going to post the Java code (or at least not yet) since I'm fairly confident it's correct and it's quite 'mature' so I'd spend more time explaining how it's structured.
So I'm not looking for someone to fix the problem for me, but hoping I can get some ideas or pointers for some other things to try as I'm completely out if ideas. Has anyone had a similar problem? Or can anyone suggest any ways I could attempt to diagnose what's going on? I'm stuck

Any help is greatly appreciated.