@@ -15,20 +15,19 @@ struct Vertex {
1515};
1616
1717struct Face {
18- Vertex a, b, c;
18+ unsigned int a, b, c;
19+ };
20+
21+ static std::vector<Vertex> vertices = {
22+ {-0 .5f , 0 .5f , 0 .0f },
23+ {-0 .5f , -0 .5f , 0 .0f },
24+ {0 .5f , -0 .5f , 0 .0f },
25+ {0 .5f , 0 .5f , 0 .0f },
1926};
2027
2128static std::vector<Face> faces = {
22- {
23- {-0 .5f , 0 .5f , 0 .0f },
24- {-0 .5f , -0 .5f , 0 .0f },
25- {0 .5f , -0 .5f , 0 .0f },
26- },
27- {
28- {-0 .5f , 0 .5f , 0 .0f },
29- {0 .5f , -0 .5f , 0 .0f },
30- {0 .5f , 0 .5f , 0 .0f },
31- },
29+ {0 , 1 , 2 },
30+ {0 , 2 , 3 },
3231};
3332
3433/* static void load_obj(std::string path) { */
@@ -56,9 +55,12 @@ static void render() {
5655 glBegin (GL_TRIANGLES);
5756
5857 for (auto const &face : faces) {
59- glVertex3f (face.a .x , face.a .y , face.a .z );
60- glVertex3f (face.b .x , face.b .y , face.b .z );
61- glVertex3f (face.c .x , face.c .y , face.c .z );
58+ Vertex a = vertices[face.a ];
59+ Vertex b = vertices[face.b ];
60+ Vertex c = vertices[face.c ];
61+ glVertex3f (a.x , a.y , a.z );
62+ glVertex3f (b.x , b.y , b.z );
63+ glVertex3f (c.x , c.y , c.z );
6264 }
6365
6466 CHECK_GL (glEnd ());
@@ -81,7 +83,7 @@ static void mouse_button_callback
8183 float x = (float )(2 * xpos / width - 1 );
8284 float y = (float )(2 * (height - ypos) / height - 1 );
8385
84- faces [0 ]. a = Vertex{x, y, 0 };
86+ vertices [0 ] = Vertex{x, y, 0 };
8587 }
8688}
8789
0 commit comments