# Opengl black screen for a simple translation

i am a beginner to opengl following an online guide, I am trying to make a simple translation to my triangle. The triangle did render correctly when i made a float uniform to translate it, but when i multiply a mat4 to translate it, i get a black screen. Opengl outputs no error, i can't tell where is the problem. Here is the code: https://pastebin.com/en2zpPTh

Here's my drawing loop:

//Loop until window close
while (!glfwWindowShouldClose(mainWindow))
{
//Get + Handle user input events
glfwPollEvents();

if (direction)
{
triOffset += triIncrement;
}
else
{
triOffset -= triIncrement;
}

if (abs(triOffset >= triMaxOffset))
{
direction = !direction;
}

//Clear window
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);

//Draw

glm::mat4 model;
/*
[1,0,0,0]
[0,1,0,0]
[0,0,1,0]
[0,0,0,1]
*/
model = glm::translate(model, glm::vec3(triOffset, 0.0f, 0.0f));

glUniformMatrix4fv(uniformModel, 1, GL_FALSE, glm::value_ptr(model));

glBindVertexArray(VAO);
glDrawArrays(GL_TRIANGLES, 0, 3);

glBindVertexArray(0);
glUseProgram(0);

glfwSwapBuffers(mainWindow);

return 0;
}


// Vertex Shader
static const char* vShader = " \n"
"#version 330                  \n"
"layout (location = 0) in vec3 pos;\n"
"uniform mat4 model;                        \n"
"void main()\n"
"{\n"
"   gl_Position = model * vec4(pos, 1.0);\n"
"}\n";


//Fragment shader
static const char* fShader =  " \n"
"#version 330                  \n"
"out vec4 color;               \n"
"void main()\n"
"{\n"
"   color = vec4(1.0, 1.0, 0.5, 1.0);\n"
"}\n";

• uniformModel = glGetUniformLocation(shader, "model"); << Do you call glUseProgram(..) before this call ? High up on my checklist would be to see if the uniform was bound correctly. – PaulHK Jun 26 '18 at 3:48
• There is definitly a problem with the matrix, because it is not set to an identity matrix, even when i call glm::mat4 model = glm::mat4(); , so the translation isn't happening, and the triangle is not drawn. – Nathan Lenas Jun 26 '18 at 9:48
• Yes i added the glUseProgram(shader); before ;uniformModel = glGetUniformLocation(shader, "model"); but i think now the problem is on the cpu side because when i breakpoint the render loop the matrix is always [0,0,0,0] instead of identity matrix – Nathan Lenas Jun 26 '18 at 9:57