Contents

Develop
2003.04.23 10:52

[c] OpenGL 마우스 이벤트

Views 10022 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
651 Develop [html] HTML5 튜토리얼 링크 ㅋㅋ hooni 2013.04.23 14038
650 Develop [jsp] RSS(xml) 파싱해서 보여주기 ㅎㅎ file hooni 2013.04.23 14000
649 Develop [c] 다중연결 서버 만들기 #1 - fork() 사용 file hooni 2013.04.23 13942
648 Develop [c++] 자료구조(링크리스트,스택,큐)와 후위 표기 계산기 샘플 ㅋㅋ 4 file hooni 2013.04.23 13891
647 Develop [php] 심플한 게시판 ㅋㅋ 1 file hooni 2013.04.23 13859
646 Develop [js] AngularJS를 소개합니다. file hooni 2014.01.06 13845
645 Develop [iphone] 아이폰 어플 모음 ㅋㅋ secret hooni 2013.04.23 13707
644 Develop [js] 자바스크립트의 클로저 (JavaScript's Closure) hooni 2013.05.15 13670
643 Develop [php] 하루 전 날짜 쉽게 구하기. hooni 2013.12.25 13592
642 Develop [ios] UIButton multi-line iOS7 hooni 2014.01.09 13582
641 Develop [c] 파일입출력 간단한 설명 hooni 2003.04.23 13577
640 Develop [ios] GCD 변수 사용 예제 hooni 2013.10.01 13574
Board Pagination Prev 1 ... 12 13 14 15 16 17 18 19 20 21 ... 71 Next
/ 71