joo50135

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:

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

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