Class Button

So from my understanding in order to move a 2d shape you need manipulate the vertices and then update????

If i do need to update the buffer how i would go by doing that?

float xpos = 150 //Cords relative to the window application so let say the window size 480 by 260 float ypos = 60 Where would I plug in position in the vertices array?

  float vertices[] = {

shader.setup("Resources/Shaders/shape.vertex", "Resources/Shaders/shape.frag");

glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
// bind the Vertex Array Object first, then bind and set vertex buffer(s), and then configure vertex attributes(s).

glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_DYNAMIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);

// note that this is allowed, the call to glVertexAttribPointer registered VBO as the vertex attribute's bound vertex buffer object so afterwards we can safely unbind
glBindBuffer(GL_ARRAY_BUFFER, 0);

// You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other
// VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.

Pass 2d vector to vertex shader as uniform:

uniform vec2 position;

Calculate new vertex position:

gl_Position = vec4(position.xy+vertex.xy,vertex.z,1.0);
  • \$\begingroup\$ What would i pass in to my shader when you vertex? @Hihikomori \$\endgroup\$
    – user146000
    Dec 31 '20 at 11:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy