コード例 #1
0
ファイル: ColorBox.cs プロジェクト: Robmaister/RoversSpirit
        /// <summary>
        /// position is top left of box.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="size"></param>
        /// <param name="color"></param>
        public ColorBox(Vector2 position, Vector2 size, Color4 color)
        {
            this.position = position;
            this.size = size;
            model = Matrix4.CreateTranslation(position.X, position.Y, 0);
            Color = color;

            float[] vertices = new float[]
            {
                0, 0,
                0, size.Y,
                size.X, 0,
                size.X, size.Y
            };

            uint[] indices = new uint[]
            {
                0, 1, 2, 3
            };

            VBO vert = new VBO(), ind = new VBO();
            vert.SetData(ref vertices, BufferUsageHint.StaticDraw);
            ind.SetData(ref indices, BufferUsageHint.StaticDraw);

            bufSet = new BufferSet();
            bufSet.VertexBuffer = vert;
            bufSet.IndexBuffer = ind;
            bufSet.VertexSize = 2;
            bufSet.DrawMode = BeginMode.TriangleStrip;
            bufSet.SetDrawState(DrawStates.Vertex);
        }
コード例 #2
0
ファイル: Entity.cs プロジェクト: Robmaister/RoversSpirit
        public Entity(Vector2 position, Vector2 size, Texture tex, Vector2 texScale, bool solid)
        {
            float x = size.X / 2.0f;
            float y = size.Y / 2.0f;

            float[] vertices =
            {
                -x, y,
                -x, -y,
                x, y,
                x, -y
            };

            float[] texcoords =
            {
                0, 1,
                0, 0,
                1, 1,
                1, 0
            };

            byte[] indices =
            {
                0, 1, 2, 3
            };

            if (texScale != Vector2.One)
            {
                for (int i = 0; i < texcoords.Length; i += 2)
                {
                    texcoords[i] *= texScale.X;
                    texcoords[i + 1] *= texScale.Y;
                }
            }

            VBO verts = new VBO(), texC = new VBO(), ind = new VBO();
            verts.SetData(ref vertices, BufferUsageHint.StaticDraw);
            texC.SetData(ref texcoords, BufferUsageHint.StaticDraw);
            ind.SetData(ref indices, BufferUsageHint.StaticDraw);

            buffers = new BufferSet();
            buffers.VertexBuffer = verts;
            buffers.VertexSize = 2;
            buffers.TexCoordBuffer = texC;
            buffers.TexCoordSize = 2;
            buffers.IndexBuffer = ind;
            buffers.DrawMode = BeginMode.TriangleStrip;
            buffers.SetDrawState(DrawStates.Vertex | DrawStates.TexCoord);

            this.size = size;
            this.position = position;
            this.tex = tex;

            this.solid = solid;

            Name = string.Empty;
            Visible = true;

            RebuildModelMatrix();
        }
コード例 #3
0
ファイル: BufferSet.cs プロジェクト: Robmaister/RoversSpirit
 private static void ValidateBuffer(VBO buffer, string name)
 {
     if (buffer == null || !buffer.Exists)
         throw new InvalidOperationException(name + " does not exist or has not been initialized properly.");
 }