조회 수 9093 추천 수 0 댓글 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();
}

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
181 Develop How to Test SMTP AUTH using Telnet hooni 2018.04.05 1585
180 System/OS 네트워크 용어 정리 file hooni 2022.11.20 1583
179 Develop What is difference between Get, Post, Put and Delete? hooni 2018.02.28 1563
178 Develop [swift] popToRoot 모달뷰, 네비게이션컨트롤러 한꺼번에 닫기 file hooni 2021.01.29 1556
177 System/OS SSH Passwordless Login Using SSH Keygen in 5 Easy Steps file hooni 2019.11.22 1533
176 System/OS How to Install and Use wget on Mac file hooni 2020.09.03 1531
175 Etc 아이폰의 터치스크린 정확도 file hooni 2015.04.01 1513
174 System/OS RPA란? 어디에 어떻게 쓰이고 누가 만드나? file hooni 2020.01.28 1512
173 Develop [ios] Swift 4 String, Date, DateFormatter 예제 hooni 2018.10.18 1507
172 System/OS Configure Postfix to Use Gmail SMTP on Ubuntu 18.04 file hooni 2020.02.07 1489
171 Etc 모바일 프로그래머가 갖추어야 할 필수 역량 file hooni 2017.02.16 1479
170 Develop [ios] How to set up clang formatter hooni 2015.09.17 1468
169 Etc ISMS 인증기준 – 정보보호대책 (시스템개발보안) file hooni 2016.12.01 1458
168 Develop [android] 간단한 SQLIite 예제 hooni 2017.06.14 1457
167 System/OS [mac] Mac OS 패키지 매니저, HomeBrew file hooni 2015.01.03 1455
166 Develop [php] 한글 문자열 자르기 (utf-8) hooni 2015.11.10 1454
Board Pagination Prev 1 ... 61 62 63 64 65 ... 74 Next
/ 74