Jump to content

  • Log In with Google      Sign In   
  • Create Account

MatsK

Member Since 21 Feb 2008
Offline Last Active May 24 2016 04:02 PM

Posts I've Made

In Topic: Texture2D.GetData() returns completely transparent data (MonoGame)

05 December 2015 - 12:06 PM

It seems the solution was closer than I thought it would be. All I had to do was call Bitmap.MakeTransparent() on my bitmaps :)


In Topic: Texture2D.GetData() returns completely transparent data (MonoGame)

05 December 2015 - 06:06 AM

Thanks! :)

The problem is, I'm working with old data that uses color masks rather than alpha. Seems like the most reliable way to make masking work on all GPUs, then, is to write an extension that will run before the game starts and converts all the BMPs to PNGs with alpha.

However, this is slightly worrying, because the reason I was looking into this problem again (I had originally ignored it for the time being) was that I was trying to set a RenderTarget2D on the GraphicsDevice, and it was failing with an InvalidOperationException. I wonder if this is also a Monogame bug rolleyes.gif


In Topic: Texture2D.GetData() returns completely transparent data (MonoGame)

04 December 2015 - 05:33 PM

Texture.Format is Color.

Color as the type for GetData doesn't change anything, I get a bunch of colors with 0,0,0,0 :(

 

And yes, they render correctly.


In Topic: Texture2D.GetData() returns completely transparent data (MonoGame)

04 December 2015 - 03:51 PM

MaxResampleBufferSize is 1024 * 768. I tried changing it to the size of the texture, it doesn't seem to have made a difference. As far as I can tell, the format is Color.

Here's how I'm loading it:

        /// <summary>
        /// Gets an Texture2D instance from the FileManager.
        /// </summary>
        /// <param name="AssetID">The FileID/InstanceID of the texture to get.</param>
        /// <returns>A Texture2D instance.</returns>
        public static Texture2D GetTexture(ulong AssetID)
        {
            Stream Data = GrabItem(AssetID);

            using (MemoryStream PNGStream = new MemoryStream())
            {
                if (IsBMP(Data))
                {
                    Bitmap BMap = new Bitmap(Data);
                    BMap.Save(PNGStream, System.Drawing.Imaging.ImageFormat.Png);
                    PNGStream.Seek(0, SeekOrigin.Begin);
                }
                else
                {
                    Paloma.TargaImage TGA = new Paloma.TargaImage(Data);
                    TGA.Image.Save(PNGStream, System.Drawing.Imaging.ImageFormat.Png);
                    PNGStream.Seek(0, SeekOrigin.Begin);
                }

                return Texture2D.FromStream(m_Game.GraphicsDevice, PNGStream);
            }
        }

        /// <summary>
        /// Checks if the supplied data is a BMP.
        /// </summary>
        /// <param name="Data">The data as a Stream.</param>
        /// <returns>True if data was BMP, false otherwise.</returns>
        private static bool IsBMP(Stream Data)
        {
            BinaryReader Reader = new BinaryReader(Data, Encoding.UTF8, true);
            byte[] data = Reader.ReadBytes(2);
            byte[] magic = new byte[] { (byte)'B', (byte)'M' };
            return data.SequenceEqual(magic);
        }

In Topic: GonzoNet - high level library for large scale robust networking

01 January 2015 - 12:40 PM

So I rewrote GonzoNet and my servers to use BlockingCollection instead of ArrayList and ConcurrentDictionary instead of Dictionary.

However, I'm pretty sure I read on MSDN somewhere (I can't find the article right now) that I should be using BlockingCollection.GetConsumingEnumerable() when doing a foreach loop, because the standard foreach iterator will block threads.

So... how would I then readd items into the collection after I'm done consuming them?

Could I add them to a temp collection and replace the original one with the temp? Would that be safe?


PARTNERS