Beispiel #1
0
 public override void Initialize()
 {
     texture = GLUtils.LoadImage(Application.StartupPath + filePath);
     MatchTextureBounds(Owner);
 }
Beispiel #2
0
        public static Texture2D LoadImage(string path)
        {
            Texture2D _out = null;

            if (loadedTextures.TryGetValue(path, out _out))
            {
                return _out;
            }

            try
            {
                using (Bitmap bitmap = new Bitmap(path))
                {
                    int textureID = GL.GenTexture();

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

                    BitmapData bmp_data = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);

                    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, bmp_data.Width, bmp_data.Height, 0,
                        OpenTK.Graphics.OpenGL4.PixelFormat.Bgra, PixelType.UnsignedByte, bmp_data.Scan0);

                    bitmap.UnlockBits(bmp_data);



                    Texture2D loadedTexture = new Texture2D()
                    {
                        TextureID = textureID,
                        Width = bitmap.Width,
                        Height = bitmap.Height
                    };

                    loadedTextures.Add(path, loadedTexture);

                    return loadedTexture;
                }
            }
            catch (Exception ex)
            {
                Debug.Print(ex.ToString());
                return new Texture2D();
            }
        }
Beispiel #3
0
        public void SetImage(string path)
        {
            filePath = path;
            texture = GLUtils.LoadImage(Application.StartupPath + filePath);

            if (AutoResizeWidget)
                MatchTextureBounds(Owner);
        }