Develop
2003.04.23 10:52
[c] OpenGL 마우스 이벤트
Views 8753 Comment 0
OpenGL 마우스 이벤트 처리 예제
#include<stdio.h> #include<stdlib.h> #include<GL/glut.h> short rightbuttonpressed = 0; double r=1.0, g=0.0, b=0.0; void display(void){ glClearColor(r, g, b, 1.0); glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); glBegin(GL_LINES); glVertex2f(-1.0, 0.0); glVertex2f(0.0, 0.0); glEnd(); glFlush(); } void keyboard(unsigned char key, int x, int y){ switch(key){ case 'r' : r=1.0; g=b=0.0; glutPostRedisplay(); break; case 'g' : g=1.0; r=b=0.0; glutPostRedisplay(); break; case 'b' : b=1.0; r=g=0.0; glutPostRedisplay(); break; case 'q': exit(0); } } void mousepress(int button, int state, int x, int y){ if((button==GLUT_LEFT_BUTTON) && (state==GLUT_DOWN)) printf("*** The left mouse button was pressed at (%d, %d)n", x, y); else if((button==GLUT_RIGHT_BUTTON) && (state==GLUT_DOWN)) rightbuttonpressed = 1; else if((button==GLUT_RIGHT_BUTTON) && (state==GLUT_UP)) rightbuttonpressed = 0; } void mousemove(int x, int y){ if(rightbuttonpressed) printf("$$$ The right mouse button is now at (%d, %d).n",x,y); } void reshape(int width, int height){ printf("### The new windows size is %dx%d.n",width, height); } void RegisterCallback(void){ glutDisplayFunc(display); glutKeyboardFunc(keyboard); glutMouseFunc(mousepress); glutMotionFunc(mousemove); glutReshapeFunc(reshape); } void main(int argc, char **argv){ glutInit(&argc, argv); glutInitDisplayMode(GLUT_RGBA); glutInitWindowSize(500,500); glutCreateWindow("My Second OpenGL Code"); RegisterCallback(); glutMainLoop(); }
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
841 | Develop | 프로그램 문서 관리 (Doxygen) | hooni | 2013.04.23 | 16434 |
840 | Develop | 프로그래밍에서 foo, bar 함수의 유래 | hooni | 2013.06.25 | 21461 |
839 | Develop | 프로그래밍 소스 관련 사이트.. | hooni | 2013.04.23 | 16523 |
838 | Develop | 페이팔에서 돈 찾기 (Paypal withdraw) | hooni | 2014.02.20 | 11467 |
837 | Develop | 캘리포니아 운전면허 족보 | hooni | 2017.06.12 | 872 |
836 | Develop | 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..) | hooni | 2013.04.23 | 10366 |
835 | Develop | 참고하고 지울 자료.. 집에서 바야지.. ㅋㅋ | hooni | 2013.04.23 | 12168 |
834 | Develop | 정리할 자료. | hooni | 2015.07.02 | 813 |
833 | Develop | 자주 쓰는 Docker 명령어 alias | hooni | 2020.01.10 | 271231 |
832 | Develop | 이어서 작업할 내용~ | hooni | 2013.11.21 | 0 |
831 | Develop | 웹페이지 성능 테스트 툴 설명 | hooni | 2013.04.23 | 27515 |
830 | Develop | 알고리즘 성능분석 | hooni | 2014.06.24 | 3093 |