Develop
2003.04.23 10:52
[c] OpenGL 마우스 이벤트
조회 수 10025 댓글 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(); }
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
949 | System/OS | [linux] 최소한의 커널 설정(커널설치 전체과정) | hooni | 2003.04.23 | 18307 |
948 | Develop |
[c] 팩토리얼 서버/클라이언트..
![]() |
hooni | 2003.04.23 | 18270 |
947 | Develop |
[java] 입출력 스트림 1부 (문자)
![]() |
hooni | 2013.04.23 | 18155 |
946 | Develop | [c] ICMP 패킷을 이용한 장난감 | hooni | 2003.04.23 | 18127 |
945 | Develop | [c++] 문자열 뒤집기(문자열 거꾸로 출력) | hooni | 2013.04.23 | 18081 |
944 | Algorithm | [security] RSA 암호화 설명과 예.. | hooni | 2013.04.23 | 18062 |
943 | PPT |
[doc] 논문.. VoIP 관련.. ㅋㅋ
![]() |
hooni | 2013.04.23 | 18045 |
942 | System/OS | [switch] 시스코 스위치 관리자 암호 초기화 방법 | hooni | 2013.04.23 | 18030 |
941 | Develop | [unix] 쉘 스크립트 예제 모음 | hooni | 2003.04.23 | 17979 |
940 | PPT |
[ppt] 웜프레임워크 발표 양식(국보연)
![]() |
hooni | 2013.04.23 | 17963 |
939 | Develop |
[winmobile] 윈도우 모바일 간단한 테스트 코드 ㅋㅋ
![]() |
hooni | 2013.04.23 | 17957 |
938 | Develop |
[ios] PHP로 APNS 프로바이더~
![]() |
hooni | 2013.06.27 | 17945 |