Inheritance: IDisposable
 public static void SetTexture(Texture2D tex)
 {
     if (tex == null)
         GL.BindTexture(TextureTarget.Texture2D, 0);
     else
         if (ActiveTexture != tex)
         GL.BindTexture(TextureTarget.Texture2D, tex);
 }
 public static void DrawTexturedRectUVRotated(Texture2D texture, double x, double y, double w, double h, double blx, double bly, double brx, double bry, double trx, double trY, double tlx, double tly, Color col)
 {
     SetColor(col);
     SetTexture(texture);
     DrawRect(x, y, w, h, blx, bly, brx, bry, trx, trY, tlx, tly);
     SetTexture();
 }
 public static void DrawTexturedRectUVRotated(Texture2D texture, double x, double y, double w, double h, double blx, double bly, double brx, double bry, double trx, double trY, double tlx, double tly)
 {
     DrawTexturedRectUV(texture, x, y, w, h, blx, bly, brx, bry, trx, trY, tlx, tly, Color.White);
 }
 public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h)
 {
     DrawTexturedRectRotated(texture, x, y, w, h, 0);
 }
 public static void DrawTexturedRectRotated(Texture2D texture, Vector2 position, Vector2 scale)
 {
     DrawTexturedRectRotated(texture, position.X, position.Y, scale.X, scale.Y);
 }
 public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h, Color col)
 {
     DrawTexturedRectRotated(texture, x, y, w, h, 0, col);
 }
 public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h, double rot)
 {
     DrawTexturedRectRotated(texture, x, y, w, h, rot, Color.White);
 }
        /*
        public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h, Quaternion rot, Color col, double blx, double bly, double brx, double bry, double trx, double trY, double tlx, double tly)
        {
            SetColor(col);
            SetTexture(texture);
            GL.PushMatrix();
            GL.Translate(x, y, 0);
            GL.Scale(w, h, 1);
            var euler = RPGEngine.Game.Components.Transform.ToEuler(rot);
            GL.Rotate(euler.X, Vector3.UnitX);
            GL.Rotate(euler.Y, Vector3.UnitY);
            GL.Rotate(euler.Z, Vector3.UnitZ);

            GL.Translate(-0.5f, -0.5f, 0);
            DrawQuad(blx, bly, brx, bry, trx, trY, tlx, tly);

            GL.PopMatrix();
            GL.PushMatrix();
        }
        */
        public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h, double rot, Color col, double blx, double bly, double brx, double bry, double trx, double trY, double tlx, double tly)
        {
            SetColor(col);
            SetTexture(texture);
            GL.PushMatrix();
            GL.Translate(x, y, 0);
            GL.Scale(w, h, 1);
            GL.Rotate(rot, Vector3d.UnitZ);

            GL.Translate(-0.5f, -0.5f, 0);
            DrawQuad(blx, bly, brx, bry, trx, trY, tlx, tly);

            GL.PopMatrix();
            /*GL.PushMatrix();

            SetColor(1, 0, 0, 1);
            GL.Translate(x, y, 0);
            GL.Scale(w / 2, h / 2, 1);
            GL.Rotate(rot, Vector3d.UnitZ);

            GL.Begin(PrimitiveType.Quads);
            GL.TexCoord2(0, 0);
            GL.Vertex2(-1, -1);

            GL.TexCoord2(1, 0);
            GL.Vertex2(1, -1);

            GL.TexCoord2(1, 1);
            GL.Vertex2(1, 1);

            GL.TexCoord2(0, 1);
            GL.Vertex2(-1, 1);
            GL.End();

            GL.PopMatrix();
            SetTexture();
            //*/
        }
 //(0, 0, 1, 0, 1, 1, 0, 1);
 public static void DrawTexturedRectRotated(Texture2D texture, double x, double y, double w, double h, double rot, Color col)
 {
     DrawTexturedRectRotated(texture, x, y, w, h, rot, col, 0, 0, 1, 0, 1, 1, 0, 1);
 }
Exemplo n.º 10
0
 public static void DrawTexturedRect(Texture2D texture, double x, double y, double w, double h, Color col)
 {
     SetColor(col);
     SetTexture(texture);
     DrawRect(x, y, w, h, col);
     SetTexture();
 }
Exemplo n.º 11
0
 public static void DrawTexturedRect(Texture2D texture, double x, double y, double w, double h)
 {
     DrawTexturedRect(texture, x, y, w, h, Color.White);
 }
 public void Dispose()
 {
     Texture.Dispose();
     Texture = null;
 }
        public static Texture2D Load(BitmapData TextureData, TextureFilteringMode mode)
        {
            int id = 0;
            GL.GenTextures(1, out id);
            GL.BindTexture(TextureTarget.Texture2D, id);

            GL.TexEnv(TextureEnvTarget.TextureEnv,
                    TextureEnvParameter.TextureEnvMode, (float)TextureEnvMode.Modulate);
            switch (mode)
            {
                case TextureFilteringMode.Nearest:
                    GL.TexParameter(TextureTarget.Texture2D,
                        TextureParameterName.TextureMinFilter, (float)TextureMinFilter.NearestMipmapNearest);
                    GL.TexParameter(TextureTarget.Texture2D,
                        TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Nearest);
                    break;
                default:
                    GL.TexParameter(TextureTarget.Texture2D,
                        TextureParameterName.TextureMinFilter, (float)TextureMinFilter.LinearMipmapLinear);
                    GL.TexParameter(TextureTarget.Texture2D,
                        TextureParameterName.TextureMagFilter, (float)TextureMagFilter.Linear);
                    break;
            }

            GL.TexParameter(TextureTarget.Texture2D,
                TextureParameterName.GenerateMipmap, (float)1.0f);

            GL.TexImage2D(
                TextureTarget.Texture2D,
                0, // level
                PixelInternalFormat.Four,
                TextureData.Width, TextureData.Height,
                0, // border
                OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                PixelType.UnsignedByte,
                TextureData.Scan0
                );

            var Texture = new Texture2D();
            Texture.Width = TextureData.Width;
            Texture.Height = TextureData.Height;
            Texture.ID = id;
            if (Texture.ID == 0)
                return null;
            return Texture;
        }
 public static Texture2D Load(string path, TextureFilteringMode mode)
 {
     int id;
     Console.WriteLine("Attemtping to load texture at '" + path + "'");
     if (System.IO.File.Exists(path))
     {
         Texture2D Texture = new Texture2D();
         using (Bitmap TextureBitmap = new Bitmap(path))
             Texture = Load(TextureBitmap, mode);
         return Texture;
     }
     return null;
 }
        public void SetTexture(Texture2D tex)
        {
            tex.Width = Width;
            tex.Height = Height;
            _colTex = null;

            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FBOHandle);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, tex, 0);
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
            //*/
            _colTex = null;
            ColorTexture.Equals(null);
        }
        public Texture2D ReleaseTexture()
        {
            var old = ColorTexture;
            //*
            int _colTexID;

            GL.GenTextures(1, out _colTexID);

            if (_colTexID == 0)
                throw new Exception("ERROR");

            GL.BindTexture(TextureTarget.Texture2D, _colTexID);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, (int)TextureMinFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, (int)TextureMagFilter.Nearest);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapS, (int)TextureWrapMode.Clamp);
            GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureWrapT, (int)TextureWrapMode.Clamp);
            GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba8, Width, Height, 0, PixelFormat.Rgba, PixelType.UnsignedByte, IntPtr.Zero);

            ColorTextureID = _colTexID;

            var err = GL.GetError();
            if (err != ErrorCode.NoError)
            {
                System.Windows.Forms.MessageBox.Show(err.ToString());
            }

            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, FBOHandle);
            GL.Ext.FramebufferTexture2D(FramebufferTarget.FramebufferExt, FramebufferAttachment.ColorAttachment0Ext, TextureTarget.Texture2D, _colTexID, 0);
            GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0);
            //*/
            _colTex = null;
            ColorTexture.Equals(null);
            return old;
        }