From 42b148bb3b8ee85a4738fb4eaed264c99fab9c75 Mon Sep 17 00:00:00 2001 From: Kenneth van Ewijk Date: Thu, 21 Apr 2016 12:27:01 +0200 Subject: [PATCH] Added the best cube (obvious) --- OpenGL1/Main.cpp | 114 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 15 deletions(-) diff --git a/OpenGL1/Main.cpp b/OpenGL1/Main.cpp index 3e928af..aabb9c7 100644 --- a/OpenGL1/Main.cpp +++ b/OpenGL1/Main.cpp @@ -3,7 +3,14 @@ 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(); @@ -21,20 +28,9 @@ void display() 0, 1, 0); glRotatef(rotation, 0, 1, 0); + glRotatef(rotation/2, 0, 0, 1); - 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(); + obj_cube(); glutSwapBuffers(); } @@ -51,18 +47,106 @@ 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"); + glEnable(GL_DEPTH_TEST); glutDisplayFunc(display); glutIdleFunc(idle); glutKeyboardFunc(keyboard); + glutReshapeFunc(resize); glutMainLoop(); return 0; +} + +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