<p>We fixed it ! it was glm::mat4(); no initializing to a identity matrix, glm::mat4(1.0f); works fine, thank you for helping me !</p>

CC BY-SA 4.0
2018-06-26T10:08:48.557Z
2018-06-26T10:08:48.557Z
Nathan Lenas
<p>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:
<a href="https://pastebin.com/en2zpPTh" rel="nofollow noreferrer">https://pastebin.com/en2zpPTh</a></p>

<p>Here's my drawing loop:</p>

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

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

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

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

    //Draw
    glUseProgram(shader);

    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;
}
</code></pre>

<p>and here's my vertex shader:</p>

<pre><code>// 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";
</code></pre>

<p>And fragment shader:</p>

<pre><code>//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";
</code></pre>

CC BY-SA 4.0
2018-06-26T09:48:50.120Z
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
CC BY-SA 4.0
2018-06-26T09:57:48.123Z
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
<opengl><rendering><c++>
Opengl black screen for a simple translation
Nathan Lenas
# Opengl black screen for a simple translation

(Asked by: username_0 on 2018-06-25)

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
    glUseProgram(shader);

    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;
}

```

and here's my vertex shader:

```
// 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";

```

And fragment shader:

```
//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";

```

**Tags:** opengl, rendering, c++

> **Comments:**
> **username_0**: 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.  
> **username_0**: 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  

---

## 1 answers

### Answer by username_0 on 2018-06-26. Score: 1

We fixed it ! it was glm::mat4(); no initializing to a identity matrix, glm::mat4(1.0f); works fine, thank you for helping me !


---

