Hello…I am new to shaders and they seem pretty self explanatory but I am getting frustrated quickly. I am starting to work with uniforms but I cannot get the location call to return anything other than incorrect results.
BTW…Visual C++ w/ Freeglut 2.6 and GLee 5.4. Maybe it’s Glee?
Here’s the code…
C++ Segment
shaderPrg = glCreateProgram();
glAttachShader(shaderPrg, v);
glAttachShader(shaderPrg, f);
glLinkProgram(shaderPrg);
int loc1 = glGetUniformLocation(shaderPrg, “color”);
int loc2 = glGetUniformLocation(shaderPrg, “norm”);
int loc3 = glGetUniformLocation(shaderPrg, “topo”);
VERTEX SHADER
uniform sampler2D topo;
uniform sampler2D norm;
uniform sampler2D color;
varying vec2 texture_coordinate;
void main()
{
// Passing The Texture Coordinate Of Texture Unit
texture_coordinate = vec2(gl_MultiTexCoord0);
// Transforming The Vertex
gl_Position = ftransform();
}
FRAGMENT SHADER
uniform sampler2D topo;
uniform sampler2D norm;
uniform sampler2D color;
varying vec2 texture_coordinate;
void main()
{
// Sampling The Texture And Passing It To The Frame Buffer
gl_FragColor = texture2D(color, texture_coordinate);
}
OK…all I can get is…
Loc1 = 0 which is wrong as color is at 2
Loc2 = -1 which is wrong as normBILL is at 1
Loc3 = -1 which is wrong as topo is at 0
I am obviously missing something rather simple. The shader seems to work and when I tweak it I see changes. One other thing I noticed is if I change the fragment shader line to…
gl_FragColor = vec4(1); //texture2D(color, texture_coordinate);
…my geometry is all white, as expected, but all locations are -1. Is there a reference thing I am having a problem with? Do I need to reference everything in a certain way for the locations to properly report?