Added the best cube (obvious)

This commit is contained in:
2016-04-21 12:27:01 +02:00
parent fef2e0ed74
commit 42b148bb3b
+99 -15
View File
@@ -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();
}