Hi all,
I’ve recently decided to move a community project of and old MMORPG over to Monogame but having issues creating textures. All the games textures are stored in a custom image library and I’m pulling the data out fine but the images are coming out blue.
Old function for creating a texture:
int w = Width;// + (4 - Width % 4) % 4; int h = Height;// + (4 - Height % 4) % 4; GraphicsStream stream = null;
Image = new Texture(DXManager.Device, w, h, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); stream = Image.LockRectangle(0, LockFlags.Discard); Data = (byte*)stream.InternalDataPointer;
byte[] decomp = DecompressImage(reader.ReadBytes(Length));
stream.Write(decomp, 0, decomp.Length);
stream.Dispose(); Image.UnlockRectangle(0);
My new code in Monogame:
Texture = new Texture2D(SceneManager.Instance.GraphicsDevice, Width, Height, false, SurfaceFormat.Color); Texture.SetData(DecompressImage(binaryReader.ReadBytes(Length)));
The decompress method is the same in both sources:
private static byte[] DecompressImage(byte[] imageData) { using (var stream = new GZipStream(new MemoryStream(imageData), CompressionMode.Decompress)) { const int size = 4096; var buffer = new byte[size];
using (var memoryStream = new MemoryStream()) { var count = 0; do { count = stream.Read(buffer, 0, size);
if (count > 0) memoryStream.Write(buffer, 0, count); } while (count > 0);
return memoryStream.ToArray(); } } }
I’m guessing it’s the SurfaceFormat is wrong I tried setting it too Rgba32 but then I receive an exception saying format is not supported.
Images: