diff --git a/Userland/Demos/GLTeapot/Common.h b/Userland/Demos/GLTeapot/Common.h index feee346014..a66734d952 100644 --- a/Userland/Demos/GLTeapot/Common.h +++ b/Userland/Demos/GLTeapot/Common.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jesse Buhagiar + * Copyright (c) 2021, Mathieu Gaillard * * SPDX-License-Identifier: BSD-2-Clause */ @@ -17,7 +18,7 @@ struct Vertex { // A triangle defines a single "face" of a mesh struct Triangle { - Vertex a; - Vertex b; - Vertex c; + GLuint a; + GLuint b; + GLuint c; }; diff --git a/Userland/Demos/GLTeapot/Mesh.cpp b/Userland/Demos/GLTeapot/Mesh.cpp index 89329186a4..3befe47ede 100644 --- a/Userland/Demos/GLTeapot/Mesh.cpp +++ b/Userland/Demos/GLTeapot/Mesh.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jesse Buhagiar + * Copyright (c) 2021, Mathieu Gaillard * * SPDX-License-Identifier: BSD-2-Clause */ @@ -20,6 +21,12 @@ const Color colors[] { Color::Yellow, }; +Mesh::Mesh(Vector vertices, Vector triangles) + : m_vertex_list(move(vertices)) + , m_triangle_list(move(triangles)) +{ +} + void Mesh::draw() { u32 color_index = 0; @@ -31,9 +38,23 @@ void Mesh::draw() glBegin(GL_TRIANGLES); glColor4ub(cur_color.red(), cur_color.green(), cur_color.blue(), 255); - glVertex3f(triangle.a.x, triangle.a.y, triangle.a.z); // Vertex 1 - glVertex3f(triangle.b.x, triangle.b.y, triangle.b.z); // Vertex 2 - glVertex3f(triangle.c.x, triangle.c.y, triangle.c.z); // Vertex 3 + // Vertex 1 + glVertex3f( + m_vertex_list.at(triangle.a).x, + m_vertex_list.at(triangle.a).y, + m_vertex_list.at(triangle.a).z); + + // Vertex 2 + glVertex3f( + m_vertex_list.at(triangle.b).x, + m_vertex_list.at(triangle.b).y, + m_vertex_list.at(triangle.b).z); + + // Vertex 3 + glVertex3f( + m_vertex_list.at(triangle.c).x, + m_vertex_list.at(triangle.c).y, + m_vertex_list.at(triangle.c).z); glEnd(); diff --git a/Userland/Demos/GLTeapot/Mesh.h b/Userland/Demos/GLTeapot/Mesh.h index f0e2808f08..7f979cff0a 100644 --- a/Userland/Demos/GLTeapot/Mesh.h +++ b/Userland/Demos/GLTeapot/Mesh.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jesse Buhagiar + * Copyright (c) 2021, Mathieu Gaillard * * SPDX-License-Identifier: BSD-2-Clause */ @@ -11,19 +12,19 @@ #include "Common.h" -// NOTE: We don't support indexed class Mesh : public RefCounted { public: Mesh() = delete; - Mesh(const Vector& triangles) - : m_triangle_list(triangles) - { - } - void draw(); + Mesh(Vector vertices, Vector triangles); + + size_t vertex_count() const { return m_vertex_list.size(); } size_t triangle_count() const { return m_triangle_list.size(); } + void draw(); + private: + Vector m_vertex_list; Vector m_triangle_list; }; diff --git a/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp b/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp index 677770ff03..7702f8a5c1 100644 --- a/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp +++ b/Userland/Demos/GLTeapot/WavefrontOBJLoader.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2021, Jesse Buhagiar + * Copyright (c) 2021, Mathieu Gaillard * * SPDX-License-Identifier: BSD-2-Clause */ @@ -47,13 +48,13 @@ RefPtr WavefrontOBJLoader::load(const String& fname) // Create a new triangle triangles.append( { - vertices.at(face_line.at(1).to_uint().value() - 1), - vertices.at(face_line.at(2).to_uint().value() - 1), - vertices.at(face_line.at(3).to_uint().value() - 1), + face_line.at(1).to_uint().value() - 1, + face_line.at(2).to_uint().value() - 1, + face_line.at(3).to_uint().value() - 1, }); } } dbgln("Wavefront: Done."); - return adopt_ref(*new Mesh(triangles)); + return adopt_ref(*new Mesh(vertices, triangles)); }