예제 #1
0
 public Texture2D(int width, int height, InternalFormat pixel_format, PixelDataType format, PixelType type, string sourcename)
     : this()
 {
     OpenGL.glBindTexture(OpenGL.Const.GL_TEXTURE_2D, handle);
     int_fmt   = (int)pixel_format;
     fmt       = (uint)format;
     this.type = (uint)type;
 }
예제 #2
0
        public void AssignBuffer <T>(T[] array)
        {
            var h = System.Runtime.InteropServices.GCHandle.Alloc(array, System.Runtime.InteropServices.GCHandleType.Pinned);

            OpenGL.glBindTexture(target, handle);
            OpenGL.glTexImage2D(target, 0, int_fmt, width, height, 0, fmt, type, h.AddrOfPinnedObject());
            OpenGL.glGenerateMipmap(target);
            h.Free();
        }
예제 #3
0
        public Texture2D(System.IO.Stream src, string sourcename)
            : this()
        {
            SourceName = sourcename;
            var bmp = System.Drawing.Bitmap.FromStream(src) as System.Drawing.Bitmap;

            width  = bmp.Width;
            height = bmp.Height;
            var lc = bmp.LockBits(new System.Drawing.Rectangle(0, 0, width, height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bmp.PixelFormat);

            OpenGL.glBindTexture(target, handle);
            switch (bmp.PixelFormat)
            {
            case System.Drawing.Imaging.PixelFormat.Format24bppRgb:
                int_fmt = (int)OpenGL.Const.GL_RGB8;
                fmt     = OpenGL.Const.GL_RGB;
                break;

            case System.Drawing.Imaging.PixelFormat.Format32bppArgb:
                int_fmt = (int)OpenGL.Const.GL_RGBA8;
                fmt     = OpenGL.Const.GL_RGBA;
                break;

            case System.Drawing.Imaging.PixelFormat.Format32bppRgb:
                int_fmt = (int)OpenGL.Const.GL_RGBA8;
                fmt     = OpenGL.Const.GL_RGB;
                break;

            default:
                throw new NotSupportedException("Texture format '" + bmp.PixelFormat.ToString() + "' not supported.");
            }
            type = OpenGL.Const.GL_UNSIGNED_BYTE;

            AssignTexture(lc.Scan0);
            MagFilter = Graphics.OpenGL.MagFilter.Linear;
            MinFilter = Graphics.OpenGL.MinFilter.LinearMipmapLinear;
            //OpenGL.glTexImage2D(target, 0, (int)OpenGL.Const.GL_RGBA8, bmp.Width, bmp.Height, 0, (uint)OpenGL.Const.GL_RGBA, (uint)OpenGL.Const.GL_UNSIGNED_BYTE, lc.Scan0);
            OpenGL.glBindTexture(target, 0);
            bmp.UnlockBits(lc);
            bmp.Dispose();
        }
예제 #4
0
 public void SetSide(CubemapSide side, Texture2D value)
 {
     OpenGL.glBindTexture(OpenGL.Const.GL_TEXTURE_CUBE_MAP, handle);
     textures[(int)side] = value;
     //OpenGL.glTexImage2D(OpenGL.Const.GL_TEXTURE_CUBE_MAP_POSITIVE_X + (uint)side, 0,
 }
예제 #5
0
 internal void AssignTexture(IntPtr ptr)
 {
     OpenGL.glBindTexture(target, handle);
     OpenGL.glTexImage2D(target, 0, (int)int_fmt, width, height, 0, (uint)fmt, (uint)type, ptr);
     OpenGL.glGenerateMipmap(target);
 }
예제 #6
0
 public void MakeNonCurrent()
 {
     OpenGL.glDisable(target);
     OpenGL.glBindTexture(target, 0);
 }
예제 #7
0
 public void MakeCurrent()
 {
     OpenGL.glEnable(target);
     OpenGL.glBindTexture(target, handle);
 }
예제 #8
0
 public void MakeCurrent(uint active)
 {
     OpenGL.glEnable(target);
     OpenGL.glActiveTexture(OpenGL.Const.GL_TEXTURE1 + active);
     OpenGL.glBindTexture(target, handle);
 }
예제 #9
0
 /// <summary>
 /// Applies a texture
 /// </summary>
 /// <param name="texture"></param>
 public void MakeCurrent(OpenGL.Texture texture, uint index)
 {
     GL.glActiveTexture(index);
     GL.glBindTexture((uint)texture.target, texture.Handle);
 }