#ifndef GLUT_DISABLE_ATEXIT_HACK #define GLUT_DISABLE_ATEXIT_HACK #endif #define GLEW_STATIC #include <GL/glew.h> #include <GL/wglew.h> #include <GL/freeglut.h> #include <vector> #include <glm/glm.hpp> #include <glm/gtc/matrix_transform.hpp> //for matrices #include <glm/gtc/type_ptr.hpp> //undefine if u want to use the default bending constraint of pbd #include<iostream> using namespace std; GLfloat rtx = 0.0f, rty = 0.0f, rtz = 0.0; GLfloat step = 0.1; //float exp1 = 1e-3; void init() { glLoadIdentity(); } // float rquad = 0; void move(){ rquad += step; if(rquad>360)rquad = 0; } void draw(void) { move(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); printf("%lf\n",rquad); glPushMatrix(); glTranslatef(rtx, rty, rtz); glRotatef(rquad,1.0f,1.0f,1.0f); glScalef(0.3, 0.3, 0.3); glBegin(GL_QUADS); glColor3f(1, 0, 0); glVertex3f(-1.0f, -1.0f, 1.0f);// 前 glColor3f(0, 1, 0); glVertex3f(1.0f, -1.0f, 1.0f); glColor3f(0, 0, 1); glVertex3f(1.0f, 1.0f, 1.0f); glColor3f(0, 1, 1); glVertex3f(-1.0f, 1.0f, 1.0f); glColor3f(1, 0, 0); glVertex3f(-1.0f, -1.0f, -1.0f);// 后 glVertex3f(-1.0f, 1.0f, -1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(1.0f, -1.0f, -1.0f); glColor3f(0, 1, 0); glVertex3f(-1.0f, 1.0f, -1.0f);// 上 glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, 1.0f, -1.0f); glColor3f(0, 0, 1); glVertex3f(-1.0f, -1.0f, -1.0f);// 下 glVertex3f(1.0f, -1.0f, -1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glColor3f(1, 1, 0); glVertex3f(1.0f, -1.0f, -1.0f);// 左 glVertex3f(1.0f, 1.0f, -1.0f); glVertex3f(1.0f, 1.0f, 1.0f); glVertex3f(1.0f, -1.0f, 1.0f); glColor3f(0, 1, 1); glVertex3f(-1.0f, -1.0f, -1.0f);// 右 glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, -1.0f); glEnd(); glPopMatrix(); glutSwapBuffers(); } //float step = 0.001; int main(int argc, char * argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); glutInitWindowPosition(100, 100); glutInitWindowSize(320, 320); glutCreateWindow("Hello OpenGL"); init(); glutDisplayFunc(draw); glutIdleFunc(draw); //指定程序空闲时调用函数 // glutReshapeFunc(changeSize); //指定窗口形状变化时的回调函数 glEnable(GL_DEPTH_TEST); glutMainLoop(); return 0; }