Contents

Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

조회 수 8753 댓글 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 [c++] p.58 연습문제 2번 hooni 2003.04.23 16349
248 System/OS [windows] 원격 데스크탑(터미널 서비스) 포트 변경 hooni 2013.04.23 16357
247 System/OS [linux] 패킷 스니퍼링 hooni 2003.04.23 16378
246 Etc [php] 싸이월드 이미지 외부 링크 하기(php) hooni 2013.04.23 16412
245 System/OS [linux] 콘솔/Xwindow 에서 PC스피커 소리 없애기 hooni 2003.04.23 16416
244 Develop 프로그램 문서 관리 (Doxygen) hooni 2013.04.23 16434
243 Etc 개발자가 알아야할 10가지 보안팁으로 코드 보호하기 hooni 2013.04.23 16447
242 System/OS [linux] 메타(기호)문자의 의미와 사용 hooni 2003.04.23 16463
241 Develop [js] 파이어폭스(Firefox;F/F)에서 outerHTML 작동하도록 만든 메소드 hooni 2013.04.23 16465
240 Develop 프로그래밍 소스 관련 사이트.. hooni 2013.04.23 16523
239 System/OS [linux] 네트워크 커널 설정.. hooni 2003.04.23 16544
238 Develop [ios] 푸시알림(APNS)에 대한 php 라이브러리 ㅋㅋ hooni 2013.04.23 16660
Board Pagination Prev 1 ... 73 74 75 76 77 78 79 80 81 82 ... 98 Next
/ 98