<p>It seems that nothing was wrong with the code I posted.
I deleted my complete build and rebuild it, and now it seems to work.
I don't see anything on screen but i think that error is unrelated.</p>

<p>I can see the matrix in the nsight debugger.</p>

CC BY-SA 3.0
2016-07-04T22:32:49.957Z
2016-07-04T22:32:49.957Z
Dragonseel
<p>I try to write a simple triangle mesh renderer with OpenGL.</p>

<pre><code>void ShaderProgram::SetUniformMatrix4(std::string name, glm::mat4 matrix)
{
  GLint location = glGetUniformLocation(program_, name.c_str());

  if (location != -1)
  {
     glUniformMatrix4fv(location, 1, GL_FALSE, &amp;matrix[0][0]);
  }
}
</code></pre>

<p>Is my uniform related code. I made sure that <em>glUseProgram(program_)</em> is called before this method is executed.<br>
Also the <em>glm::mat4</em> does indeed contain the correct values and <em>program_</em> has a value of 3 so it seems valid.<br>
The location comes out as a 0 </p>

<p>Here how I call that method:</p>

<pre><code>shader_-&gt;BindProgram();
shader_-&gt;SetUniformMatrix4("matModel", transformation);

texture_-&gt;BindTexture();
mesh_-&gt;Draw();
texture_-&gt;FreeTexture();

shader_-&gt;FreeProgram();
</code></pre>

<p>Now I have following simple Vertex Shader </p>

<pre><code>#version 330 core

layout (location = 0) in vec3 vertexPosition_modelspace;
layout (location = 1) in vec3 vertexNormal_modelspace;
layout (location = 2) in vec2 textureCoords_modelspace;

uniform mat4 matModel;

layout(std140) uniform Camera{
  mat4 matView;
  mat4 matProjection;
};

out vec2 textureCoords;

void main(){    
  textureCoords = textureCoords_modelspace;
  gl_Position =  matProjection * matView * matModel * vec4(vertexPosition_modelspace, 1.0);
}
</code></pre>

<p>I see nothing on the screen which is the main error.<br>
When Debugging with Nvidia-NSight I find that all values except the <em>matModel</em> are correctly set. The <em>matModel</em> contains all zero which seems to be why the model isn't drawn.</p>

<p>Why is the <em>matModel</em> always zero, even when I try to set the uniform?</p>

<opengl><shader><c++>
Uniform not set, despite valid location
Dragonseel
# Uniform not set, despite valid location

(Asked by: username_0 on 2016-07-04)

I try to write a simple triangle mesh renderer with OpenGL.

```
void ShaderProgram::SetUniformMatrix4(std::string name, glm::mat4 matrix)
{
  GLint location = glGetUniformLocation(program_, name.c_str());

  if (location != -1)
  {
     glUniformMatrix4fv(location, 1, GL_FALSE, &matrix[0][0]);
  }
}

```

Is my uniform related code. I made sure that *glUseProgram(program\_)* is called before this method is executed.  
Also the *glm::mat4* does indeed contain the correct values and *program\_* has a value of 3 so it seems valid.  
The location comes out as a 0

Here how I call that method:

```
shader_->BindProgram();
shader_->SetUniformMatrix4("matModel", transformation);

texture_->BindTexture();
mesh_->Draw();
texture_->FreeTexture();

shader_->FreeProgram();

```

Now I have following simple Vertex Shader

```
#version 330 core

layout (location = 0) in vec3 vertexPosition_modelspace;
layout (location = 1) in vec3 vertexNormal_modelspace;
layout (location = 2) in vec2 textureCoords_modelspace;

uniform mat4 matModel;

layout(std140) uniform Camera{
  mat4 matView;
  mat4 matProjection;
};

out vec2 textureCoords;

void main(){    
  textureCoords = textureCoords_modelspace;
  gl_Position =  matProjection * matView * matModel * vec4(vertexPosition_modelspace, 1.0);
}

```

I see nothing on the screen which is the main error.  
When Debugging with Nvidia-NSight I find that all values except the *matModel* are correctly set. The *matModel* contains all zero which seems to be why the model isn't drawn.

Why is the *matModel* always zero, even when I try to set the uniform?

**Tags:** opengl, shader, c++


---

## 1 answers

### Answer by username_0 on 2016-07-04. Score: 1 | Accepted answer

It seems that nothing was wrong with the code I posted.
I deleted my complete build and rebuild it, and now it seems to work.
I don't see anything on screen but i think that error is unrelated.

I can see the matrix in the nsight debugger.


---

