Contents

Views 10087 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
315 Develop [ios] Did UIScrollView End Scrolling? hooni 2016.04.19 8317
314 Develop [c] 연산자 우선순위.. ㅋㅋ hooni 2013.04.23 8304
313 Develop [c] 지폰(gphone) 소스.. 수정(암호화) file hooni 2013.04.23 8291
312 Develop [c] 신기한 atoi함수(www.game79.net) hooni 2003.04.23 8283
311 Develop [asp] 기본 문법과 제어문 hooni 2013.04.23 8282
310 Develop [c] 로또(Lotto) 번호 생성기 file hooni 2013.04.23 8279
309 Develop [linux] crond 사용법.. ㅋㅋ hooni 2013.04.23 8270
308 Develop [js] php의 number_format() 함수와 같은.. ㅋㅋ hooni 2013.04.23 8266
307 Develop [js] 한글문서로 된 259가지 자바스크립트 예제파일 file hooni 2013.04.23 8263
306 Develop [linux] 임베디드 리눅스 (embedded linux) file hooni 2013.04.23 8262
305 Develop [pdf] 포인터 문법 정리 (C pointer) file hooni 2013.04.23 8262
304 Develop [c] 게임 AI FSM 테스트 샘플 소스.. 꽤 괜찮은 소스.. file hooni 2013.04.23 8248
Board Pagination Prev 1 ... 40 41 42 43 44 45 46 47 48 49 ... 71 Next
/ 71