aboutsummaryrefslogtreecommitdiffstatsci
path: root/src/OpenGL/GLBackend/Surface.cs
diff options
context:
space:
mode:
authorjpbruyere <jp.bruyere@hotmail.com>2015-10-21 22:00:20 +0200
committerjpbruyere <jp.bruyere@hotmail.com>2015-10-21 22:00:20 +0200
commit8099f1775b6d9083e04b2f39700c2e90a0724aca (patch)
treea145c7f1ec8aeb4aade2ffae4e2c50771ef9ec86 /src/OpenGL/GLBackend/Surface.cs
parentf31ffd683210c50b777dce4e76d0d9912ca925a8 (diff)
glbackend tests, copy first try from hg reposglbackend
Diffstat (limited to 'src/OpenGL/GLBackend/Surface.cs')
-rw-r--r--src/OpenGL/GLBackend/Surface.cs103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/OpenGL/GLBackend/Surface.cs b/src/OpenGL/GLBackend/Surface.cs
new file mode 100644
index 00000000..010a0f54
--- /dev/null
+++ b/src/OpenGL/GLBackend/Surface.cs
@@ -0,0 +1,103 @@
+using System;
+using OpenTK.Graphics.OpenGL;
+
+namespace go.GLBackend
+{
+ [Serializable]
+ public enum Format
+ {
+ Argb32,
+ Rgb24,
+ A8,
+ A1,
+ Rgb16565,
+ ARGB32,
+ RGB24
+ }
+ [Serializable]
+ public enum LineJoin
+ {
+ Miter,
+ Round,
+ Bevel
+ }
+ [Serializable]
+ public enum LineCap
+ {
+ Butt,
+ Round,
+ Square
+ }
+ public class Surface : IDisposable
+ {
+ public static int samples;
+
+ public int texId,
+ width,
+ height;
+ Format format;
+
+ public PixelFormat PixelFormat;
+ public PixelInternalFormat InternalFormat;
+
+ public Surface (int _width, int _height)
+ {
+ format = Format.Argb32;
+ width = _width;
+ height = _height;
+
+ createTexture ();
+ }
+
+ public Surface (Format _format,int _width, int _height)
+ {
+ format = _format;
+ width = _width;
+ height = _height;
+
+ InternalFormat = PixelInternalFormat.Rgba;
+ PixelFormat = PixelFormat.Bgra;
+
+ createTexture ();
+ }
+
+ public Surface CreateSimilar()
+ {
+ return new Surface (format, width, height);
+ }
+
+ void createTexture()
+ {
+ texId = GL.GenTexture();
+ GL.BindTexture(TextureTarget.Texture2D, texId);
+ GL.TexImage2D(TextureTarget.Texture2D,0,
+ PixelInternalFormat.Rgba, width, height,0,PixelFormat.Bgra,PixelType.UnsignedByte,IntPtr.Zero);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
+ GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
+
+
+ public void Save(string fileName)
+ {
+ GL.BindTexture(TextureTarget.Texture2D, texId);
+ System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ System.Drawing.Imaging.BitmapData data = bmp.LockBits(new System.Drawing.Rectangle(0, 0, width, height),
+ System.Drawing.Imaging.ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
+ GL.GetTexImage(TextureTarget.Texture2D, 0, OpenTK.Graphics.OpenGL.PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0);
+ bmp.UnlockBits(data);
+ bmp.RotateFlip (System.Drawing.RotateFlipType.RotateNoneFlipY);
+ bmp.Save(fileName);
+ GL.BindTexture(TextureTarget.Texture2D, 0);
+ }
+
+ #region IDisposable implementation
+ public void Dispose ()
+ {
+ if (GL.IsTexture (texId))
+ GL.DeleteTexture (texId);
+ }
+ #endregion
+ }
+}
+