OpenGL 4.2 is basically killing me, I can't rotation, transformation or scaling, I have to use another library to do it, which is OpenGL mathematics. And I can't find any tutorials on how to do this.
I miss OpenGL 2.1.
Can you please guys help me out here.
I have this cube and I want to rotate it how can I do that in OpenGL mathematics?
void Engine::CreateCube()
{
float* Vertices = new float[72]; // Vertices for our square
Vertices[0] = -0.3f; Vertices[1] = -0.3f; Vertices[2] = 0.3f;
Vertices[3] = 0.3f; Vertices[4] = -0.3f; Vertices[5] = 0.3f;
Vertices[6] = 0.3f; Vertices[7] = 0.3f; Vertices[8] = 0.3f;
Vertices[9] = -0.3f; Vertices[10] = 0.3f; Vertices[11] = 0.3f;
Vertices[12] = -0.3f; Vertices[13] = -0.3f; Vertices[14] = -0.3f;
Vertices[15] = -0.3f; Vertices[16] = 0.3f; Vertices[17] = -0.3f;
Vertices[18] = 0.3f; Vertices[19] = 0.3f; Vertices[20] = -0.3f;
Vertices[21] = 0.3f; Vertices[22] = -0.3f; Vertices[23] = -0.3f;
Vertices[24] = -0.3f; Vertices[25] = 0.3f; Vertices[26] = -0.3f;
Vertices[27] = -0.3f; Vertices[28] = 0.3f; Vertices[29] = 0.3f;
Vertices[30] = 0.3f; Vertices[31] = 0.3f; Vertices[32] = 0.3f;
Vertices[33] = 0.3f; Vertices[34] = 0.3f; Vertices[35] = -0.3f;
Vertices[36] = -0.3f; Vertices[37] = -0.3f; Vertices[38] = -0.3f;
Vertices[39] = 0.3f; Vertices[40] = -0.3f; Vertices[41] = -0.3f;
Vertices[42] = 0.3f; Vertices[43] = -0.3f; Vertices[44] = 0.3f;
Vertices[45] = -0.3f; Vertices[46] = -0.3f; Vertices[47] = 0.3f;
Vertices[48] = 0.3f; Vertices[49] = -0.3f; Vertices[50] = -0.3f;
Vertices[51] = 0.3f; Vertices[52] = 0.3f; Vertices[53] = -0.3f;
Vertices[54] = 0.3f; Vertices[55] = 0.3f; Vertices[56] = 0.3f;
Vertices[57] = 0.3f; Vertices[58] = -0.3f; Vertices[59] = 0.3f;
Vertices[60] = -0.3f; Vertices[61] = -0.3f; Vertices[62] = -0.3f;
Vertices[63] = -0.3f; Vertices[64] = -0.3f; Vertices[65] = 0.3f;
Vertices[66] = -0.3f; Vertices[67] = 0.3f; Vertices[68] = 0.3f;
Vertices[69] = -0.3f; Vertices[70] = 0.3f; Vertices[71] = -0.3f;
glGenVertexArrays(1, &VAO_ID[0]); // Create our Vertex Array Object
glBindVertexArray(VAO_ID[0]); // Bind our Vertex Array Object so we can use it
glGenBuffers(1, VBO_ID); // Generate our Vertex Buffer Object
glBindBuffer(GL_ARRAY_BUFFER, VBO_ID[0]); // Bind our Vertex Buffer Object
glBufferData(GL_ARRAY_BUFFER, 72 * sizeof(GLfloat), Vertices, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW
glVertexAttribPointer((GLuint)0, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer
glEnableVertexAttribArray(0); // Disable our Vertex Array Object
glBindVertexArray(0); // Disable our Vertex Buffer Object
delete [] Vertices; // Delete our vertices from memory
}
In my redner function which draws the cube i tried doing this but nothing changes.
void Engine::Render()
{
glViewport(0, 0, WindowWidth, WindowHeight);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
ViewMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, 0.0f, -5.f)); // Create our view matrix which will translate us back 5 units
ModelMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(0.5f)); // Create our model matrix which will halve the size of our model
glm::mat4 View = glm::mat4(1.);
View = glm::rotate(View, angle * -1.0f, glm::vec3(1.f, 0.f, 0.f));
glBindVertexArray(VAO_ID[0]); // Bind our Vertex Array Object
glDrawArrays(GL_QUADS, 0, 24); // Draw our cube
glBindVertexArray(0); // Unbind our Vertex Array Object
}