From e97bf85bf4be1fcdac3be38c7cf2c90b6c904bef Mon Sep 17 00:00:00 2001 From: Kai Blaschke Date: Wed, 30 Mar 2022 18:31:34 +0200 Subject: [PATCH] Fix "idle" preset by re-enabling custom textures on shapes. Renamed the parameter to "image" and fixed texture wrapping/sizing. --- .../MilkdropPresetFactory/CustomShape.cpp | 3 +++ .../MilkdropPresetFactory/IdlePreset.cpp | 14 +++++------ .../Renderer/RenderItemMergeFunction.hpp | 2 +- src/libprojectM/Renderer/Shape.cpp | 23 +++++++++++++++++-- src/libprojectM/Renderer/Shape.hpp | 2 +- src/libprojectM/Renderer/TextureManager.cpp | 4 ++-- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp b/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp index a958e1120..cbc60b42e 100755 --- a/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp +++ b/src/libprojectM/MilkdropPresetFactory/CustomShape.cpp @@ -124,6 +124,9 @@ CustomShape::CustomShape(int _id) MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, 0.0), &this->param_tree); } + // projectM custom addition: Specify a texture file for use on shapes! + ParamUtils::insert(Param::new_param_string("image", P_FLAG_READONLY, &this->image), &this->text_properties_tree); + } /* Frees a custom shape form object */ diff --git a/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp b/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp index ea83875cf..785f29feb 100644 --- a/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp +++ b/src/libprojectM/MilkdropPresetFactory/IdlePreset.cpp @@ -75,17 +75,17 @@ std::string IdlePresets::presetText() "mv_b=1.000000\n" << "mv_a=0.000000\n" << "shapecode_3_enabled=1\n" << - "shapecode_3_sides=20\n" << + "shapecode_3_sides=4\n" << "shapecode_3_additive=0\n" << "shapecode_3_thickOutline=0\n" << "shapecode_3_textured=1\n" << - "shapecode_3_ImageURL=M.tga\n" << + "shapecode_3_image=m\n" << "shapecode_3_x=0.68\n" << "shapecode_3_y=0.5\n" << "shapecode_3_rad=0.41222\n" << "shapecode_3_ang=0\n" << "shapecode_3_tex_ang=0\n" << - "shapecode_3_tex_zoom=0.71\n" << + "shapecode_3_tex_zoom=0.5\n" << "shapecode_3_r=1\n" << "shapecode_3_g=1\n" << "shapecode_3_b=1\n" << @@ -111,13 +111,13 @@ std::string IdlePresets::presetText() "shapecode_4_additive=0\n" << "shapecode_4_thickOutline=0\n" << "shapecode_4_textured=1\n" << - "shapecode_4_ImageURL=headphones.tga\n" << + "shapecode_4_image=headphones\n" << "shapecode_4_x=0.68\n" << "shapecode_4_y=0.58\n" << "shapecode_4_rad=0.6\n" << "shapecode_4_ang=0\n" << "shapecode_4_tex_ang=0\n" << - "shapecode_4_tex_zoom=0.71\n" << + "shapecode_4_tex_zoom=0.5\n" << "shapecode_4_r=1\n" << "shapecode_4_g=1\n" << "shapecode_4_b=1\n" << @@ -141,13 +141,13 @@ std::string IdlePresets::presetText() // "shapecode_6_additive=0\n" << // "shapecode_6_thickOutline=0\n" << // "shapecode_6_textured=1\n" << - // "shapecode_6_ImageURL=project.tga\n" << + // "shapecode_6_image=project.tga\n" << // "shapecode_6_x=0.38\n" << // "shapecode_6_y=0.435\n" << // "shapecode_6_rad=0.8\n" << // "shapecode_6_ang=0\n" << // "shapecode_6_tex_ang=0\n" << - // "shapecode_6_tex_zoom=0.71\n" << + // "shapecode_6_tex_zoom=0.5\n" << // "shapecode_6_r=1\n" << // "shapecode_6_g=1\n" << // "shapecode_6_b=1\n" << diff --git a/src/libprojectM/Renderer/RenderItemMergeFunction.hpp b/src/libprojectM/Renderer/RenderItemMergeFunction.hpp index 6ab1308e1..bc87a7ff0 100644 --- a/src/libprojectM/Renderer/RenderItemMergeFunction.hpp +++ b/src/libprojectM/Renderer/RenderItemMergeFunction.hpp @@ -120,7 +120,7 @@ protected: target.enabled = interpolate(lhs->enabled, rhs->enabled, ratio); target.masterAlpha = interpolate(lhs->masterAlpha, rhs->masterAlpha, ratio); - target.imageUrl = (ratio > 0.5) ? lhs->imageUrl : rhs->imageUrl; + target.image = (ratio > 0.5) ? lhs->image : rhs->image; return ret; } diff --git a/src/libprojectM/Renderer/Shape.cpp b/src/libprojectM/Renderer/Shape.cpp index d14ea7cec..ba660f861 100644 --- a/src/libprojectM/Renderer/Shape.cpp +++ b/src/libprojectM/Renderer/Shape.cpp @@ -92,8 +92,27 @@ void Shape::Draw(RenderContext& context) if (textured) { + auto textureAspectY = context.aspectY; glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, context.textureManager->getMainTexture()->texID); + if (image.empty()) + { + glBindTexture(GL_TEXTURE_2D, context.textureManager->getMainTexture()->texID); + } + else + { + auto texture = context.textureManager->getTexture(image, GL_CLAMP_TO_BORDER, GL_LINEAR); + if (texture.first) + { + glBindTexture(GL_TEXTURE_2D, texture.first->texID); + glBindSampler(0, texture.second->samplerID); + textureAspectY = 1.0f; + } + else + { + // No texture found, fall back to main texture. + glBindTexture(GL_TEXTURE_2D, context.textureManager->getMainTexture()->texID); + } + } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); @@ -102,7 +121,7 @@ void Shape::Draw(RenderContext& context) const float cornerProgress = static_cast(i - 1) / static_cast(sides); vertexData[i].tex_x = - 0.5f + 0.5f * cosf(cornerProgress * pi * 2.0f + ang + pi * 0.25f) / tex_zoom * context.aspectY; + 0.5f + 0.5f * cosf(cornerProgress * pi * 2.0f + ang + pi * 0.25f) / tex_zoom * textureAspectY; vertexData[i].tex_y = 0.5f + 0.5f * sinf(cornerProgress * pi * 2.0f + ang + pi * 0.25f) / tex_zoom; } diff --git a/src/libprojectM/Renderer/Shape.hpp b/src/libprojectM/Renderer/Shape.hpp index 1cd894aaa..0e1d67fd9 100644 --- a/src/libprojectM/Renderer/Shape.hpp +++ b/src/libprojectM/Renderer/Shape.hpp @@ -19,7 +19,7 @@ public: virtual void Draw(RenderContext& context); - std::string imageUrl; //!< Texture filename to be rendered on this shape + std::string image; //!< Texture filename to be rendered on this shape int sides{ 4 }; //!< Number of sides (vertices) bool thickOutline{ false }; //!< If true, the shape is rendered with a thick line, otherwise a single-pixel line. diff --git a/src/libprojectM/Renderer/TextureManager.cpp b/src/libprojectM/Renderer/TextureManager.cpp index 9a5e127e9..ef970d36b 100644 --- a/src/libprojectM/Renderer/TextureManager.cpp +++ b/src/libprojectM/Renderer/TextureManager.cpp @@ -153,9 +153,9 @@ void TextureManager::Preload() ,&width,&height); - Texture * newTex = new Texture("M", tex, GL_TEXTURE_2D, width, height, true); + Texture * newTex = new Texture("m", tex, GL_TEXTURE_2D, width, height, true); newTex->getSampler(GL_CLAMP_TO_EDGE, GL_LINEAR); - textures["M"] = newTex; + textures["m"] = newTex; // tex = SOIL_load_OGL_texture_from_memory( // project_data,