본문 바로가기
Language/C++ & openGL

OpenGL 키보드 콜백 회전 회오리

by javapp 자바앱 2020. 4. 25.
728x90

 

#include <GL/glut.h>

#include <GL/gl.h>

#include <GL/glu.h>

#include <stdio.h>

#include <windows.h>

#include <math.h>

 

using namespace std;

 

int zRotate = 0;

 

void MyDisplay()

{

        glClear(GL_COLOR_BUFFER_BIT);

 

 

        glLoadIdentity();        //이전 상태 초기화 후 변환

        glRotatef(zRotate, 0.0, 0.0, 1.0); //z를 중심을 회전

 

        glutSolidTeapot(0.5);

 

 

        glFlush();

}

void MyKeyboard(unsigned char KeyPressed, int X, int Y)

{

        switch (KeyPressed) {

        case 'Q':case'q':

                 exit(0); break;

        case 'Z':

                 zRotate += 10;

                 break;

        case 'z':

                 zRotate -= 10;

                 break;

        default:

                 break;

        }

        glutPostRedisplay();//다시 그려주기

}

 

int main(int argc, char* argv[])

{

        glutInit_ATEXIT_HACK(&argc, argv);

        glutInitWindowSize(500, 500); // 윈도우 크기

        glutInitWindowPosition(500, 100); // (500,100) 위치에 윈도우

        glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);

        glutCreateWindow_ATEXIT_HACK("OpenGL Example");

 

 

        glutKeyboardFunc(MyKeyboard); // 키보드 콜백 추가

 

 

        glutDisplayFunc(MyDisplay);

        glutMainLoop();

        return 0;

}

댓글