(gl_)Normal question :D

Pardon me for my ignorance, but I’m quite new to GLSL. I have very simple task: to make a cube and color it’s surface with a color depending to it’s surface orientation using shaders. I was expecting gl_Normal to help me, but I realized that these normals are always (0.0,0.0,1.0)…

Posting that, quite simple shader. Result of these two shaders is completely blue cube,but I want it multicolored…

Thanx in advance…
vertex shader:

varying vec3 N;

void main(void) {
gl_Position = ftransform();
N = gl_Normal;

fragment shader:

varying vec3 N;

void main(void) {
gl_FragColor = vec4(1.0);
gl_FragColor.rgb = N;

Are you sending the per-vertex normals? Do you rotate the cube around, to look what the other faces’ colors are?

For each and every vertex within cube, I have set glNormal (within API rendering code) as required, meaning all normals are oriented as x,y,z,-x,-y,-z axes. On the other hand, yes, I’d like to rotate cube (no problem on cube rotation, just ‘coloring’ is issue) and take look at the color on the some other face, but I’d like that color rotation independent.

“and take look at the color on the some other face”
so, you have only seen one face of the cube? The face that points towards you and thus is blue?

No, no… I’am able to rotate cube, but all of faces are blue…

One thing that would not solve the current issue but the next one: Transform the gl_Normal built-in by the modelview matrix. Vertex normal is given to the vertex shader in object space, so you may have to transform it to eye space to see a change in the faces color depending on the cube orientation.

For your problem, I have no ideas. Actually I think that the problem is not in the shader part but in your opengl program. Could we see the rendering code?