<p>You forgot to call <code>glVertexArrayAttribFormat</code>:</p>

<pre><code>glCreateBuffers(1, &amp;buffer);
glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);

glCreateVertexArrays(1, &amp;vao);
glEnableVertexArrayAttrib(vao, 0);
glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0);

glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);
glVertexArrayAttribBinding(vao, 0, 0);
</code></pre>

CC BY-SA 3.0
2017-07-16T20:37:42.823Z
Great to see you active on this new Stack Exchange site dedicated to graphics.
Startec
CC BY-SA 3.0
2017-07-16T16:16:17.923Z
2017-07-16T16:16:17.923Z
Nicol Bolas
<p>I am trying to draw a triangle.  Here is my code:
    const char* vertexShaderSource = "#version 330 core\n"
        "layout (location = 0) in vec3 aPos;\n"
        "void main()\n"
        "{\n"
        "   gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
        "}\0";</p>

<pre><code>const char* fragmentShaderSource = "#version 330 core\n"
    "out vec4 FragColor;\n"
    "void main()\n"
    "{\n"
    "   FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
    "}\n\0";

GLfloat vertices[] = {
    -0.5f, -0.5f, 0.0f,
    0.5f, -0.5f, 0.0f,
    0.0f,  0.5f, 0.0f
};

// Create the VAO
GLuint vao;
GLuint buffer;

glGenBuffers(1, &amp;buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glGenVertexArrays(1, &amp;vao);
glBindVertexArray(vao);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
</code></pre>

<p>This results in the following image:
<a href="https://i.sstatic.net/7uGSN.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7uGSN.png" alt="triangle"></a></p>

<p>However, trying to use newer, DSA type methods does not draw the correct triangle.  If I switch my code to:</p>

<pre><code>glCreateBuffers(1, &amp;buffer);
glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);

glCreateVertexArrays(1, &amp;vao);
glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);
glVertexArrayAttribBinding(vao, 0, 0);
glEnableVertexArrayAttrib(vao, 0);
</code></pre>

<p>I get this image:</p>

<p><a href="https://i.sstatic.net/1hBov.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1hBov.png" alt="squished triangle"></a></p>

<p>The triangle is squished.  In fact, changing any of the coordinates of the last row of vertices (the point that is squished) do not change the image result.  Why is this happening?</p>

<opengl>
Different result with DSA (vertexArrayVertexBuffer, vertexArrayAttribBinding) than with glBufferData
Startec
# Different result with DSA (vertexArrayVertexBuffer, vertexArrayAttribBinding) than with glBufferData

(Asked by: username_0 on 2017-07-16)

I am trying to draw a triangle. Here is my code:
const char\* vertexShaderSource = "#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"
"void main()\n"
"{\n"
" gl\_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);\n"
"}\0";

```
const char* fragmentShaderSource = "#version 330 core\n"
    "out vec4 FragColor;\n"
    "void main()\n"
    "{\n"
    "   FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);\n"
    "}\n\0";

GLfloat vertices[] = {
    -0.5f, -0.5f, 0.0f,
    0.5f, -0.5f, 0.0f,
    0.0f,  0.5f, 0.0f
};

// Create the VAO
GLuint vao;
GLuint buffer;

glGenBuffers(1, &buffer);
glBindBuffer(GL_ARRAY_BUFFER, buffer);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

glGenVertexArrays(1, &vao);
glBindVertexArray(vao);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);

```

This results in the following image:
[![triangle](https://i.sstatic.net/7uGSN.png)](https://i.sstatic.net/7uGSN.png)

However, trying to use newer, DSA type methods does not draw the correct triangle. If I switch my code to:

```
glCreateBuffers(1, &buffer);
glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);

glCreateVertexArrays(1, &vao);
glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);
glVertexArrayAttribBinding(vao, 0, 0);
glEnableVertexArrayAttrib(vao, 0);

```

I get this image:

[![squished triangle](https://i.sstatic.net/1hBov.png)](https://i.sstatic.net/1hBov.png)

The triangle is squished. In fact, changing any of the coordinates of the last row of vertices (the point that is squished) do not change the image result. Why is this happening?

**Tags:** opengl


---

## 1 answers

### Answer by username_1 on 2017-07-16. Score: 3 | Accepted answer

You forgot to call `glVertexArrayAttribFormat`:

```
glCreateBuffers(1, &buffer);
glNamedBufferStorage(buffer, sizeof(vertices), vertices, 0);

glCreateVertexArrays(1, &vao);
glEnableVertexArrayAttrib(vao, 0);
glVertexArrayAttribFormat(vao, 0, 3, GL_FLOAT, GL_FALSE, 0);

glVertexArrayVertexBuffer(vao, 0, buffer, 0, sizeof(GLfloat) * 3);
glVertexArrayAttribBinding(vao, 0, 0);

```

> **Comments:**
> **username_0**: Great to see you active on this new Stack Exchange site dedicated to graphics.  

---

