I am trying to rotate a quad in a 3D space. The following code shows the vertex shader utilized to draw the quad:
#version 330 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
out vec3 ourColor;
uniform mat4 transform;
uniform mat4 model;
uniform mat4 view;
uniform mat4 projection;
void main()
{
gl_Position = transform*(projection*view*model*vec4(aPos, 1.0f));
ourColor = aColor;
}
The quad is displayed when transform
is not multiplied to projection*view*model*vec4(aPos,1.0f)
but is not displayed when it is multiplied as above.
The code for transformation:
trans=glm::rotate(trans,(float)(glfwGetTime()),glm::vec3(0.0,0.0,1.0));
float scaleAmount = sin(j*0.3);j=j+0.035;
trans=glm::scale(trans,glm::vec3(scaleAmount,scaleAmount,scaleAmount));
unsigned int transformLoc = glGetUniformLocation(shaderProgram, "transform");
glUniformMatrix4fv(transformLoc, 1, GL_FALSE, glm::value_ptr(trans));
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
I have set the uniform present in the vertex shader as well.
Why is it not rotating and scaling, or even appearing when I multiply transform
with (projection*view*model*vec4(aPos,1.0f))
?
Edit: I figured out that the problem is with scaling, since the code works with rotation only. The code does not work with scaling only.