View Full Version : VBO/EBO with a lot of triangles/squares... just want to rotate one

07-04-2015, 09:26 AM
Hello my friends

So, I have a VAO with the following information:
- VBO with a lot of triangles (two triangles are a square)
- EBO with the indices of the triangles

I can draw normally all my squares...but now I just want to rotate one square... How can I do this? The following code will rotate all the squares...

I have:

glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);


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

glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);

glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);

glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));

glBindBuffer(GL_ARRAY_BUFFER, 0);


my vertex shader is like this:

#version 330 core
layout (location = 0) in vec3 position;
layout (location = 1) in vec2 texCoord;

out vec2 TexCoord;

uniform mat4 transform;

void main()
gl_Position = transform * vec4(position, 1.0f); //new

TexCoord = vec2(texCoord.x, 1.0 - texCoord.y);

and when I try to rotate one square, I'm doing this no rendering:

glm::mat4 transform;
transform = glm::rotate(transform, 270.0f, glm::vec3(0.0f, 0.0f, 1.0f));

GLint transformLoc = glGetUniformLocation(ourShader.Program, "transform");
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(transform));

The problem is that this code will rotate all my squares..and I just want to rotate one :(

Any help?

Thank you in advance

07-04-2015, 01:50 PM
but now I just want to rotate one square... How can I do this?
- Rotate the vertices in the application and copy the modified data to the VBO
- Add an extra vertex attribute holding the rotation for each vertex, and perform the rotation in the vertex shader
- Similar to the above, but use instanced rendering with an instance for each square, and add an instanced attribute for the rotation
- Store the rotation for each primitive in a UBO or texture and perform the rotation in a geometry shader

If you really only want to rotate one square, the first option is probably the best. If you want to rotate most of the squares, but with each having its own rotation, one of the shader-based options may be better.

07-05-2015, 02:20 AM
Thank you GClements :)
Option 1 working!!!!!!!