Contents

조회 수 9070 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
#include<stdlib.h>
#include<GL/glut.h>

GLfloat vertices[][2] = {
        {-0.1, 0.1}, {-0.1, -0.1}, {0.1, -0.1}, {0.1, 0.1}
};

int R=120, G=0, B=120;
double rec_size=1;

void drawSquare(){
        int i;
        glColor3ub( R, G, B );
        glBegin(GL_POLYGON);
                for(i=0; i<4; i++) glVertex3fv(vertices[i]);
        glEnd();
}

void display(void){
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        glScalef(rec_size, rec_size, rec_size);
        drawSquare();

        glFlush();
        glutSwapBuffers();
}

void mouse(int btn, int state, int x, int y){
        if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN && rec_size<32){
                R+=20;        B-=20;
                rec_size *= 2;
        }
        if(btn==GLUT_RIGHT_BUTTON && state==GLUT_DOWN && rec_size>0.1){
                R-=20;        B+=20;
                rec_size /= 2;
        }
        
        glutPostRedisplay();
}

void myReshape(int w, int h){
        glViewport(0, 0, w, h);
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();

        glOrtho(-2.0, 2.0, -2.0 * (GLfloat)h / (GLfloat)w, 2.0 * (GLfloat)h / (GLfloat)w, -10.0, 10.0);
        glMatrixMode(GL_MODELVIEW);
}

void main(int argc, char **argv){
        glutInit(&argc, argv);

        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
        glutInitWindowSize(500, 500);
        glutCreateWindow("Square!!");

        glutReshapeFunc(myReshape);
        glutDisplayFunc(display);
        glutMouseFunc(mouse);

        glutMainLoop();
}


?

  1. [c] 문자열 자르는 함수(strtok) 예제

  2. SVN 명령어 (SVN command)

  3. 참고하고 지울 자료.. 집에서 바야지.. ㅋㅋ

  4. [mysql] DB->Text, Text->DB 변환

  5. [oracle] SQL문 실행 방법 3가지

  6. [ios] GCD 변수 사용 예제

  7. [linux] 데스크탑환경(GNOME/KDE) 바꾸기..

  8. [ppt] Magic URLs & Hidden Form Fields 에 대해.. ㅋㅋ

  9. [c++] 기초강좌 #03(함수의 매개변수 전달)

  10. [linux] /etc/fstab 설정 방법.. ㅋㅋ

  11. [c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ

  12. [linux] 쉘 스크립트 (Shell Script)

Board Pagination Prev 1 ... 28 29 30 31 32 33 34 35 36 37 ... 98 Next
/ 98