I’m trying move square, but it’s not happening. I’m just started using “glm”. So my doubt is how to move object using “glm”?. Or if you not able to understand following code, then send code for this using “glfw” & “glm” .Here is code:
#include <GLFW/glfw3.h>
#include<glm/glm.hpp>
#include<glm/gtc/matrix_transform.hpp>
#include<glm/gtc/type_ptr.hpp>
#define SCREEN_WIDTH 500
#define SCREEN_HEIGHT 500
#include<iostream>
using namespace std;
int posx = 0;
void Coordinate_System(void)
{
glViewport(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-100, 100, -100, 100, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void Process_Input(GLFWwindow* window)
{
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
}
int main(void)
{
glfwInit();
GLFWwindow* window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Hello World", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
float vertices[] = {
0,0,0,
10,0,0,
10,10,0,
0,10,0
};
Coordinate_System();
while (!glfwWindowShouldClose(window))
{
Process_Input(window);
glClearColor(0.2, 0.3, 0.3, 0.1);
glClear(GL_COLOR_BUFFER_BIT);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glm::vec4 vec(1.0f, 0.0f, 0.0f, 1.0f);
glm::mat4 trans = glm::mat4(1.0f);
trans = glm::translate(trans, glm::vec3(1.0f, 100.0f, 0.0f));
vec = trans * vec;
cout << vec.x << " " << vec.y << " " << vec.z << endl;
glDrawArrays(GL_POLYGON, 0, 4);
glDisableClientState(GL_VERTEX_ARRAY);
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}