fixed texture scaling
This commit is contained in:
1 parent
4fb1544d65
commit
a2720eb2c5
1 file changed
+35
-5
@@ -932,11 +932,41 @@ namespace Vocaluxe.Lib.Draw
|
||||
h = maxSize;
|
||||
}
|
||||
|
||||
//Fill the new Bitmap with the texture data
|
||||
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
byte[] data = new byte[4 * w * h];
|
||||
Marshal.Copy(bmpData.Scan0, data, 0, data.Length);
|
||||
bmp.UnlockBits(bmpData);
|
||||
//Older graphics card can only handle textures with sizes being powers of two
|
||||
w = (int)_CheckForNextPowerOf2(w);
|
||||
h = (int)_CheckForNextPowerOf2(h);
|
||||
|
||||
Bitmap bmp2 = null;
|
||||
byte[] data;
|
||||
try
|
||||
{
|
||||
if (w != bmp.Width || h != bmp.Height)
|
||||
{
|
||||
//Create a new Bitmap with the new sizes
|
||||
bmp2 = new Bitmap(w, h);
|
||||
//Scale the texture
|
||||
Graphics g = Graphics.FromImage(bmp2);
|
||||
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
|
||||
g.SmoothingMode = SmoothingMode.HighQuality;
|
||||
g.DrawImage(bmp, new Rectangle(0, 0, bmp2.Width, bmp2.Height));
|
||||
g.Dispose();
|
||||
bmp = bmp2;
|
||||
}
|
||||
|
||||
//Fill the new Bitmap with the texture data
|
||||
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, w, h), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
|
||||
data = new byte[4 * w * h];
|
||||
Marshal.Copy(bmpData.Scan0, data, 0, data.Length);
|
||||
bmp.UnlockBits(bmpData);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (bmp2 != null)
|
||||
bmp2.Dispose();
|
||||
}
|
||||
|
||||
if (data == null)
|
||||
return new STexture(-1);
|
||||
|
||||
return AddTexture(w, h, ref data);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user