Пример #1
0
        void LoadFromFile(string f)
        {
            if (!String.IsNullOrEmpty(f))
            {
                if (File.Exists(f))
                {
                    _filename = f;
                    if (frames == null)
                    {
                        frames = new TextureList();
                    }
                    frames.Clear();

                    Image          gifImg    = Image.FromFile(f);
                    FrameDimension dimension = new FrameDimension(gifImg.FrameDimensionsList[0]);

                    int frameCount = gifImg.GetFrameCount(dimension);

                    for (int i = 0; i < frameCount; i++)
                    {
                        gifImg.SelectActiveFrame(dimension, i);
                        Bitmap  frame = new Bitmap(gifImg);
                        Texture tex   = new Texture();
                        tex.LoadFromBitmap(frame);
                        frames.Add(tex);
                    }
                }
            }
            else
            {
                frames = null;
            }
        }
Пример #2
0
        public static void drawTexture(Texture texture, Vector position, Vector center, Vector scale, int angle, int width, int height)
        {
            Vector[] vertexBuf = new Vector[4];
            Vector[] normalsBuf = new Vector[4];
            Vector[] textureBuf = new Vector[4];

            vertexBuf[0].x = -center.x; vertexBuf[0].y = -center.y;
            vertexBuf[1].x = width - center.x; vertexBuf[1].y = -center.y;
            vertexBuf[2].x = width - center.x; vertexBuf[2].y = height - center.y;
            vertexBuf[3].x = -center.x; vertexBuf[3].y = height - center.y;

            textureBuf[0] = new Vector(0, 0);
            textureBuf[1] = new Vector(1, 0);
            textureBuf[2] = new Vector(1, 1);
            textureBuf[3] = new Vector(0, 1);

            //Verts
            int vId = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.BufferData<Vector>(BufferTarget.ArrayBuffer, new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf, BufferUsageHint.StreamDraw);
            GL.BufferSubData<Vector>(BufferTarget.ArrayBuffer, new IntPtr(0), new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Textures
            int tId = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 2 * textureBuf.Length), textureBuf, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.PushMatrix();

            if (width <= 0) width = 1;
            if (height <= 0) height = 1;

            Texture tex = new Texture();
            Bitmap bitmap = new Bitmap(texture.bitmap, width, height);
            tex.LoadFromBitmap(bitmap);

            Engine.shaders.guiShader.begin();
            Engine.shaders.guiShader.pass("texture", tex);
            Engine.shaders.guiShader.pass("color", new Vec4(1, 1, 1, 1));

            GL.Translate(position.x, position.y, 0);
            GL.Rotate(angle, 0, 0, 1);

            GL.Scale(scale.x, scale.y, 1);

            //Биндим текстурные координаты
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, 0);

            //Биндим геометрию
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.VertexPointer(2, VertexPointerType.Float, 0, 0);

            //Рисуем
            GL.DrawArrays(PrimitiveType.Quads, 0, vertexBuf.Length);

            Engine.shaders.guiShader.passNullTex("texture");
            Engine.shaders.guiShader.end();

            GL.DeleteTexture(tex.ID);

            bitmap.Dispose();
            tex.Dispose();

            GL.PopMatrix();

            //Отключаем все
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);

            GL.DeleteBuffer(vId);
            GL.DeleteBuffer(tId);
        }
Пример #3
0
        public static void drawTexture(Texture texture, Vector position, Vector center, Vector scale, int angle, int width, int height)
        {
            Vector[] vertexBuf  = new Vector[4];
            Vector[] normalsBuf = new Vector[4];
            Vector[] textureBuf = new Vector[4];

            vertexBuf[0].x = -center.x; vertexBuf[0].y = -center.y;
            vertexBuf[1].x = width - center.x; vertexBuf[1].y = -center.y;
            vertexBuf[2].x = width - center.x; vertexBuf[2].y = height - center.y;
            vertexBuf[3].x = -center.x; vertexBuf[3].y = height - center.y;

            textureBuf[0] = new Vector(0, 0);
            textureBuf[1] = new Vector(1, 0);
            textureBuf[2] = new Vector(1, 1);
            textureBuf[3] = new Vector(0, 1);

            //Verts
            int vId = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.BufferData <Vector>(BufferTarget.ArrayBuffer, new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf, BufferUsageHint.StreamDraw);
            GL.BufferSubData <Vector>(BufferTarget.ArrayBuffer, new IntPtr(0), new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Textures
            int tId = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 2 * textureBuf.Length), textureBuf, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.PushMatrix();

            if (width <= 0)
            {
                width = 1;
            }
            if (height <= 0)
            {
                height = 1;
            }

            Texture tex    = new Texture();
            Bitmap  bitmap = new Bitmap(texture.bitmap, width, height);

            tex.LoadFromBitmap(bitmap);

            Engine.shaders.guiShader.begin();
            Engine.shaders.guiShader.pass("texture", tex);
            Engine.shaders.guiShader.pass("color", new Vec4(1, 1, 1, 1));

            GL.Translate(position.x, position.y, 0);
            GL.Rotate(angle, 0, 0, 1);

            GL.Scale(scale.x, scale.y, 1);

            //Биндим текстурные координаты
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, 0);

            //Биндим геометрию
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.VertexPointer(2, VertexPointerType.Float, 0, 0);

            //Рисуем
            GL.DrawArrays(PrimitiveType.Quads, 0, vertexBuf.Length);

            Engine.shaders.guiShader.passNullTex("texture");
            Engine.shaders.guiShader.end();

            GL.DeleteTexture(tex.ID);

            bitmap.Dispose();
            tex.Dispose();

            GL.PopMatrix();

            //Отключаем все
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.TextureCoordArray);

            GL.DeleteBuffer(vId);
            GL.DeleteBuffer(tId);
        }
Пример #4
0
        internal void renderString(Vector position, Vector center, Vector scale, int angle, int width, int height, string text, Color color, int size)
        {
            Vector[] vertexBuf  = new Vector[4];
            Vector[] normalsBuf = new Vector[4];
            Vector[] textureBuf = new Vector[4];

            vertexBuf[0].x = -center.x; vertexBuf[0].y = -center.y;
            vertexBuf[1].x = width - center.x; vertexBuf[1].y = -center.y;
            vertexBuf[2].x = width - center.x; vertexBuf[2].y = height - center.y;
            vertexBuf[3].x = -center.x; vertexBuf[3].y = height - center.y;

            textureBuf[0] = new Vector(0, 0);
            textureBuf[1] = new Vector(1, 0);
            textureBuf[2] = new Vector(1, 1);
            textureBuf[3] = new Vector(0, 1);

            //Verts
            int vId = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.BufferData <Vector>(BufferTarget.ArrayBuffer, new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf, BufferUsageHint.StreamDraw);
            GL.BufferSubData <Vector>(BufferTarget.ArrayBuffer, new IntPtr(0), new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Textures
            int tId = GL.GenBuffer();

            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 2 * textureBuf.Length), textureBuf, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.PushMatrix();

            if (width <= 0)
            {
                width = 1;
            }
            if (height <= 0)
            {
                height = 1;
            }

            Bitmap   bitmap = new Bitmap(width, height);
            Graphics g      = Graphics.FromImage(bitmap);

            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            g.Clear(System.Drawing.Color.Transparent);

            font = new System.Drawing.Font(font.FontFamily, size, FontStyle.Regular);
            g.DrawString(text, font, new SolidBrush(System.Drawing.Color.FromArgb(color.a, color.r, color.g, color.b)), new PointF(0, 0));

            if (bitmap != null)
            {
                Texture tex = new Texture();
                tex.LoadFromBitmap(bitmap);

                Engine.shaders.guiShader.begin();
                Engine.shaders.guiShader.pass("texture", tex);
                Engine.shaders.guiShader.pass("color", new Vec4(1, 1, 1, 1));

                GL.Translate(position.x, position.y, 0);
                GL.Rotate(angle, 0, 0, 1);

                GL.Scale(scale.x, scale.y, 1);

                //Биндим текстурные координаты
                GL.EnableClientState(ArrayCap.TextureCoordArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, 0);

                //Биндим геометрию
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
                GL.VertexPointer(2, VertexPointerType.Float, 0, 0);

                //Рисуем
                GL.DrawArrays(PrimitiveType.Quads, 0, vertexBuf.Length);

                Engine.shaders.guiShader.passNullTex("texture");
                Engine.shaders.guiShader.end();

                GL.DeleteTexture(tex.ID);

                bitmap.Dispose();
                g.Dispose();
                tex.Dispose();
            }

            GL.PopMatrix();

            if (bitmap != null)
            {
                //Отключаем все
                GL.DisableClientState(ArrayCap.VertexArray);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
            }

            GL.DeleteBuffer(vId);
            GL.DeleteBuffer(tId);
        }
Пример #5
0
        internal void renderString(Vector position, Vector center, Vector scale, int angle, int width, int height, string text, Color color, int size)
        {
            Vector[] vertexBuf = new Vector[4];
            Vector[] normalsBuf = new Vector[4];
            Vector[] textureBuf = new Vector[4];

            vertexBuf[0].x = -center.x; vertexBuf[0].y = -center.y;
            vertexBuf[1].x = width - center.x; vertexBuf[1].y = -center.y;
            vertexBuf[2].x = width - center.x; vertexBuf[2].y = height - center.y;
            vertexBuf[3].x = -center.x; vertexBuf[3].y = height - center.y;

            textureBuf[0] = new Vector(0, 0);
            textureBuf[1] = new Vector(1, 0);
            textureBuf[2] = new Vector(1, 1);
            textureBuf[3] = new Vector(0, 1);

            //Verts
            int vId = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
            GL.BufferData<Vector>(BufferTarget.ArrayBuffer, new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf, BufferUsageHint.StreamDraw);
            GL.BufferSubData<Vector>(BufferTarget.ArrayBuffer, new IntPtr(0), new IntPtr(Marshal.SizeOf(new Vector()) * 2 * vertexBuf.Length), vertexBuf);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            //Textures
            int tId = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
            GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(sizeof(float) * 2 * textureBuf.Length), textureBuf, BufferUsageHint.StaticDraw);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.PushMatrix();

            if (width <= 0) width = 1;
            if (height <= 0) height = 1;

            Bitmap bitmap = new Bitmap(width, height);
            Graphics g = Graphics.FromImage(bitmap);

            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            g.Clear(System.Drawing.Color.Transparent);

            font = new System.Drawing.Font(font.FontFamily, size, FontStyle.Regular);
            g.DrawString(text, font, new SolidBrush(System.Drawing.Color.FromArgb(color.a, color.r, color.g, color.b)), new PointF(0, 0));

            if (bitmap != null)
            {
                Texture tex = new Texture();
                tex.LoadFromBitmap(bitmap);

                Engine.shaders.guiShader.begin();
                Engine.shaders.guiShader.pass("texture", tex);
                Engine.shaders.guiShader.pass("color", new Vec4(1, 1, 1, 1));

                GL.Translate(position.x, position.y, 0);
                GL.Rotate(angle, 0, 0, 1);

                GL.Scale(scale.x, scale.y, 1);

                //Биндим текстурные координаты
                GL.EnableClientState(ArrayCap.TextureCoordArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, tId);
                GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, 0);

                //Биндим геометрию
                GL.EnableClientState(ArrayCap.VertexArray);
                GL.BindBuffer(BufferTarget.ArrayBuffer, vId);
                GL.VertexPointer(2, VertexPointerType.Float, 0, 0);

                //Рисуем
                GL.DrawArrays(PrimitiveType.Quads, 0, vertexBuf.Length);

                Engine.shaders.guiShader.passNullTex("texture");
                Engine.shaders.guiShader.end();

                GL.DeleteTexture(tex.ID);

                bitmap.Dispose();
                g.Dispose();
                tex.Dispose();
            }

            GL.PopMatrix();

            if (bitmap != null)
            {
                //Отключаем все
                GL.DisableClientState(ArrayCap.VertexArray);
                GL.DisableClientState(ArrayCap.TextureCoordArray);
            }

            GL.DeleteBuffer(vId);
            GL.DeleteBuffer(tId);
        }