# For some reason I can apply my uniforms to shaders in one place but not another

I actually did the right debugging to find this. I am doing a section on lighting

This is a lesson that I am following Youtube OpenGL

``````#version 330 core

struct Material{
vec3 ambient;
vec3 diffuse;
vec3 specular;
float shineness;
};

struct Light{
vec3 position;
vec3 ambient
vec3 diffuse;
vec3 specular;
};

in vec3 frag_pos;
in vec3 normal;
in vec2 texCoord;
out vec4 frag_color;

//uniform sampler2D texture1;
//uniform sampler2D texture2;

uniform Material material;
uniform Light light;
uniform vec3 viewPos;
uniform vec3 Lightambient;
void main(){
vec3 ambient = material.ambient * light.ambient;
//vec3 ambient = vec3(0.75);
vec3 norm = normalize(normal);
vec3 lightDir = normalize(light.position - frag_pos);
float diff = max(dot(norm, light.position), 0.0);
vec3 diffuse = light.diffuse * diff * material.diffuse;
vec3 viewDir = normalize(viewPos - frag_pos);
vec3 reflectDir = reflect(-lightDir, norm);
float specular = pow(max(dot(viewDir, reflectDir), 0), 128 * material.shineness);
vec3 specu = light.specular * specular * material.specular;
frag_color = vec4(vec3(Lightambient + diffuse + specular ), 1.0);
//frag_color = vec4(material.specular, 1);
}
``````

what I know is that I got the case right because he uses the same name for things. As you can see the last line I tested the material property I also tested the light property which comes up with just Black. Of course these are used in different classes which I think have something to do with it.

part of the main is

``````Cube cube(Material::emerald, glm::vec3(0, 0, -1), glm::vec3(0.75f));
cube.init();

Lamp1 lamp(glm::vec3(1.0f), glm::vec3(1.0f, 1.0f, 1.0f), glm::vec3(1.0f), glm::vec3(1.0f), glm::vec3(-1, -0.5, -0.5), glm::vec3(0.25f));
lamp.init();
double lastTime = 0;
while (!scrn.shouldClose()) {
double currentTime = glfwGetTime();
deltaTime = currentTime - lastTime;
lastTime = currentTime;
processInput();
scrn.update();

//glm::mat4 trans(1.0f);
//trans = glm::rotate(trans, glm::radians((float)glfwGetTime() / 1.0f), glm::vec3(0, 0, 1));

glm::mat4 view = glm::mat4(1.0);

glm::mat4 projection = glm::mat4(1.0);

view = cam.getViewMatrix();
projection = glm::perspective(glm::radians(cam.getZoom()), (float)width / (float)height, 0.1f, 100.0f);

glDrawArrays(GL_TRIANGLES, 0, 36);
//glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);

scrn.newFrame();

}
``````

the light:

``````#include "Cube.hpp"

class Lamp1 : public Cube {
public:
glm::vec3 lightColor;
glm::vec3 ambient;
glm::vec3 diffuse;
glm::vec3 specular;
Lamp1(glm::vec3 lig, glm::vec3 amb, glm::vec3 dif, glm::vec3 spec, glm::vec3 pos, glm::vec3 siz) // add material
:lightColor(lig), ambient(amb), diffuse(dif), specular(spec), Cube(Material::white_plastic, pos, siz)
{

}
}
};

``````

the cube:

``````#include "../Model.h"
#include "../material.h"

class Cube : public Model {
public:
glm::vec3 position;
glm::vec3 size;
Material material;
Cube(Material material, glm::vec3 pos, glm::vec3 siz) // add material
:material(material), position(pos), size(siz)
{}
void init() {
int numVerts = 36;
float vertices[] = {
// position                 normal              texcoord
-0.5f, -0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    0.0f, 0.0f,
0.5f, -0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    1.0f, 0.0f,
0.5f,  0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    1.0f, 1.0f,
0.5f,  0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    1.0f, 1.0f,
-0.5f,  0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    0.0f, 1.0f,
-0.5f, -0.5f, -0.5f,     0.0f,  0.0f, -1.0f,    0.0f, 0.0f,

-0.5f, -0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    0.0f, 0.0f,
0.5f, -0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    1.0f, 0.0f,
0.5f,  0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    1.0f, 1.0f,
0.5f,  0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    1.0f, 1.0f,
-0.5f,  0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    0.0f, 1.0f,
-0.5f, -0.5f,  0.5f,     0.0f,  0.0f,  1.0f,    0.0f, 0.0f,

-0.5f,  0.5f,  0.5f,    -1.0f,  0.0f,  0.0f,    1.0f, 0.0f,
-0.5f,  0.5f, -0.5f,    -1.0f,  0.0f,  0.0f,    1.0f, 1.0f,
-0.5f, -0.5f, -0.5f,    -1.0f,  0.0f,  0.0f,    0.0f, 1.0f,
-0.5f, -0.5f, -0.5f,    -1.0f,  0.0f,  0.0f,    0.0f, 1.0f,
-0.5f, -0.5f,  0.5f,    -1.0f,  0.0f,  0.0f,    0.0f, 0.0f,
-0.5f,  0.5f,  0.5f,    -1.0f,  0.0f,  0.0f,    1.0f, 0.0f,

0.5f,  0.5f,  0.5f,     1.0f,  0.0f,  0.0f,    1.0f, 0.0f,
0.5f,  0.5f, -0.5f,     1.0f,  0.0f,  0.0f,    1.0f, 1.0f,
0.5f, -0.5f, -0.5f,     1.0f,  0.0f,  0.0f,    0.0f, 1.0f,
0.5f, -0.5f, -0.5f,     1.0f,  0.0f,  0.0f,    0.0f, 1.0f,
0.5f, -0.5f,  0.5f,     1.0f,  0.0f,  0.0f,    0.0f, 0.0f,
0.5f,  0.5f,  0.5f,     1.0f,  0.0f,  0.0f,    1.0f, 0.0f,

-0.5f, -0.5f, -0.5f,     0.0f, -1.0f,  0.0f,    0.0f, 1.0f,
0.5f, -0.5f, -0.5f,     0.0f, -1.0f,  0.0f,    1.0f, 1.0f,
0.5f, -0.5f,  0.5f,     0.0f, -1.0f,  0.0f,    1.0f, 0.0f,
0.5f, -0.5f,  0.5f,     0.0f, -1.0f,  0.0f,    1.0f, 0.0f,
-0.5f, -0.5f,  0.5f,     0.0f, -1.0f,  0.0f,    0.0f, 0.0f,
-0.5f, -0.5f, -0.5f,     0.0f, -1.0f,  0.0f,    0.0f, 1.0f,

-0.5f,  0.5f, -0.5f,     0.0f,  1.0f,  0.0f,    0.0f, 1.0f,
0.5f,  0.5f, -0.5f,     0.0f,  1.0f,  0.0f,    1.0f, 1.0f,
0.5f,  0.5f,  0.5f,     0.0f,  1.0f,  0.0f,    1.0f, 0.0f,
0.5f,  0.5f,  0.5f,     0.0f,  1.0f,  0.0f,    1.0f, 0.0f,
-0.5f,  0.5f,  0.5f,     0.0f,  1.0f,  0.0f,    0.0f, 0.0f,
-0.5f,  0.5f, -0.5f,     0.0f,  1.0f,  0.0f,    0.0f, 1.0f
};

vector<unsigned int> induces(numVerts);
for (int i = 0; i < numVerts; i++) {
induces[i] = i;
}
Texture tex1("images/airplane_512x512.png", "texture0");
Texture tex2("images/tunnel.bmp", "texture1");
meshes.push_back(Mesh(Vertex::genList(vertices, numVerts), induces, { tex1, tex2 }));
}
glm::mat4 model(glm::mat4(1.0f));
model = glm::translate(model, position);
model = glm::rotate(model, (float)glfwGetTime() * glm::radians(-55.0f), glm::vec3(0.5f));
model = glm::scale(model, size);

}
};
``````

In the future, please don’t post code with GL calls buried in a bunch of wrappers. It’s not a given or necessarily even obvious what those do.

Here though, we can guess. Notice anything about the above subset?

Do you see a `shade.activate()` before setting up the `light.*` uniforms?

You need to bind the shader program before you can set old-style global-scope uniforms using glUniform…().

By contrast, note that you do not need to bind the program first if you instead use a Direct State Access (DSA) API call for that, like glProgramUniform…().

I would suggest that you stop burying GL calls within abstractions until you really lock-in how OpenGL work. Then add the abstractions that make sense from a performance perspective. Fewer abstractions is typically better, from a code clarity and performance perspective.