Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

Views 8731 Votes 0 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
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();
}


?

List of Articles
No. Category Subject Author Date Views
965 System/OS [linux] CentOS 에 APM 설치하기 hooni 2015.01.02 1688
964 Develop [php] mysql_ 과 mysqli_ 의 차이 hooni 2017.12.01 1691
963 Develop [swift] UIView에서 subview 찾기 hooni 2022.12.09 1742
962 System/OS CentOS 에서 Cacti 설치하기 hooni 2015.01.02 1762
961 Develop [iOS] 시뮬레이터에 푸시 알림을 보내는 방법 file hooni 2021.10.13 1768
960 Develop [iOS] Xcode 불필요한 캐시 삭제하기 hooni 2021.10.12 1780
959 Develop [ios] Xcode cannot run using the selected device hooni 2014.08.14 1785
958 Etc 인증서 *.p12 파일을 *.pem 파일로 변환 hooni 2015.04.30 1804
957 System/OS [mac] 맥에서 기본 실행 앱 변경하기 file hooni 2018.03.02 1804
956 Database SQL JOIN 정리 (Inner Join & Outer Join) file hooni 2019.11.22 1832
955 Develop [ios] Objective-C 에서 자주 사용하는 수학 함수와 유용한 Define hooni 2014.08.08 1856
954 Develop [ios] 카메라 사용 권한 확인해서 분기하는 방법 hooni 2015.02.26 1867
953 Develop [php][laravel] 초간단 MacOS에서 Laravel 개발 환경 구축 hooni 2017.12.15 1869
952 Develop [android] 가속도 센서를 이용한 흔듦(Shake) 감지 file hooni 2014.11.04 1898
951 System/OS 맥 OS X 에서 스크린 화면 캡쳐 단축키 (Mac Print Screen) hooni 2015.07.21 1898
950 Develop [ios] 웹뷰 history.back() ㅋㄷ file hooni 2016.06.27 1899
Board Pagination Prev 1 ... 12 13 14 15 16 ... 74 Next
/ 74