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
565 Develop [js] 객체 머지.. hooni 2013.12.17 9911
564 Develop [c++] mfc 윈도우에서 ODBC 사용하여 MDB파일 읽기.. ㅋㅋ file hooni 2013.04.23 9920
563 Develop [c] 이진트리(binary tree)의 운행.. hooni 2003.04.23 9929
562 Develop [c++] 중복실행 방지(Mutex;뮤텍스 ) 샘플 소스.. ㅋㅋ file hooni 2013.04.23 9929
561 System/OS [linux] 간단한 find 명령어 설명(업데이트 해야 함) hooni 2013.04.23 9943
560 Develop [c] Unix Domain Socket 을 이용한 IPC hooni 2013.04.23 9953
559 System/OS [linux] man 명령어 뽀개기.. hooni 2003.04.23 9955
558 Develop [c] 컴파일러 DFA구현^^ 입력 받아 실행 4 file hooni 2003.04.23 9976
557 Develop [java] 채팅창 처럼.. swing.. file hooni 2013.04.23 9998
» Develop [c] OpenGL 마우스 이벤트 hooni 2003.04.23 10022
555 Develop [c][java] 주사선 채우기 알고리즘(scan line filling algorithm) 구현 file hooni 2013.04.23 10026
554 Develop [c][cpp] mfc, win32api, 예제 소스 대박 모음~ file hooni 2013.04.23 10026
Board Pagination Prev 1 ... 47 48 49 50 51 52 53 54 55 56 ... 99 Next
/ 99