Contents

Views 9082 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
#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();
}


?

List of Articles
No. Category Subject Author Date Views
177 System/OS SSH Passwordless Login Using SSH Keygen in 5 Easy Steps file hooni 2019.11.22 1513
176 Etc 아이폰의 터치스크린 정확도 file hooni 2015.04.01 1496
175 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1491
174 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 1480
173 System/OS RPA란? 어디에 어떻게 쓰이고 누가 만드나? file hooni 2020.01.28 1478
172 Develop [ios] How to set up clang formatter hooni 2015.09.17 1453
171 System/OS Configure Postfix to Use Gmail SMTP on Ubuntu 18.04 file hooni 2020.02.07 1449
170 Etc 모바일 프로그래머가 갖추어야 할 필수 역량 file hooni 2017.02.16 1431
169 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 1429
168 System/OS [mac] Mac OS 패키지 매니저, HomeBrew file hooni 2015.01.03 1429
167 Etc ISMS 인증기준 – 정보보호대책 (시스템개발보안) file hooni 2016.12.01 1424
166 Develop [php] 한글 문자열 자르기 (utf-8) hooni 2015.11.10 1422
Board Pagination Prev 1 ... 79 80 81 82 83 84 85 86 87 88 ... 98 Next
/ 98