#include <gl/freeglut.h> #include <cstdio> //----------- プロトタイプ宣言 --------------// void display(); void reshape(int w, int h); void timer(int value); void MouseWheel(int wheel_number, int direction, int x, int y); //------------- OpenGLの初期設定 ------------------// void GLUT_INIT() { glutInitDisplayMode(GLUT_RGBA| GLUT_DOUBLE | GLUT_DEPTH); glutInitWindowSize(640,480); glutCreateWindow("freeglut MouseWheel"); } void GLUT_CALL_FUNC() { glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseWheelFunc ( MouseWheel ) ;//ホイールコールバック glutTimerFunc(0,timer,17); } void MY_INIT() { glClearColor(1.0, 1.0, 1.0, 1.0); glEnable(GL_DEPTH_TEST);//ZバッファON } //--------- GLUTの初期設定 -----------// void GLUT_INITs(int *argcp, char **argv) { glutInit(argcp,argv); GLUT_INIT(); GLUT_CALL_FUNC(); MY_INIT(); } //------------- メイン関数 ----------------// int main(int argc, char **argv) { GLUT_INITs(&argc, argv); glutMainLoop(); return 0; } //------------ ここからコールバック関数 ------------------// void display() { static int r = 0; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0,0,1); glPushMatrix(); glRotated(static_cast<double>(r), 0.0, 1.0, 0.0); glutWireRhombicDodecahedron();//菱形12面体 glPopMatrix(); //行列を戻す glColor3f(1,1,1); glutSwapBuffers(); if(++r > 360){r= 0;} } void reshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(30.0, (double)w / (double)h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(3.0, 4.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); } void timer(int t) { glutPostRedisplay(); glutTimerFunc(t,timer,17); //タイマー関数 } void MouseWheel(int wheel_number, int direction, int x, int y) { printf("WheelNumber:%d, direction:%d, at (%d, %d)\n",wheel_number,direction,x,y); }