diff options
author | Treeki <treeki@gmail.com> | 2011-02-18 03:28:31 +0100 |
---|---|---|
committer | Treeki <treeki@gmail.com> | 2011-02-18 03:28:31 +0100 |
commit | b0760b28807b31cc1403584265c07feb87ac4887 (patch) | |
tree | dc97346a0c0d0cdcdc066d77df3905a614a858e8 /NW4RTools/Models/OpenGL/GLTexture.cs | |
parent | 7d7491feb41bc9724bf63bef545b996226406889 (diff) | |
download | nw4rtools-b0760b28807b31cc1403584265c07feb87ac4887.tar.gz nw4rtools-b0760b28807b31cc1403584265c07feb87ac4887.zip |
some collada work, and an unfinished OGL renderer using OpenTK. huge commit
Diffstat (limited to 'NW4RTools/Models/OpenGL/GLTexture.cs')
-rw-r--r-- | NW4RTools/Models/OpenGL/GLTexture.cs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/NW4RTools/Models/OpenGL/GLTexture.cs b/NW4RTools/Models/OpenGL/GLTexture.cs new file mode 100644 index 0000000..c4cdee6 --- /dev/null +++ b/NW4RTools/Models/OpenGL/GLTexture.cs @@ -0,0 +1,46 @@ +using System; +using NW4RTools; +using NW4RTools.Models; +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.OpenGL; + +namespace NW4RTools.Models.OpenGL { + public class GLTexture : IDisposable { + public readonly int TextureID; + + public GLTexture() { + TextureID = GL.GenTexture(); + } + + void IDisposable.Dispose() { + GL.DeleteTexture(TextureID); + } + + public void Load(Texture tex) { + Bind(TextureTarget.Texture2D); + + // todo: check if this is configurable + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Linear); + GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMagFilter.Linear); + + //byte[] pixelData = new byte[tex.BaseImage.Width * tex.BaseImage.Height * 4]; + + var lb = tex.BaseImage.LockBits( + new System.Drawing.Rectangle(0, 0, tex.BaseImage.Width, tex.BaseImage.Height), + System.Drawing.Imaging.ImageLockMode.ReadOnly, + System.Drawing.Imaging.PixelFormat.Format32bppArgb); + + GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Four, + tex.BaseImage.Width, tex.BaseImage.Height, 0, + PixelFormat.Bgra, PixelType.UnsignedByte, lb.Scan0); + + tex.BaseImage.UnlockBits(lb); + } + + public void Bind(TextureTarget target) { + GL.BindTexture(target, TextureID); + } + } +} + |