summaryrefslogtreecommitdiff
path: root/Userland/Applications/3DFileViewer
diff options
context:
space:
mode:
authorStephan Unverwerth <s.unverwerth@serenityos.org>2021-08-11 23:43:28 +0200
committerAndreas Kling <kling@serenityos.org>2021-08-12 18:58:41 +0200
commit75bc7be6222d8d892c556ff3fa07c8265bc0c621 (patch)
tree8850895f47d45de93f21387c6b4515cbda321920 /Userland/Applications/3DFileViewer
parentb9523e15dfc6510b9c2978b1645ad61c690811ee (diff)
downloadserenity-75bc7be6222d8d892c556ff3fa07c8265bc0c621.zip
3DFileViewer: Add texture menu
This allows setting different texture wrap modes and setting different texture coordinate scale factors.
Diffstat (limited to 'Userland/Applications/3DFileViewer')
-rw-r--r--Userland/Applications/3DFileViewer/Mesh.cpp8
-rw-r--r--Userland/Applications/3DFileViewer/Mesh.h2
-rw-r--r--Userland/Applications/3DFileViewer/main.cpp99
3 files changed, 103 insertions, 6 deletions
diff --git a/Userland/Applications/3DFileViewer/Mesh.cpp b/Userland/Applications/3DFileViewer/Mesh.cpp
index 9a8a7001f7..20e8cec61a 100644
--- a/Userland/Applications/3DFileViewer/Mesh.cpp
+++ b/Userland/Applications/3DFileViewer/Mesh.cpp
@@ -29,7 +29,7 @@ Mesh::Mesh(Vector<Vertex> vertices, Vector<TexCoord> tex_coords, Vector<Triangle
{
}
-void Mesh::draw()
+void Mesh::draw(float uv_scale)
{
// Light direction
const FloatVector3 light_direction(1.f, 1.f, 1.f);
@@ -76,7 +76,7 @@ void Mesh::draw()
m_vertex_list.at(m_triangle_list[i].a).z);
if (is_textured())
- glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index0).u, 1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index0).v);
+ glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index0).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index0).v) * uv_scale);
// Vertex 2
glVertex3f(
@@ -85,7 +85,7 @@ void Mesh::draw()
m_vertex_list.at(m_triangle_list[i].b).z);
if (is_textured())
- glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index1).u, 1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index1).v);
+ glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index1).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index1).v) * uv_scale);
// Vertex 3
glVertex3f(
@@ -94,7 +94,7 @@ void Mesh::draw()
m_vertex_list.at(m_triangle_list[i].c).z);
if (is_textured())
- glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index2).u, 1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index2).v);
+ glTexCoord2f(m_tex_coords.at(m_triangle_list[i].tex_coord_index2).u * uv_scale, (1.0f - m_tex_coords.at(m_triangle_list[i].tex_coord_index2).v) * uv_scale);
glEnd();
}
diff --git a/Userland/Applications/3DFileViewer/Mesh.h b/Userland/Applications/3DFileViewer/Mesh.h
index b17b0bde8e..ce5c718e7b 100644
--- a/Userland/Applications/3DFileViewer/Mesh.h
+++ b/Userland/Applications/3DFileViewer/Mesh.h
@@ -22,7 +22,7 @@ public:
size_t triangle_count() const { return m_triangle_list.size(); }
- void draw();
+ void draw(float uv_scale);
bool is_textured() const { return m_tex_coords.size() > 0; }
diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp
index ae2c1fbc2a..ba95f1873e 100644
--- a/Userland/Applications/3DFileViewer/main.cpp
+++ b/Userland/Applications/3DFileViewer/main.cpp
@@ -39,6 +39,9 @@ public:
void toggle_rotate_z() { m_rotate_z = !m_rotate_z; }
void set_rotation_speed(float speed) { m_rotation_speed = speed; }
void set_stat_label(RefPtr<GUI::Label> l) { m_stats = l; };
+ void set_wrap_s_mode(GLint mode) { m_wrap_s_mode = mode; }
+ void set_wrap_t_mode(GLint mode) { m_wrap_t_mode = mode; }
+ void set_texture_scale(float scale) { m_texture_scale = scale; }
void toggle_show_frame_rate()
{
@@ -97,6 +100,9 @@ private:
int m_cycles = 0;
int m_accumulated_time = 0;
RefPtr<GUI::Label> m_stats;
+ GLint m_wrap_s_mode = GL_REPEAT;
+ GLint m_wrap_t_mode = GL_REPEAT;
+ float m_texture_scale = 1.0f;
};
void GLContextWidget::paint_event(GUI::PaintEvent& event)
@@ -141,8 +147,11 @@ void GLContextWidget::timer_event(Core::TimerEvent&)
glRotatef(m_angle_y, 0, 1, 0);
glRotatef(m_angle_z, 0, 0, 1);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, m_wrap_s_mode);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, m_wrap_t_mode);
+
if (!m_mesh.is_null())
- m_mesh->draw();
+ m_mesh->draw(m_texture_scale);
m_context->present();
@@ -319,6 +328,94 @@ int main(int argc, char** argv)
view_menu.add_action(*show_frame_rate_action);
+ auto& texture_menu = window->add_menu("&Texture");
+
+ auto& wrap_u_menu = texture_menu.add_submenu("Wrap &S");
+ GUI::ActionGroup wrap_s_actions;
+ wrap_s_actions.set_exclusive(true);
+
+ auto wrap_u_repeat_action = GUI::Action::create_checkable("&Repeat", [&widget](auto&) {
+ widget.set_wrap_s_mode(GL_REPEAT);
+ });
+ auto wrap_u_mirrored_repeat_action = GUI::Action::create_checkable("&Mirrored Repeat", [&widget](auto&) {
+ widget.set_wrap_s_mode(GL_MIRRORED_REPEAT);
+ });
+ auto wrap_u_clamp_action = GUI::Action::create_checkable("&Clamp", [&widget](auto&) {
+ widget.set_wrap_s_mode(GL_CLAMP);
+ });
+
+ wrap_s_actions.add_action(*wrap_u_repeat_action);
+ wrap_s_actions.add_action(*wrap_u_mirrored_repeat_action);
+ wrap_s_actions.add_action(*wrap_u_clamp_action);
+
+ wrap_u_menu.add_action(*wrap_u_repeat_action);
+ wrap_u_menu.add_action(*wrap_u_mirrored_repeat_action);
+ wrap_u_menu.add_action(*wrap_u_clamp_action);
+
+ wrap_u_repeat_action->set_checked(true);
+
+ auto& wrap_t_menu = texture_menu.add_submenu("Wrap &T");
+ GUI::ActionGroup wrap_t_actions;
+ wrap_t_actions.set_exclusive(true);
+
+ auto wrap_t_repeat_action = GUI::Action::create_checkable("&Repeat", [&widget](auto&) {
+ widget.set_wrap_t_mode(GL_REPEAT);
+ });
+ auto wrap_t_mirrored_repeat_action = GUI::Action::create_checkable("&Mirrored Repeat", [&widget](auto&) {
+ widget.set_wrap_t_mode(GL_MIRRORED_REPEAT);
+ });
+ auto wrap_t_clamp_action = GUI::Action::create_checkable("&Clamp", [&widget](auto&) {
+ widget.set_wrap_t_mode(GL_CLAMP);
+ });
+
+ wrap_t_actions.add_action(*wrap_t_repeat_action);
+ wrap_t_actions.add_action(*wrap_t_mirrored_repeat_action);
+ wrap_t_actions.add_action(*wrap_t_clamp_action);
+
+ wrap_t_menu.add_action(*wrap_t_repeat_action);
+ wrap_t_menu.add_action(*wrap_t_mirrored_repeat_action);
+ wrap_t_menu.add_action(*wrap_t_clamp_action);
+
+ wrap_t_repeat_action->set_checked(true);
+
+ auto& texture_scale_menu = texture_menu.add_submenu("S&cale");
+ GUI::ActionGroup texture_scale_actions;
+ texture_scale_actions.set_exclusive(true);
+
+ auto texture_scale_025_action = GUI::Action::create_checkable("0.25x", [&widget](auto&) {
+ widget.set_texture_scale(0.25f);
+ });
+
+ auto texture_scale_05_action = GUI::Action::create_checkable("0.5x", [&widget](auto&) {
+ widget.set_texture_scale(0.5f);
+ });
+
+ auto texture_scale_1_action = GUI::Action::create_checkable("1x", [&widget](auto&) {
+ widget.set_texture_scale(1);
+ });
+
+ auto texture_scale_2_action = GUI::Action::create_checkable("2x", [&widget](auto&) {
+ widget.set_texture_scale(2);
+ });
+
+ auto texture_scale_4_action = GUI::Action::create_checkable("4x", [&widget](auto&) {
+ widget.set_texture_scale(4);
+ });
+
+ texture_scale_actions.add_action(*texture_scale_025_action);
+ texture_scale_actions.add_action(*texture_scale_05_action);
+ texture_scale_actions.add_action(*texture_scale_1_action);
+ texture_scale_actions.add_action(*texture_scale_2_action);
+ texture_scale_actions.add_action(*texture_scale_4_action);
+
+ texture_scale_menu.add_action(*texture_scale_025_action);
+ texture_scale_menu.add_action(*texture_scale_05_action);
+ texture_scale_menu.add_action(*texture_scale_1_action);
+ texture_scale_menu.add_action(*texture_scale_2_action);
+ texture_scale_menu.add_action(*texture_scale_4_action);
+
+ texture_scale_1_action->set_checked(true);
+
auto& help_menu = window->add_menu("&Help");
help_menu.add_action(GUI::CommonActions::make_about_action("3D File Viewer", app_icon, window));