Contents

Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

조회 수 8750 댓글 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
번호 분류 제목 글쓴이 날짜 조회 수
417 Develop [c] 학생명단 관리 프로그램 소스 ㅋㅋ 1 file hooni 2003.04.23 7793
416 Develop [c] 학교 건물 최단거리 찾는 웹 연동 프로그램 file hooni 2013.04.23 6812
415 Develop [c] 하노이탑 - 재귀함수 hooni 2003.04.23 9167
414 Develop [c] 플러드 필링 (flood filling) 알고리즘.. file hooni 2013.04.23 7327
413 Develop [c] 프로세스간의 통신(파이프) hooni 2003.04.23 6905
412 Develop [c] 프로세스 정보 출력하기.. file hooni 2003.04.23 6932
411 Develop [c] 프로세스 검사하기 hooni 2013.04.23 8037
410 Develop [c] 프로그램 코드(c/c++)를 html 파일로 변환 file hooni 2013.04.23 7685
409 Develop [c] 프로그래밍의 전반적인 설명 ppt file hooni 2003.04.23 7697
408 Develop [c] 프로그래밍 과제..(colprint) file hooni 2003.04.23 6765
407 Develop [c] 프로그래밍 ppt, 스킬업 (비트 수업자료) file hooni 2003.04.23 8211
406 Develop [c] 포인터와 함수포인터에 대해.. hooni 2003.04.23 8037
Board Pagination Prev 1 ... 59 60 61 62 63 64 65 66 67 68 ... 98 Next
/ 98