Vertex shader:
#version 330 core
layout (location = 0) in vec2 position;
void main() {
gl_Position = vec4(position.xy, 0.0f, 1.0f);
}
Fragment shader:
Fragment shader:
#version 330 core
out vec4 color;
void main() {
color = vec4(1.0f, 1.0f, 0.0f, 1.0f);
}
I use this to create my object:
m_verticles[0] = posx;
m_verticles[1] = posy;
m_verticles[2] = posx;
m_verticles[3] = posy - height;
m_verticles[4] = posx + width;
m_verticles[5] = posy - height;
m_verticles[6] = posx + width;
m_verticles[7] = posy;
m_points[0] = 0;
m_points[1] = 1;
m_points[2] = 2;
m_points[3] = 0;
m_points[4] = 2;
m_points[5] = 3;
glGenVertexArrays(1, &m_VAO);
glGenBuffers(1, &m_VBO);
glGenBuffers(1, &m_EBO);
glBindVertexArray(m_VAO);
glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(m_verticles), m_verticles, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(m_points), m_points, GL_STATIC_DRAW);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 2 * sizeof(float), (GLvoid*)0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
And this to draw it:
glUseProgram(shaderProgram);
glBindVertexArray(target.m_VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, (GLvoid*)0);
glBindVertexArray(0);
(target is the object which has the m_VAO buffer)
When I use glDrawArrays it works perfectly fine, but only for the first triangle, and when I do this, it doesn’t draw anything at all. There must be something I’m doing wrong with my Element Array Buffer, but I cant figure it out by myself.