From c88038e38a60f0cb2144f62dc0bfc4dd888495a9 Mon Sep 17 00:00:00 2001 From: Absolutely disgusting Date: Wed, 4 Mar 2026 21:26:54 +0400 Subject: [PATCH] Fixed bitmap resize --- 2DGAMELIB/_2DGAMELIB/ModeEventDispatcher.cs | 11 ++ 2DGAMELIB/_2DGAMELIB/WPFImage.cs | 146 ++++++++++++------ .../BodyPartClasses/バイブ_デンマ.cs | 2 +- SlaveMatrix/SlaveMatrix/GameClasses/Sta.cs | 54 +++---- 4 files changed, 140 insertions(+), 73 deletions(-) diff --git a/2DGAMELIB/_2DGAMELIB/ModeEventDispatcher.cs b/2DGAMELIB/_2DGAMELIB/ModeEventDispatcher.cs index a62277e..9a73924 100644 --- a/2DGAMELIB/_2DGAMELIB/ModeEventDispatcher.cs +++ b/2DGAMELIB/_2DGAMELIB/ModeEventDispatcher.cs @@ -215,6 +215,17 @@ namespace _2DGAMELIB resVector.Y = ((double)height - (double)BaseSize.Height / resMag) * 0.5; } } + + int fbW, fbH; + + Glfw.GetFramebufferSize(GlImage.PtrToWindow(window), out fbW, out fbH); + + uint vpW = (uint)(BaseSize.Width / resMag); + uint vpH = (uint)(BaseSize.Height / resMag); + int vpX = (int)(resVector.X); + int vpY = (int)(fbH - resVector.Y - vpH); + + baseControl.SetViewport(vpW, vpH, vpX, vpY); }; return BaseSize; diff --git a/2DGAMELIB/_2DGAMELIB/WPFImage.cs b/2DGAMELIB/_2DGAMELIB/WPFImage.cs index d6985ac..b8b7c2f 100644 --- a/2DGAMELIB/_2DGAMELIB/WPFImage.cs +++ b/2DGAMELIB/_2DGAMELIB/WPFImage.cs @@ -37,9 +37,16 @@ namespace _2DGAMELIB private uint texture; private uint vertex_buf; private uint vao; + public int texW = 0; + public int texH = 0; public GlImage() { } + public void SetViewport(uint vpW, uint vpH, int vpX, int vpY) + { + gl.Viewport(vpX, vpY, vpW, vpH); + } + public Vector2D GetCursorPoint() { double x, y; Glfw.GetCursorPosition(window, out x, out y); @@ -92,48 +99,47 @@ namespace _2DGAMELIB public unsafe void SetBitmap(Bitmap bmp) { gl.UseProgram(shader_program); - gl.Viewport(new Size(bmp.Width, bmp.Height)); - gl.ActiveTexture(Silk.NET.OpenGL.GLEnum.Texture0); - gl.BindTexture(Silk.NET.OpenGL.GLEnum.Texture2D, texture); + gl.BindTexture(Silk.NET.OpenGL.GLEnum.Texture2D, texture); - BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); - - gl.TexImage2D( - Silk.NET.OpenGL.GLEnum.Texture2D, + if (bmp.Width != texW || bmp.Height != texH) + { + gl.TexImage2D( + Silk.NET.OpenGL.GLEnum.Texture2D, 0, - InternalFormat.Rgba8, - (uint)bmp.Width, - (uint)bmp.Height, + InternalFormat.Rgba8, + (uint)bmp.Width, + (uint)bmp.Height, 0, Silk.NET.OpenGL.GLEnum.Bgra, - Silk.NET.OpenGL.GLEnum.UnsignedByte, - (void*)data.Scan0 - ); + Silk.NET.OpenGL.GLEnum.UnsignedByte, + null); + + texW = bmp.Width; + texH = bmp.Height; + } + + BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + gl.PixelStore(GLEnum.UnpackAlignment, 1); + + gl.TexSubImage2D( + Silk.NET.OpenGL.GLEnum.Texture2D, + 0, + 0, + 0, + (uint)bmp.Width, + (uint)bmp.Height, + Silk.NET.OpenGL.GLEnum.Bgra, + Silk.NET.OpenGL.GLEnum.UnsignedByte, + (void*)data.Scan0); bmp.UnlockBits(data); - - int res_pos = gl.GetUniformLocation(shader_program, "res"); - gl.Uniform2(res_pos, (float)bmp.Width, (float)bmp.Height); - - gl.BindBuffer(GLEnum.ArrayBuffer, vertex_buf); - uint vert_pos = (uint)gl.GetAttribLocation(shader_program, "vertPos"); - gl.EnableVertexAttribArray(vert_pos); - - gl.BindVertexArray(vao); - gl.VertexAttribPointer( - vert_pos, - 2, - GLEnum.Float, - false, - 0, - IntPtr.Zero - ); - - gl.DrawArrays(GLEnum.TriangleStrip, 0, 4); + gl.BindVertexArray(0); + Glfw.SwapBuffers(window); } @@ -164,31 +170,33 @@ namespace _2DGAMELIB string vertexShaderSource = @" -#version 100 -precision mediump float; +#version 330 core -attribute vec2 vertPos; +layout (location = 0) in vec2 aPos; +layout (location = 1) in vec2 aUV; + +out vec2 vUV; void main() { - gl_Position = vec4(vertPos, 0.0, 1.0); + gl_Position = vec4(aPos, 0.0f, 1.0f); + vUV = aUV; } "; string fragmentShaderSource = @" -#version 100 -precision mediump float; +#version 330 core + +in vec2 vUV; + +out vec4 FragColor; uniform sampler2D sTexture; -uniform vec2 res; void main() { - vec2 tc = gl_FragCoord.xy / res; - tc.y = 1.0 - tc.y; - - gl_FragColor = texture2D(sTexture, tc); + FragColor = texture(sTexture, vUV); } "; @@ -217,19 +225,67 @@ void main() gl.ActiveTexture(Silk.NET.OpenGL.GLEnum.Texture0); gl.BindTexture(Silk.NET.OpenGL.GLEnum.Texture2D, texture); - + gl.TexParameterI(Silk.NET.OpenGL.GLEnum.Texture2D, Silk.NET.OpenGL.GLEnum.TextureWrapS, new int[] {(int)TextureWrapMode.ClampToEdge}); gl.TexParameterI(Silk.NET.OpenGL.GLEnum.Texture2D, Silk.NET.OpenGL.GLEnum.TextureWrapT, new int[] {(int)TextureWrapMode.ClampToEdge}); gl.TexParameterI(Silk.NET.OpenGL.GLEnum.Texture2D, Silk.NET.OpenGL.GLEnum.TextureMagFilter, new int[] {(int)TextureMagFilter.Nearest}); gl.TexParameterI(Silk.NET.OpenGL.GLEnum.Texture2D, Silk.NET.OpenGL.GLEnum.TextureMinFilter, new int[] {(int)TextureMinFilter.Nearest}); + gl.TexImage2D( + Silk.NET.OpenGL.GLEnum.Texture2D, + 0, + InternalFormat.Rgba8, + (uint)bmp.Width, + (uint)bmp.Height, + 0, + Silk.NET.OpenGL.GLEnum.Bgra, + Silk.NET.OpenGL.GLEnum.UnsignedByte, + null + ); + + texW = bmp.Width; + texH = bmp.Height; + + float[] buf = { + -1.0f, -1.0f, 0.0f, 1.0f, + 1.0f, -1.0f, 1.0f, 1.0f, + -1.0f, 1.0f, 0.0f, 0.0f, + 1.0f, 1.0f, 1.0f, 0.0f + }; - float[] buf = { 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, -1.0f, -1.0f }; vertex_buf = gl.GenBuffer(); gl.BindBuffer(Silk.NET.OpenGL.GLEnum.ArrayBuffer, vertex_buf); fixed (float* buf_ = buf) gl.BufferData(Silk.NET.OpenGL.GLEnum.ArrayBuffer, (uint)(sizeof(float) * buf.Length), buf_, Silk.NET.OpenGL.GLEnum.StaticDraw); vao = gl.GenVertexArray(); + + gl.BindVertexArray(vao); + gl.BindBuffer(GLEnum.ArrayBuffer, vertex_buf); + + + gl.VertexAttribPointer( + 0, + 2, + GLEnum.Float, + false, + 4 * sizeof(float), + IntPtr.Zero + ); + + gl.EnableVertexAttribArray(0); + + gl.VertexAttribPointer( + 1, + 2, + GLEnum.Float, + false, + 4 * sizeof(float), + (void*)(2 * sizeof(float)) + ); + + gl.EnableVertexAttribArray(1); + + gl.BindVertexArray(0); } } } \ No newline at end of file diff --git a/SlaveMatrix/SlaveMatrix/BodyPartClasses/バイブ_デンマ.cs b/SlaveMatrix/SlaveMatrix/BodyPartClasses/バイブ_デンマ.cs index 477aaf0..81e99b8 100644 --- a/SlaveMatrix/SlaveMatrix/BodyPartClasses/バイブ_デンマ.cs +++ b/SlaveMatrix/SlaveMatrix/BodyPartClasses/バイブ_デンマ.cs @@ -2,7 +2,7 @@ using _2DGAMELIB; namespace SlaveMatrix { - public class バイブ_デンマ : Ele + public class バイブ_デンマ : Ele //baibu_denma { public Par X0Y0_ヘッド; diff --git a/SlaveMatrix/SlaveMatrix/GameClasses/Sta.cs b/SlaveMatrix/SlaveMatrix/GameClasses/Sta.cs index 8534503..c1d13c4 100644 --- a/SlaveMatrix/SlaveMatrix/GameClasses/Sta.cs +++ b/SlaveMatrix/SlaveMatrix/GameClasses/Sta.cs @@ -902,7 +902,7 @@ namespace SlaveMatrix return t[num][num2]; } - public static List パース(this string s) + public static List Parse(this string s) { List list = new List(); string[] array = s.Split("\r\n\r\n"); @@ -921,29 +921,29 @@ namespace SlaveMatrix public static void Set擬音() { string[] array = ImiPath.FromText().Split(','); - 口挿 = array[0].パース(); - 口中 = array[1].パース(); - 口抜 = array[2].パース(); - 膣挿 = array[3].パース(); - 膣中 = array[4].パース(); - 膣抜 = array[5].パース(); - 肛挿 = array[6].パース(); - 肛中 = array[7].パース(); - 肛抜 = array[8].パース(); - 糸挿 = array[9].パース(); - 糸中 = array[10].パース(); - 糸抜 = array[11].パース(); - 潮吹 = array[12].パース(); - 放尿 = array[13].パース(); - くぱ = array[14].パース(); - 吸引 = array[15].パース(); - 吸着 = array[16].パース(); - 吸脱 = array[17].パース(); - 振動 = array[18].パース(); - 鞭振 = array[19].パース(); - 鞭打 = array[20].パース(); - 剃り = array[21].パース(); - 射精 = array[22].パース(); + 口挿 = array[0].Parse(); + 口中 = array[1].Parse(); + 口抜 = array[2].Parse(); + 膣挿 = array[3].Parse(); + 膣中 = array[4].Parse(); + 膣抜 = array[5].Parse(); + 肛挿 = array[6].Parse(); + 肛中 = array[7].Parse(); + 肛抜 = array[8].Parse(); + 糸挿 = array[9].Parse(); + 糸中 = array[10].Parse(); + 糸抜 = array[11].Parse(); + 潮吹 = array[12].Parse(); + 放尿 = array[13].Parse(); + くぱ = array[14].Parse(); + 吸引 = array[15].Parse(); + 吸着 = array[16].Parse(); + 吸脱 = array[17].Parse(); + 振動 = array[18].Parse(); + 鞭振 = array[19].Parse(); + 鞭打 = array[20].Parse(); + 剃り = array[21].Parse(); + 射精 = array[22].Parse(); 処女喪失 = (from f in array[23].Split("\r\n") where !string.IsNullOrWhiteSpace(f) && !f.StartsWith("//") select f).First(); @@ -1088,9 +1088,9 @@ namespace SlaveMatrix obj.MigrateKeys(); 胴体 = obj; - //胴体.SaveExMod("C:\\Users\\dave\\Documents\\胴体"); - //Ser.ToJson(胴体, "C:\\Users\\dave\\Documents\\胴体.json"); - //胴体 = Ser.UnJson("C:\\Users\\dave\\Documents\\胴体.json"); + //胴体.SaveExMod("C:\\Users\\adel4\\Documents\\胴体"); + //Ser.ToJson(胴体, "C:\\Users\\adel4\\Documents\\胴体.json"); + //胴体 = Ser.UnJson("C:\\Users\\adel4\\Documents\\胴体.json"); obj = Resources.肩左.ObjLoad(); obj.MigrateKeys();