public int Add(ushort[] p, VertexPositionTexture[] vertexPositionTexture, bool transparent, int texture)
 {
     int id;
     lock (toadd)
     {
         if (empty.Count > 0)
         {
             id = MyLinq.First(empty.Keys);
             empty.Remove(id);
         }
         else
         {
             id = count;
             count++;
         }
         toadd.Enqueue(new ToAdd() { indices = p, vertices = vertexPositionTexture, id = id,
             transparent = transparent, texture = texture });
     }
     return id;
 }
Beispiel #2
0
        public void Draw2dTextures(Draw2dData[] todraw, int textureid, float angle)
        {
            GL.PushAttrib(AttribMask.ColorBufferBit);
            GL.BindTexture(TextureTarget.Texture2D, textureid);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);

            VertexPositionTexture[] vertices;
            ushort[] indices;
            if (todraw.Length >= draw2dtexturesMAX)
            {
                vertices = new VertexPositionTexture[todraw.Length * 4];
                indices = new ushort[todraw.Length * 4];
            }
            else
            {
                if (draw2dtexturesVertices == null)
                {
                    draw2dtexturesVertices = new VertexPositionTexture[draw2dtexturesMAX * 4];
                    draw2dtexturesIndices = new ushort[draw2dtexturesMAX * 4];
                }
                vertices = draw2dtexturesVertices;
                indices = draw2dtexturesIndices;
            }
            ushort i = 0;
            foreach (Draw2dData v in todraw)
            {
                RectangleF rect;
                if (v.inAtlasId == null)
                {
                    rect = new RectangleF(0, 0, 1, 1);
                }
                else
                {
                    rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, d_Terrain.texturesPacked);
                }
                float x2 = v.x1 + v.width;
                float y2 = v.y1 + v.height;

                PointF[] pnts = new PointF[4] {
                    new PointF(x2, y2),
                    new PointF(x2,v.y1),
                    new PointF(v.x1,v.y1),
                    new PointF(v.x1,y2)};
                if (angle != 0)
                {
                    System.Drawing.Drawing2D.Matrix mx=new System.Drawing.Drawing2D.Matrix();
                    mx.RotateAt(angle, new PointF(v.x1+v.width/2,v.y1+v.height/2));
                    mx.TransformPoints(pnts);
                }

                vertices[i] = new VertexPositionTexture(pnts[0].X, pnts[0].Y, 0, rect.Right, rect.Bottom, v.color);
                vertices[i + 1] = new VertexPositionTexture(pnts[1].X, pnts[1].Y, 0, rect.Right, rect.Top, v.color);
                vertices[i + 2] = new VertexPositionTexture(pnts[2].X, pnts[2].Y, 0, rect.Left, rect.Top, v.color);
                vertices[i + 3] = new VertexPositionTexture(pnts[3].X, pnts[3].Y, 0, rect.Left, rect.Bottom, v.color);
                indices[i] = i;
                indices[i + 1] = (ushort)(i + 1);
                indices[i + 2] = (ushort)(i + 2);
                indices[i + 3] = (ushort)(i + 3);
                i += 4;
            }
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            unsafe
            {
                fixed (VertexPositionTexture* p = vertices)
                {
                    GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte*)p));
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte*)p));
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte*)p));
                    GL.DrawElements(BeginMode.Quads, i, DrawElementsType.UnsignedShort, indices);
                }
            }
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            GL.Enable(EnableCap.DepthTest);
            GL.PopAttrib();
        }
        public void Draw2dTextures(List<Draw2dData> todraw, int textureid)
        {
            GL.PushAttrib(AttribMask.ColorBufferBit);
            GL.BindTexture(TextureTarget.Texture2D, textureid);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);

            VertexPositionTexture[] vertices = new VertexPositionTexture[todraw.Count * 4];
            ushort[] indices = new ushort[todraw.Count * 4];
            ushort i=0;
            foreach (var v in todraw)
            {
                RectangleF rect;
                if (v.inAtlasId == null)
                {
                    rect = new RectangleF(0, 0, 1, 1);
                }
                else
                {
                    rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, terrain.texturesPacked);
                }
                GL.Color3(v.color);
                float x2 = v.x1 + v.width;
                float y2 = v.y1 + v.height;
                vertices[i] = new VertexPositionTexture(x2, y2, 0, rect.Right, rect.Bottom, v.color);
                vertices[i + 1] = new VertexPositionTexture(x2, v.y1, 0, rect.Right, rect.Top, v.color);
                vertices[i + 2] = new VertexPositionTexture(v.x1, v.y1, 0, rect.Left, rect.Top, v.color);
                vertices[i + 3] = new VertexPositionTexture(v.x1, y2, 0, rect.Left, rect.Bottom, v.color);
                indices[i] = i;
                indices[i + 1] = (ushort)(i + 1);
                indices[i + 2] = (ushort)(i + 2);
                indices[i + 3] = (ushort)(i + 3);
                i += 4;
            }
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            unsafe
            {
                fixed (VertexPositionTexture* p = vertices)
                {
                    GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte*)p));
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte*)p));
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte*)p));
                    GL.DrawElements(BeginMode.Quads, indices.Length, DrawElementsType.UnsignedShort, indices);
                }
            }
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            GL.Enable(EnableCap.DepthTest);
            GL.PopAttrib();
        }
Beispiel #4
0
        public void Draw2dTextures(Draw2dData[] todraw, int textureid, float angle)
        {
            GL.PushAttrib(AttribMask.ColorBufferBit);
            GL.BindTexture(TextureTarget.Texture2D, textureid);
            GL.Enable(EnableCap.Texture2D);
            GL.Disable(EnableCap.DepthTest);

            VertexPositionTexture[] vertices;
            ushort[] indices;
            if (todraw.Length >= draw2dtexturesMAX)
            {
                vertices = new VertexPositionTexture[todraw.Length * 4];
                indices  = new ushort[todraw.Length * 4];
            }
            else
            {
                if (draw2dtexturesVertices == null)
                {
                    draw2dtexturesVertices = new VertexPositionTexture[draw2dtexturesMAX * 4];
                    draw2dtexturesIndices  = new ushort[draw2dtexturesMAX * 4];
                }
                vertices = draw2dtexturesVertices;
                indices  = draw2dtexturesIndices;
            }
            ushort i = 0;

            foreach (Draw2dData v in todraw)
            {
                RectangleF rect;
                if (v.inAtlasId == null)
                {
                    rect = new RectangleF(0, 0, 1, 1);
                }
                else
                {
                    rect = TextureAtlas.TextureCoords2d(v.inAtlasId.Value, d_Terrain.texturesPacked);
                }
                float x2 = v.x1 + v.width;
                float y2 = v.y1 + v.height;

                PointF[] pnts = new PointF[4] {
                    new PointF(x2, y2),
                    new PointF(x2, v.y1),
                    new PointF(v.x1, v.y1),
                    new PointF(v.x1, y2)
                };
                if (angle != 0)
                {
                    System.Drawing.Drawing2D.Matrix mx = new System.Drawing.Drawing2D.Matrix();
                    mx.RotateAt(angle, new PointF(v.x1 + v.width / 2, v.y1 + v.height / 2));
                    mx.TransformPoints(pnts);
                }

                vertices[i]     = new VertexPositionTexture(pnts[0].X, pnts[0].Y, 0, rect.Right, rect.Bottom, v.color);
                vertices[i + 1] = new VertexPositionTexture(pnts[1].X, pnts[1].Y, 0, rect.Right, rect.Top, v.color);
                vertices[i + 2] = new VertexPositionTexture(pnts[2].X, pnts[2].Y, 0, rect.Left, rect.Top, v.color);
                vertices[i + 3] = new VertexPositionTexture(pnts[3].X, pnts[3].Y, 0, rect.Left, rect.Bottom, v.color);
                indices[i]      = i;
                indices[i + 1]  = (ushort)(i + 1);
                indices[i + 2]  = (ushort)(i + 2);
                indices[i + 3]  = (ushort)(i + 3);
                i += 4;
            }
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.ColorArray);
            unsafe
            {
                fixed(VertexPositionTexture *p = vertices)
                {
                    GL.VertexPointer(3, VertexPointerType.Float, StrideOfVertices, (IntPtr)(0 + (byte *)p));
                    GL.TexCoordPointer(2, TexCoordPointerType.Float, StrideOfVertices, (IntPtr)(12 + (byte *)p));
                    GL.ColorPointer(4, ColorPointerType.UnsignedByte, StrideOfVertices, (IntPtr)(20 + (byte *)p));
                    GL.DrawElements(BeginMode.Quads, i, DrawElementsType.UnsignedShort, indices);
                }
            }
            GL.DisableClientState(ArrayCap.TextureCoordArray);
            GL.DisableClientState(ArrayCap.VertexArray);
            GL.DisableClientState(ArrayCap.ColorArray);

            GL.Enable(EnableCap.DepthTest);
            GL.PopAttrib();
        }