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 Develop [php] 초간단 웹 카운터.. file hooni 2003.04.23 7063
964 Develop [c] 프로그래밍 과제..(colprint) file hooni 2003.04.23 6745
963 Develop [java] 스윙(swing) 인터페이스 이용해서 만든 구구단.. ㅋㅋ file hooni 2003.04.23 6682
962 Develop [c++] Window API(MFC) 오목 게임 file hooni 2003.04.23 10275
961 System/OS [sql] 내 방명록 답글 찾는 쿼리문.. (JOIN 구문) hooni 2003.04.23 12845
960 System/OS [sql] alter table 쿼리 예제 hooni 2003.04.23 12459
959 Algorithm [algorithm] Greedy (탐욕 기법) hooni 2003.04.23 15108
958 Develop [js] 가운데 새창 뜨는 함수와 이벤트 hooni 2003.04.23 6722
957 System/OS [dos] 노트북 백업 스크립트 xcopy 명령 예제 hooni 2003.04.23 40805
956 Database [mysql] error while loading shared libraries: libmysqlclient.so.10: hooni 2003.04.23 12663
955 System/OS [linux] 터미널에서 문자 깨질 때 설정 ㅋㅋ hooni 2003.04.23 13914
954 System/OS [linux] root도 삭제하지 못하는 파일 속성 hooni 2003.04.23 12412
953 Develop [php] 메모장 - 웅지학원 ([c] mysql 백업프로그램 포함) file hooni 2003.04.23 6993
952 Develop [c] 문자열 컨트롤 함수로 만든 프로그램들.. file hooni 2003.04.23 6786
951 Develop [js] 주민번호 생성기.. file hooni 2003.04.23 8142
950 Develop [c] 문자열 라이브러리 최신버전 file hooni 2003.04.23 7188
Board Pagination Prev 1 ... 12 13 14 15 16 ... 74 Next
/ 74