Beispiel #1
0
 public void Draw2dTextures(Draw2dData[] todraw, int textureid)
 {
     Draw2dTextures(todraw, textureid, 0);
 }
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();
        }
        void DrawCompass()
        {
            if (!CompassInActiveMaterials()) return;
            if (compassid == -1) {
                compassid = d_The3d.LoadTexture(d_GetFile.GetFile(Path.Combine("gui", "compass.png")));
                needleid = d_The3d.LoadTexture(d_GetFile.GetFile(Path.Combine("gui", "compassneedle.png")));
            }
            float size = 175;
            float posX = Width-100;
            float posY = 100;
            float playerorientation = -(float)((player.playerorientation.Y / (2 * Math.PI)) * 360);

            compassvertex += (playerorientation-compassangle) / 50;
            compassvertex *= .90f;
            compassangle += compassvertex;

            Draw2dData[] todraw = new Draw2dData[1];
            todraw[0].x1 = posX-size/2;
            todraw[0].y1 = posY-size/2;
            todraw[0].width = size;
            todraw[0].height = size;
            todraw[0].inAtlasId = null;
            todraw[0].color = new FastColor(Color.White);

            d_The3d.Draw2dTexture(compassid, posX-size/2, posY-size/2, size, size, null);
            d_The3d.Draw2dTextures(todraw, needleid, compassangle);
        }