Contents

Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

조회 수 8748 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
337 Develop [c] 단기과정[01/17] 후위연산 스택 계산기.. file hooni 2003.04.23 7244
336 Develop [html] 메타태그 사용예.. 은지나 바라~ hooni 2003.04.23 7243
335 Develop [jsp] 초간단한 include 구문 예제.. file hooni 2013.04.23 7236
334 Develop [js] 네이버에서 그림 퍼올 때.. URL Encoding 관련ㅋㅋ hooni 2013.04.23 7233
333 Develop [ios][swift] 초간단 카달로그 앱 (Catalog App) file hooni 2016.06.27 7227
332 Develop [c] 문자열 라이브러리 최신버전 file hooni 2003.04.23 7213
331 Develop [c] 네트워크 관련 프로그래밍 (포트스캔 탐지 샘플) file hooni 2013.04.23 7209
330 Develop [c] 시스템 보안 과제.. 시간(amc time) 변경 file hooni 2013.04.23 7202
329 Develop [c] 함수 목록과 예제 소스 파일 file hooni 2013.04.23 7200
328 Develop [c++] template 사용예 hooni 2003.04.23 7198
327 Develop [c] 시스템공학 레포트 (pass1, pass2) file hooni 2003.04.23 7193
326 Develop [c] 연산자 우선순위.. ㅋㅋ hooni 2013.04.23 7189
Board Pagination Prev 1 ... 38 39 40 41 42 43 44 45 46 47 ... 71 Next
/ 71