From 492571207dce0f661dfa4f47d2dae942bb819090 Mon Sep 17 00:00:00 2001 From: Maschell Date: Fri, 1 Mar 2019 19:18:03 +0100 Subject: [PATCH] Implement support for DrawTexture hook --- src/myutils/texture_utils.cpp | 23 +++++++++++++++++++++++ src/myutils/texture_utils.h | 3 ++- src/patcher/hooks_patcher.cpp | 2 ++ src/utils.cpp | 1 + 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/myutils/texture_utils.cpp b/src/myutils/texture_utils.cpp index c5248e9..7a638ba 100644 --- a/src/myutils/texture_utils.cpp +++ b/src/myutils/texture_utils.cpp @@ -41,6 +41,29 @@ void gdImageToUnormR8G8B8A8(gdImagePtr gdImg, u32 *imgBuffer, u32 width, u32 hei } } + +void TextureUtils::drawTexture(GX2Texture * texture, GX2Sampler* sampler, float x, float y, int32_t width, int32_t height, float alpha = 1.0f) { + float widthScaleFactor = 1.0f / (float)1280; + float heightScaleFactor = 1.0f / (float)720; + + glm::vec3 positionOffsets = glm::vec3(0.0f); + + positionOffsets[0] = (x-((1280)/2)+(width/2)) * widthScaleFactor * 2.0f; + positionOffsets[1] = -(y-((720)/2)+(height/2)) * heightScaleFactor * 2.0f; + + glm::vec3 scale(width*widthScaleFactor,height*heightScaleFactor,1.0f); + + Texture2DShader::instance()->setShaders(); + Texture2DShader::instance()->setAttributeBuffer(); + Texture2DShader::instance()->setAngle(0.0f); + Texture2DShader::instance()->setOffset(positionOffsets); + Texture2DShader::instance()->setScale(scale); + Texture2DShader::instance()->setColorIntensity(glm::vec4(alpha)); + Texture2DShader::instance()->setBlurring(glm::vec3(0.0f)); + Texture2DShader::instance()->setTextureAndSampler(texture, sampler); + Texture2DShader::instance()->draw(); +} + bool TextureUtils::convertImageToTexture(const uint8_t *img, int32_t imgSize, void * _texture){ if(!img || (imgSize < 8) || _texture == NULL){ return false; diff --git a/src/myutils/texture_utils.h b/src/myutils/texture_utils.h index 7545ed9..68d23c5 100644 --- a/src/myutils/texture_utils.h +++ b/src/myutils/texture_utils.h @@ -18,11 +18,12 @@ #define __TEXTURE_UTILS_UTILS_H_ #include #include +#include