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 62 63 64
|
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
float yup = 0.0f;
float ydown = 0.0f;
void KeyUp(int key, int x, int y){
ydown = ydown + 0.5f;
}
void cube(void){
glRotatef(ydown,0.0f,0.0f,0.0f);
glColor4f(0.0, 1.0, 0.0, 0.2);
glutSolidCube(1);
glColor4f(0.0, 1.0, 0.0, 0.5);
}
void init(void){
glClearDepth(1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
}
void display(void){
glClearColor(1.0f,0.0f,0.0f,1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glLoadIdentity();
cube();
glutSwapBuffers();
}
int main(int argc, char **argv) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(320,320);
glutCreateWindow("Dimension");
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glLoadIdentity();
glutSpecialFunc(KeyUp);
glutMainLoop();
return 0;
}
|