== Contents == == Source code == 주석은 차후에 다시 {{{ #include void Line() { glLineWidth(5); glColor3f(0, 0, 0); glBegin(GL_LINES); glVertex2f(-1.0, 1.0); glVertex2f(1.0, -1.0); glEnd(); } void Square() { glColor3f(1, 0, 0); glBegin(GL_LINE_LOOP); glVertex2f(-0.7, 0.7); glVertex2f(-0.7, 0.2); glVertex2f(-0.2, 0.2); glVertex2f(-0.2, 0.7); glEnd(); } void display() { glClearColor(1, 1, 1, 1); glClear(GL_COLOR_BUFFER_BIT); Line(); Square(); glFlush(); } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600, 600); glutInitWindowPosition(200, 200); glutCreateWindow("Homework0_1"); glutDisplayFunc(display); glutMainLoop(); return 0; } }}} {{{ #include #include float speed = 0; void Rec(float locationX, float locationY, float size) { vec2 rec[4] = { { -size + locationX, size + locationY }, { size + locationX, size + locationY }, { size + locationX, -size + locationY }, { -size + locationX, -size + locationY } }; glBegin(GL_QUADS); for (int i = 0; i < 4;i++) glVertex2fv(rec[i]); glEnd(); } void idle() { speed += 0.0005; glutPostRedisplay(); } void display() { glClearColor(0.5, 0.5, 0.5, 0.5); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); mat4 m(1.0); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(matrix_to_float(m)); m *= Translate(speed, 0.0, 0.0); glPushMatrix(); glLoadMatrixf(matrix_to_float(m)); glColor3f(1, 1, 1); Rec(-1.0, 0.2, 0.2); m *= Translate(speed, 0.0, 0.0); glPushMatrix(); glLoadMatrixf(matrix_to_float(m)); glColor3f(0, 0, 0); Rec(-1.0, -0.2, 0.2); glutSwapBuffers(); } int main(int argc, char**argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowPosition(200, 200); glutInitWindowSize(600, 600); glutCreateWindow("Homework2-1"); glutIdleFunc(idle); glutDisplayFunc(display); glutMainLoop(); return 0; } }}} {{{ #include #include #define Round 0.2 #define PI 3.145926 #define radi2theta(x) x*PI/180.0 void cycle(float x, float y, float r, float g, float b) { float dx = 0, dy = 0; glColor3f(r, g, b); glBegin(GL_POLYGON); for (float i = 0; i < 360; i += 0.01) { dx = Round*cos(radi2theta(i)); dy = Round*sin(radi2theta(i)); glVertex2f(x + dx, y + dy); } glEnd(); } void display() { glClearColor(1.0, 1.0, 1.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); cycle(-0.7, 0.7, 1, 0, 0); cycle(-0.25, 0.7, 0, 1, 0); cycle(0.2, 0.7, 0, 0, 1); glFlush(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowSize(600, 600); glutInitWindowPosition(200, 200); glutCreateWindow("Homework0_3"); glutDisplayFunc(display); glutMainLoop(); return 0; } }}}