コード例 #1
0
ファイル: OpenGLTexture.cs プロジェクト: szlatyka/Sharpex2D
        /// <summary>
        /// Initializes a new OpenGLTexture class.
        /// </summary>
        /// <param name="bitmap">The Bitmap.</param>
        internal OpenGLTexture(Bitmap bitmap)
        {
            Height = bitmap.Height;
            Width  = bitmap.Width;

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

            Id = OpenGLInterops.GenTexture();

            OpenGLInterops.BindTexture(OpenGLInterops.GL_TEXTURE_2D, Id);
            OpenGLInterops.TexParameterI(OpenGLInterops.GL_TEXTURE_2D, OpenGLInterops.GL_TEXTURE_WRAP_S,
                                         (int)OpenGLInterops.GL_REPEAT);
            OpenGLInterops.TexParameterI(OpenGLInterops.GL_TEXTURE_2D, OpenGLInterops.GL_TEXTURE_WRAP_T,
                                         (int)OpenGLInterops.GL_REPEAT);

            OpenGLInterops.TexParameterF(OpenGLInterops.GL_TEXTURE_2D, OpenGLInterops.GL_TEXTURE_MIN_FILTER,
                                         SGL.SpriteBatch.InterpolationMode == InterpolationMode.Linear
                    ? OpenGLInterops.GL_LINEAR
                    : OpenGLInterops.GL_NEAREST);
            OpenGLInterops.TexParameterF(OpenGLInterops.GL_TEXTURE_2D, OpenGLInterops.GL_TEXTURE_MAG_FILTER,
                                         SGL.SpriteBatch.InterpolationMode == InterpolationMode.Linear
                    ? OpenGLInterops.GL_LINEAR
                    : OpenGLInterops.GL_NEAREST);

            OpenGLInterops.TexImage2D(OpenGLInterops.GL_TEXTURE_2D, OpenGLInterops.GL_RGBA, Width, Height,
                                      OpenGLInterops.GL_BGRA, OpenGLInterops.GL_UNSIGNED_BYTE, data.Scan0);

            OpenGLInterops.BindTexture(OpenGLInterops.GL_TEXTURE_2D, 0);
            bitmap.UnlockBits(data);
            bitmap.Dispose();
        }
コード例 #2
0
ファイル: OpenGLTexture.cs プロジェクト: szlatyka/Sharpex2D
 /// <summary>
 /// Unbinds the texture.
 /// </summary>
 internal void Unbind()
 {
     OpenGLInterops.BindTexture(OpenGLInterops.GL_TEXTURE_2D, 0);
 }
コード例 #3
0
ファイル: OpenGLTexture.cs プロジェクト: szlatyka/Sharpex2D
 /// <summary>
 /// Binds the current texture.
 /// </summary>
 internal void Bind()
 {
     OpenGLInterops.ActiveTexture(OpenGLInterops.GL_TEXTURE0);
     OpenGLInterops.BindTexture(OpenGLInterops.GL_TEXTURE_2D, Id);
 }