PDA

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



joo50135
07-04-2015, 10: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:


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

glBindVertexArray(VAO);

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

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

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

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

glBindBuffer(GL_ARRAY_BUFFER, 0);

glBindVertexArray(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

GClements
07-04-2015, 02: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.

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