From 4c3b95678702ccb41e7ba720579a35fff8b6550b Mon Sep 17 00:00:00 2001 From: hodasemi Date: Fri, 31 May 2019 14:42:02 +0200 Subject: [PATCH] Fix cube rendering --- exercise3/src/cube_system.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/exercise3/src/cube_system.cpp b/exercise3/src/cube_system.cpp index 280bd65..610fb86 100644 --- a/exercise3/src/cube_system.cpp +++ b/exercise3/src/cube_system.cpp @@ -80,6 +80,7 @@ void render_cube_face( const double p2[3], const double p3[3]) { + glColor3dv(color); glVertex3dv(p0); glColor3dv(color); glVertex3dv(p1); @@ -91,7 +92,6 @@ void render_cube_face( glVertex3dv(p3); glColor3dv(color); glVertex3dv(p0); - glColor3dv(color); } // Render one single cube @@ -125,14 +125,14 @@ void cube_system::render_cube() */ const double vertices[8][3] = { - {-1.0, -1.0, 1.0}, - { 1.0, -1.0, 1.0}, - { 1.0, 1.0, 1.0}, - {-1.0, 1.0, 1.0}, - {-1.0, -1.0, -1.0}, - { 1.0, -1.0, -1.0}, - { 1.0, 1.0, -1.0}, - {-1.0, 1.0, -1.0} + {-1.0, -1.0, 1.0}, // 1 + { 1.0, -1.0, 1.0}, // 2 + { 1.0, 1.0, 1.0}, // 3 + {-1.0, 1.0, 1.0}, // 4 + {-1.0, -1.0, -1.0}, // 5 + { 1.0, -1.0, -1.0}, // 6 + { 1.0, 1.0, -1.0}, // 7 + {-1.0, 1.0, -1.0} // 8 }; const double colors[6][3] = { @@ -144,12 +144,14 @@ void cube_system::render_cube() {0.0, 1.0, 1.0}, }; + glBegin(GL_TRIANGLES); render_cube_face(colors[0], vertices[0], vertices[1], vertices[2], vertices[3]); render_cube_face(colors[1], vertices[1], vertices[5], vertices[6], vertices[2]); render_cube_face(colors[2], vertices[5], vertices[4], vertices[7], vertices[6]); render_cube_face(colors[3], vertices[4], vertices[0], vertices[3], vertices[7]); render_cube_face(colors[4], vertices[4], vertices[5], vertices[1], vertices[0]); render_cube_face(colors[5], vertices[6], vertices[7], vertices[3], vertices[2]); + glEnd(); }