1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
#include "main.h"
camera cam = {3, 2, 5, 0, 0, 0, 0, 1, 0};
Cube cube();
Model cubeModel("Model1.txt");
float angle = 0.1;
int speed = 2;
void display() {
glClear(GL_COLOR_BUFFER_BIT );//| GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); // reset the matrix
gluLookAt(cam.pos.x, cam.pos.y, cam.pos.z, cam.lookAt.x,
cam.lookAt.y, cam.lookAt.z,
cam.up.x, cam.up.y, cam.up.z);
glPushMatrix();
glRotatef(angle * speed, 0.0f, 1.0f, 0.0f);
cube.model->draw();
glPopMatrix();
glPopMatrix();
::glTranslatef(2,0,1);
glutSwapBuffers();
speed++;
}
void init() {
glClearColor(1.0, 1.0, 1.0, 1.0);
glColor3f(0.0, 0.0, 0.0);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
cube.model = &cubeModel;
}
void reshape(int w, int h) {
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0, 1.0, -1.0, 1.0, 2.0, 10.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc, char** argv) {
glutInit(&argc, argv);
glutInitWindowSize(500, 500);
glutInitDisplayMode(GLUT_DOUBLE);
glutCreateWindow("Cube");
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
init();
glutMainLoop();
}
|