Contents

Views 9084 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
1173 Develop [ios] 아이폰용 앱 오픈 소스들 hooni 2013.04.23 468095
1172 Develop 자주 쓰는 Docker 명령어 alias hooni 2020.01.10 270715
1171 Develop [ios] 언어, 지역, 국가 설정 가져오기 hooni 2014.05.12 270555
1170 Etc 베지어 곡선 (Bezier curve) file hooni 2013.08.18 222061
1169 Develop [ios] Start developing your navigation app for CarPlay without enrollment file hooni 2020.02.22 125159
1168 Develop [android] 만화 어플 소스코드 file hooni 2013.04.23 92906
1167 Develop 레고 마인드스톰 NXT 수도쿠, 큐브 소스코드.. 20 file hooni 2013.04.23 81519
1166 Algorithm 디피헬만(Diffie-Hellman) 초간단 개념.. hooni 2013.04.23 81069
1165 Develop [c#] Hashtable <-> Json (dll 포함) file hooni 2013.04.23 80713
1164 Develop [C#] MD5, SHA1 해시 & 인코딩 hooni 2013.04.23 77940
1163 Develop [android] 점심 해결 앱 소스 코드 ㅋㅋ file hooni 2013.04.23 76465
1162 PPT [android] XML파서(XMLParser)의 종류와 성능 비교에 대한 발표 자료 file hooni 2013.04.23 75698
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98