Contents

Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

조회 수 8754 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
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
번호 분류 제목 글쓴이 날짜 조회 수
249 Develop [ios] UIWebView를 이용한 로컬 HTML 파일 표시 file hooni 2015.01.02 1339
248 System/OS [linux] CentOS 에 APM 설치하기 hooni 2015.01.02 1911
247 Develop [ios] UIView 계층구조 hooni 2015.01.03 1224
246 Develop [ios] Thread Loop 내에서 UI 업데이트 방법 hooni 2015.01.03 923
245 Develop [ios] Xcode를 사용해서 Static Library 만들기 (시뮬레이터 + 디바이스) file hooni 2015.01.03 3400
244 Develop [ios] iOS앱의 Xcode 빌드 과정 file hooni 2015.01.03 2394
243 Develop [ios] APNS에 사용할 인증서 만들기 (KeyChain에 있는 인증서 Export) file hooni 2015.01.03 985
242 Develop [ios] binary를 C코드로 변환 file hooni 2015.01.03 1648
241 System/OS [mac] Mac OS 패키지 매니저, HomeBrew file hooni 2015.01.03 1470
240 System/OS [mac] 패키지 매니저, MacPort hooni 2015.01.03 1129
239 Develop [ios] Xcode의 디버그 모드에서 콜스택 file hooni 2015.01.03 1112
238 Develop [ios] iOS 앱 아이콘을 만드는 유틸 file hooni 2015.01.03 945
Board Pagination Prev 1 ... 73 74 75 76 77 78 79 80 81 82 ... 98 Next
/ 98