Example #1
0
        public static GameTexture ConvertToTexture(EmbeddedTexture tex)
        {
            tex.Log($"Loading Texture... Width: {tex.Width} Height: {tex.Height}", DebugChannel.Log, 8);
            GameTexture ret = new GameTexture();

            GL.BindTexture(TextureTarget.Texture2D, ret.textureID);

            byte[] flatBytes = flattenImageData(tex.NonCompressedData);

            GCHandle handle = GCHandle.Alloc(flatBytes, GCHandleType.Pinned);
            IntPtr   ptr    = handle.AddrOfPinnedObject();


            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, tex.Width, tex.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, ptr);

            handle.Free();

            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            return(ret);
        }
Example #2
0
        public static GameTexture Load(string filename)
        {
            Bitmap bmp = new Bitmap(filename);

            bmp.Log($"Loading Texture: " + filename, DebugChannel.Log, 8);
            bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);

            BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly,
                                           PixelFormat.Format32bppArgb);

            GameTexture ret = new GameTexture();

            GL.BindTexture(TextureTarget.Texture2D, ret.textureID);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, data.Width, data.Height, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
            bmp.UnlockBits(data);


            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Repeat);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Repeat);

            return(ret);
        }
Example #3
0
 public static void Update(GameTexture tex, byte[] buffer, int width, int height)
 {
     GL.BindTexture(TextureTarget.Texture2D, tex.textureID);
     GL.TexSubImage2D(TextureTarget.Texture2D, 0, 0, 0, (int)width, (int)height, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, buffer);
 }