Ejemplo n.º 1
0
 public void DrawText(string text, Rect clipRect, TextureUnits textureUnit)
 {
     // TODO Convert chars to quadrecord
     //throw new NotImplementedException();
 }
Ejemplo n.º 2
0
 public void BindTexture2D(uint textureId, TextureUnits textureUnit = TextureUnits.GL_TEXTURE0)
 {
     GlBindings.ActiveTexture(textureUnit);
     GlBindings.BindTexture(TextureType.GL_TEXTURE_2D, textureId);
 }
Ejemplo n.º 3
0
        public void DrawText(string text, Vector2 position, TextureFont font, Vector4 color, TextureUnits textureUnit = TextureUnits.GL_TEXTURE0, int layer = 0)
        {
            // TODO? Make a seperate FontBatcher?
            // See http://www.angelcode.com/products/bmfont/doc/render_text.html
            // To improve the rendering...

            var fontSheetWidth  = (float)font.Font.Common.ScaleW;
            var fontSheetHeight = (float)font.Font.Common.ScaleH;

            for (int i = 0; i < text.Length; i++)
            {
                var quad = new QuadRecord();
                quad.X = 32 + i * 32 + 16 * i + position.X;
                quad.Y = 32 + (2 * i) + position.Y;
                quad.W = 32;
                quad.H = 32;

                // Compute the U, V and UW, UH values
                var charId   = (byte)text[i];
                var fontChar = font.CharLookup[charId];

                quad.U = fontChar.X / fontSheetWidth;
                quad.V = fontChar.Y / fontSheetHeight;

                quad.UW = fontChar.Width / fontSheetWidth;
                quad.VH = fontChar.Height / fontSheetHeight;



                PushQuad(quad);
            }

            var device = GameWindow.GraphicsDevice;

            var sX = 2 / (float)GameWindow.ScreenWidth;
            var sY = 2 / (float)GameWindow.ScreenHeight;

            var oX = -1;
            var oY = 1;

            var quadCount = m_quadRecordCount;

            // Edit Vertex Data
            for (int i = 0; i < quadCount; i++)
            {
                var record = quadRecords[i];
                m_Verticies[i * 4 + 0].Position = new Vector3(oX + (record.X + record.W) * sX, oY - (record.Y + record.H) * sY, 0.0f);       // Top Right
                m_Verticies[i * 4 + 1].Position = new Vector3(oX + (record.X + record.W) * sX, oY - (record.Y * sY), 0.0f);                  // Bottom Right
                m_Verticies[i * 4 + 2].Position = new Vector3(oX + record.X * sX, oY - (record.Y * sY), 0.0f);                               // Bottom Left
                m_Verticies[i * 4 + 3].Position = new Vector3(oX + record.X * sX, oY - (record.Y + record.H) * sY, 0.0f);                    // Top Left


                m_Verticies[i * 4 + 0].Texture = new Vector2(record.U + record.UW, record.V + record.VH);                      // Note: Inverted Y
                m_Verticies[i * 4 + 1].Texture = new Vector2(record.U + record.UW, record.V);
                m_Verticies[i * 4 + 2].Texture = new Vector2(record.U, record.V);
                m_Verticies[i * 4 + 3].Texture = new Vector2(record.U, record.V + record.VH);
            }

            m_VertexArrayObject.UpdateVertexData <DefaultQuadBatchVertex>(m_Verticies, 0, quadCount * 6);


            // TODO Make a font.glsl shader
            //    GlBindings.PolygonMode(Face.GL_FRONT_AND_BACK, Mode.GL_LINE);

            GameWindow.GraphicsDevice.BindTexture2D(font.FontTexture.TextureId, OpenGL.TextureUnits.GL_TEXTURE0);
            GameWindow.GraphicsDevice.BindTexture2D(0, OpenGL.TextureUnits.GL_TEXTURE1);

            GameWindow.GraphicsDevice.BindShaderProgram(GameWindow.QuadBatchShader.ShaderProgramId);

            GameWindow.QuadBatchShader.SetUniform("texture1", 0);

            GlBindings.BindVertexArray(m_VertexArrayObject.VaoId);
            GlBindings.DrawElements(PrimitiveType.TriangleList, quadCount * 6, DrawElementsType.UnsignedInt, 0);

            GlBindings.BindVertexArray(0);

            m_quadRecordCount = 0;
        }
Ejemplo n.º 4
0
        /// <inheritdoc/>
        public void LoadBinaryData(byte[] inData)
        {
            using (var ms = new MemoryStream(inData))
                using (var br = new BinaryReader(ms))
                {
                    br.ReadUInt32(); // Signature
                    Version = br.ReadUInt32();
                    Name    = br.ReadMD20String(br.ReadUInt32(), br.ReadUInt32());
                    Flags   = br.ReadUInt32(); // TODO: Implement Flags


                    // Global Sequences
                    UInt32 count     = br.ReadUInt32();
                    UInt32 offset    = br.ReadUInt32();
                    long   headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        UInt32 value = br.ReadUInt32();
                        GlobalSequences.Add(value);
                    }
                    br.BaseStream.Position = headerpos;

                    // Sequences
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Sequence seq = new M2Sequence();

                        seq.AnimationID         = br.ReadUInt16();
                        seq.SubAnimationID      = br.ReadUInt16();
                        seq.Length              = br.ReadUInt32();
                        seq.MovingSpeed         = br.ReadSingle();
                        seq.Flags               = br.ReadUInt32();
                        seq.Probability         = br.ReadInt16();
                        seq.Padding             = br.ReadUInt16();
                        seq.MinimumRepetitions  = br.ReadUInt32();
                        seq.MaximumRepetitions  = br.ReadUInt32();
                        seq.BlendTime           = br.ReadUInt32();
                        seq.BoundsMinimumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        seq.BoundsMaximumExtend = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        seq.BoundRadius         = br.ReadSingle();
                        seq.NextAnimation       = br.ReadInt16();
                        seq.aliasNext           = br.ReadUInt16();

                        Sequences.Add(seq);
                    }
                    br.BaseStream.Position = headerpos;

                    //SequencesLookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        SequencesLookups.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Bones
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Bone bone = new M2Bone();

                        bone.KeyBoneID  = br.ReadInt32();
                        bone.Flags      = br.ReadUInt32();
                        bone.ParentBone = br.ReadInt16();
                        bone.SubmeshID  = br.ReadUInt16();

                        bone.CompressData[0] = br.ReadUInt16();
                        bone.CompressData[1] = br.ReadUInt16();

                        //translation

                        M2Track translation = new M2Track();
                        translation.readM2Track(br);
                        bone.translation = translation;

                        // rotation
                        M2Track rotation = new M2Track();
                        rotation.readM2Track(br);
                        bone.rotation = rotation;

                        // Scale
                        M2Track scale = new M2Track();
                        scale.readM2Track(br);
                        bone.scale = scale;

                        bone.pivot = new C3Vector(br.ReadUInt32(), br.ReadUInt32(), br.ReadUInt32());

                        Bones.Add(bone);
                    }
                    br.BaseStream.Position = headerpos;

                    // key_bone_lookup
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        KeyBoneLookup.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Vetices
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Vertex temp = new M2Vertex();

                        temp.Pos = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        for (int a = 0; a < 4; a++)
                        {
                            temp.BoneWeights.Add(br.ReadByte());
                        }
                        for (int a = 0; a < 4; a++)
                        {
                            temp.BoneIndices.Add(br.ReadByte());
                        }
                        temp.Normal = new C3Vector(br.ReadSingle(), br.ReadSingle(), br.ReadSingle());
                        temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle()));
                        temp.TexCords.Add(new C2Vector(br.ReadSingle(), br.ReadSingle()));
                    }
                    br.BaseStream.Position = headerpos;

                    // Number of Skin profiles
                    NumberSkinProfiles = br.ReadUInt32();

                    // Colors
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Color temp = new M2Color();

                        // Color
                        M2Track color = new M2Track();
                        color.readM2Track(br);
                        temp.Color = color;

                        // Alpha
                        M2Track alpha = new M2Track();
                        alpha.readM2Track(br);
                        temp.Alpha = alpha;

                        Color.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Textures
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Texture temp = new M2Texture();

                        temp.Type  = br.ReadUInt32();
                        temp.Flags = br.ReadUInt32();

                        UInt32 tCount     = br.ReadUInt32();
                        UInt32 tOffset    = br.ReadUInt32();
                        long   tHeaderpos = br.BaseStream.Position;
                        br.BaseStream.Position = tOffset;

                        temp.Filename = "";
                        for (int a = 0; a < tCount; a++)
                        {
                            temp.Filename += br.ReadChar();
                        }
                        br.BaseStream.Position = tHeaderpos;

                        Texture.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Weights
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Track temp = new M2Track();
                        temp.readM2Track(br);
                        TextureWeights.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // UV Animations
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2TextureTransform temp = new M2TextureTransform();

                        M2Track translation = new M2Track();
                        translation.readM2Track(br);
                        temp.Translation = translation;

                        M2Track rotation = new M2Track();
                        rotation.readM2Track(br);
                        temp.Rotation = rotation;

                        M2Track scaling = new M2Track();
                        scaling.readM2Track(br);
                        temp.Scaling = scaling;

                        UvAnimations.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Replacements
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureReplacements.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Materials
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        M2Material temp = new M2Material();

                        temp.Flags     = br.ReadUInt16();
                        temp.BlendMode = br.ReadUInt16();

                        Materials.Add(temp);
                    }
                    br.BaseStream.Position = headerpos;

                    // Bone Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        BoneLookups.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Units
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureUnits.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Texture Weights Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        TextureWeightsLookups.Add(br.ReadUInt16());
                    }
                    br.BaseStream.Position = headerpos;

                    // Animation Lookups
                    count     = br.ReadUInt32();
                    offset    = br.ReadUInt32();
                    headerpos = br.BaseStream.Position;
                    br.BaseStream.Position = offset;
                    for (int i = 0; i < count; i++)
                    {
                        UvAnimationLookups.Add(br.ReadInt16());
                    }
                    br.BaseStream.Position = headerpos;
                }
        }