Develop
2003.04.23 10:52
[c] OpenGL 마우스 이벤트
조회 수 8754 댓글 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(); }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
249 | Develop | [ios] UIWebView를 이용한 로컬 HTML 파일 표시 | hooni | 2015.01.02 | 1340 |
248 | System/OS | [linux] CentOS 에 APM 설치하기 | hooni | 2015.01.02 | 1912 |
247 | Develop | [ios] UIView 계층구조 | hooni | 2015.01.03 | 1225 |
246 | Develop | [ios] Thread Loop 내에서 UI 업데이트 방법 | hooni | 2015.01.03 | 925 |
245 | Develop | [ios] Xcode를 사용해서 Static Library 만들기 (시뮬레이터 + 디바이스) | hooni | 2015.01.03 | 3402 |
244 | Develop | [ios] iOS앱의 Xcode 빌드 과정 | hooni | 2015.01.03 | 2397 |
243 | Develop | [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export) | hooni | 2015.01.03 | 991 |
242 | Develop | [ios] binary를 C코드로 변환 | hooni | 2015.01.03 | 1649 |
241 | System/OS | [mac] Mac OS 패키지 매니저, HomeBrew | hooni | 2015.01.03 | 1472 |
240 | System/OS | [mac] 패키지 매니저, MacPort | hooni | 2015.01.03 | 1129 |
239 | Develop | [ios] Xcode의 디버그 모드에서 콜스택 | hooni | 2015.01.03 | 1113 |
238 | Develop | [ios] iOS 앱 아이콘을 만드는 유틸 | hooni | 2015.01.03 | 945 |