diff --git a/OpenGL1/Main.cpp b/OpenGL1/Main.cpp index 29ba40e..8ac4d7a 100644 --- a/OpenGL1/Main.cpp +++ b/OpenGL1/Main.cpp @@ -2,8 +2,15 @@ #include using namespace std; + +/* Prototypes */ +void obj_flag(void); +void obj_cube(void); void obj_cube2(void); + float rotation = 0; +int width = 800; +int height = 600; void display() { @@ -12,7 +19,7 @@ void display() glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluPerspective(90, 1, 0.5f, 20.0f); + gluPerspective(90, (float)width/height, 0.5f, 20.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -22,7 +29,8 @@ void display() glRotatef(rotation, 0, 1, 0); glRotatef(rotation/2, 0, 0, 1); - obj_cube2(); + + obj_cube(); glutSwapBuffers(); } @@ -39,10 +47,16 @@ void keyboard(unsigned char key, int x, int y) exit(0); } +void resize(int w, int h) +{ + width = w; + height = w; +} + int main(int argc, char *argv[]) { glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH); - glutInitWindowSize(800, 600); + glutInitWindowSize(width, height); glutInit(&argc, argv); glutCreateWindow("Hello World"); @@ -51,6 +65,7 @@ int main(int argc, char *argv[]) glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboard); + glutReshapeFunc(resize); glutMainLoop(); return 0; @@ -143,5 +158,84 @@ void obj_cube2() glVertex3f(0, 0, 1); glVertex3f(1, 0, 1); glEnd(); +} +void obj_cube() +{ + //Side 1 : Green + glBegin(GL_QUADS); + glColor3f(0.0f, 1.0f, 0.0f); + glVertex3f(-1, -1, -1); + glVertex3f(-1, 1, -1); + glColor3f(0.5f, 1.0f, 0.5f); + glVertex3f(1, 1, -1); + glVertex3f(1, -1, -1); + glEnd(); + + //Side 2 : Red + glBegin(GL_QUADS); + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(-1, -1, 1); + glVertex3f(-1, 1, 1); + glColor3f(1.0f, 0.5f, 0.5f); + glVertex3f(1, 1, 1); + glVertex3f(1, -1, 1); + glEnd(); + + //Side 3 : Blue + glBegin(GL_QUADS); + glColor3f(0.0f, 0.0f, 1.0f); + glVertex3f(-1, -1, -1); + glVertex3f(-1, -1, 1); + glColor3f(0.5f, 0.5f, 1.0f); + glVertex3f(-1, 1, 1); + glVertex3f(-1, 1, -1); + glEnd(); + + //Side 4 : Yellow + glBegin(GL_QUADS); + glColor3f(1.0f, 1.0f, 0.0f); + glVertex3f(1, -1, -1); + glVertex3f(1, -1, 1); + glColor3f(1.0f, 1.0f, 0.5f); + glVertex3f(1, 1, 1); + glVertex3f(1, 1, -1); + glEnd(); + + //Side 5 : Purple + glBegin(GL_QUADS); + glColor3f(1.0f, 0.0f, 1.0f); + glVertex3f(-1, -1, -1); + glVertex3f(-1, -1, 1); + glColor3f(1.0f, 0.5f, 1.0f); + glVertex3f(1, -1, 1); + glVertex3f(1, -1, -1); + glEnd(); + + //Side 6 : Light blue + glBegin(GL_QUADS); + glColor3f(0.0f, 1.0f, 1.0f); + glVertex3f(-1, 1, -1); + glVertex3f(-1, 1, 1); + glColor3f(0.5f, 1.0f, 1.0f); + glVertex3f(1, 1, 1); + glVertex3f(1, 1, -1); + glEnd(); +} + +void obj_flag() +{ + glBegin(GL_TRIANGLES); + glColor3f(1.0f, 0.7f, 1.0f); + glVertex3f(0, 0, 0); + glVertex3f(0, 1, 0); + glVertex3f(1, 1, 0); + glEnd(); + + glBegin(GL_TRIANGLES); + glColor3f(0.1, 1, 0.1); + glVertex3f(0, 0, 0); + glVertex3f(1, 1, 0); + glVertex3f(1, 0, 0); + glEnd(); } \ No newline at end of file