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
729 Develop [ios] How to set up clang formatter hooni 2015.09.17 1364
728 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1388
727 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1402
726 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 1409
725 Develop [android] 레이아웃 사이즈 변경 (동적; programmatically) hooni 2016.11.07 1486
724 Develop [ios] binary를 C코드로 변환 file hooni 2015.01.03 1531
723 Develop [ios] Pod 특정 버전 설치하고 사용하기 hooni 2022.05.28 1543
722 Develop [python] 파라미터 앞에 *, ** 의 의미? (*args, **kwargs) hooni 2019.11.22 1555
721 Develop [ios] 스크린 캡쳐 (전원버튼 + 홈버튼) 호출 알아내기 hooni 2014.11.19 1556
720 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 1591
719 Develop [ios] Swift 4 Singleton inheritance hooni 2018.10.31 1597
718 Develop [ios] Requesting Location Permissions in iOS file hooni 2018.08.18 1607
717 Develop [ios] How To Use UIScrollView to Scroll and Zoom Content (Using Objective-C) file hooni 2016.03.23 1621
716 Develop [ios] Locale Identifiers file hooni 2018.11.29 1627
715 Develop ZBar 라이브러리를 이용한 바코드 스캔 앱 개발하기 file hooni 2015.01.01 1629
714 Develop [web] 더 빠른 웹을 위한 프로토콜, 'HTTP/2' file hooni 2014.10.20 1641
Board Pagination Prev 1 ... 6 7 8 9 10 ... 53 Next
/ 53