Ejemplo n.º 1
0
        /// <inheritdoc/>
        public void Point(Color color, Vector vector)
        {
            var r = GetColorValue(color.R);
            var g = GetColorValue(color.G);
            var b = GetColorValue(color.B);

            float x = (float)vector.X, y = 200f - (float)vector.Y;

            _pointBuffer.Triangle(0, 1, 2);
            _pointBuffer.Triangle(0, 2, 3);

            WriteVector(_pointBuffer, x - _lineRadius, y - _lineRadius);
            _pointBuffer.VertexFloat(-1, -1);
            _pointBuffer.VertexByte(r, g, b);
            _pointBuffer.EndVertex();

            WriteVector(_pointBuffer, x + _lineRadius, y - _lineRadius);
            _pointBuffer.VertexFloat(1, -1);
            _pointBuffer.VertexByte(r, g, b);
            _pointBuffer.EndVertex();

            WriteVector(_pointBuffer, x + _lineRadius, y + _lineRadius);
            _pointBuffer.VertexFloat(1, 1);
            _pointBuffer.VertexByte(r, g, b);
            _pointBuffer.EndVertex();

            WriteVector(_pointBuffer, x - _lineRadius, y + _lineRadius);
            _pointBuffer.VertexFloat(-1, 1);
            _pointBuffer.VertexByte(r, g, b);
            _pointBuffer.EndVertex();
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreProcessor"/> class.
 /// </summary>
 public PreProcessor()
 {
     _buffer.Clear();
     _buffer.Triangle(0, 1, 2);
     _buffer.Triangle(0, 2, 3);
     _buffer.VertexFloat(-1, -1);
     _buffer.EndVertex();
     _buffer.VertexFloat(1, -1);
     _buffer.EndVertex();
     _buffer.VertexFloat(1, 1);
     _buffer.EndVertex();
     _buffer.VertexFloat(-1, 1);
     _buffer.EndVertex();
     _vertexArray.SetData(_buffer, BufferUsageHint.StaticDraw);
 }
Ejemplo n.º 3
0
        /// <inheritdoc/>
        public void Line(Color color, Vector begin, Vector end)
        {
            var r = GetColorValue(color.R);
            var g = GetColorValue(color.G);
            var b = GetColorValue(color.B);

            float ax = (float)begin.X, ay = 200f - (float)begin.Y, bx = (float)end.X, by = 200f - (float)end.Y;

            var   vx           = bx - ax;
            float vy           = by - ay;
            var   vectorLength = (float)Math.Sqrt(vx * vx + vy * vy);
            float vf           = _lineRadius / vectorLength;

            vx *= vf;
            vy *= vf;

            float lineLength = vectorLength / _lineRadius;

            _lineBuffer.Triangle(0, 1, 3);
            _lineBuffer.Triangle(1, 2, 3);

            WriteVector(_lineBuffer, ax - vx - vy, ay - vy + vx);
            _lineBuffer.VertexFloat(-1, 1);
            _lineBuffer.VertexFloat(lineLength);
            _lineBuffer.VertexByte(r, g, b);
            _lineBuffer.EndVertex();

            WriteVector(_lineBuffer, ax - vx + vy, ay - vy - vx);
            _lineBuffer.VertexFloat(-1, -1);
            _lineBuffer.VertexFloat(lineLength);
            _lineBuffer.VertexByte(r, g, b);
            _lineBuffer.EndVertex();

            WriteVector(_lineBuffer, bx + vx + vy, by + vy - vx);
            _lineBuffer.VertexFloat(lineLength + 1, -1);
            _lineBuffer.VertexFloat(lineLength);
            _lineBuffer.VertexByte(r, g, b);
            _lineBuffer.EndVertex();

            WriteVector(_lineBuffer, bx + vx - vy, by + vy + vx);
            _lineBuffer.VertexFloat(lineLength + 1, 1);
            _lineBuffer.VertexFloat(lineLength);
            _lineBuffer.VertexByte(r, g, b);
            _lineBuffer.EndVertex();
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Begins a new frame and sets the dimensions of the render area.
        /// </summary>
        /// <param name="width">The width in pixels.</param>
        /// <param name="height">The height in pixels.</param>
        internal void BeginFrame(int width, int height)
        {
            if (_width != width || _height != height)
            {
                _width  = width;
                _height = height;

                for (int i = 0; i < _blurFramebuffers.Length; ++i)
                {
                    _blurFramebuffers[i].SetSize(width * 2 / 3, height * 2 / 3);
                }

                float w, h;
                float a = (float)(width / GraphicsConstants.Width * GraphicsConstants.Height / height);
                if (a > 1)
                {
                    h = 1;
                    w = a;
                }
                else
                {
                    w = 1;
                    h = 1 / a;
                }

                _triangleBuffer.Clear();
                _triangleBuffer.Triangle(0, 1, 2);
                _triangleBuffer.Triangle(0, 2, 3);
                _triangleBuffer.VertexFloat(-1, -1);
                _triangleBuffer.VertexFloat(-w, -h);
                _triangleBuffer.EndVertex();
                _triangleBuffer.VertexFloat(1, -1);
                _triangleBuffer.VertexFloat(w, -h);
                _triangleBuffer.EndVertex();
                _triangleBuffer.VertexFloat(1, 1);
                _triangleBuffer.VertexFloat(w, h);
                _triangleBuffer.EndVertex();
                _triangleBuffer.VertexFloat(-1, 1);
                _triangleBuffer.VertexFloat(-w, h);
                _triangleBuffer.EndVertex();
                _vertexArray.SetData(_triangleBuffer, BufferUsageHint.StaticDraw);
            }
        }
Ejemplo n.º 5
0
        private void DrawBlockBottom(TriangleBuffer buffer, WorldTextureAtlas.TextureEntry textureEntry, float x, float y, float z, float highlight)
        {
            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);

            buffer.VertexFloat(x - 0.5f, y - 0.5f, z + 0.5f); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex();
            buffer.VertexFloat(x - 0.5f, y - 0.5f, z - 0.5f); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex();
            buffer.VertexFloat(x + 0.5f, y - 0.5f, z - 0.5f); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex();
            buffer.VertexFloat(x + 0.5f, y - 0.5f, z + 0.5f); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexColorBytes(0.33f, 0.33f, 0.33f, highlight); buffer.EndVertex();
        }
Ejemplo n.º 6
0
        private void DrawEntity(TriangleBuffer buffer, float x, float y, float z, float xRadius, float height)
        {
            var textureEntry = _textureAtlas.GetTextureEntry(0);

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(217, 217, 217, 0); buffer.EndVertex();

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x - xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(178, 204, 230, 0); buffer.EndVertex();

            buffer.Triangle(0, 1, 3);
            buffer.Triangle(3, 1, 2);
            buffer.VertexFloat(x - xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y0); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z + xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y0); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex();
            buffer.VertexFloat(x + xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X1, textureEntry.Y1); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex();
            buffer.VertexFloat(x - xRadius, y + height, z - xRadius); buffer.VertexUInt16(textureEntry.X0, textureEntry.Y1); buffer.VertexByte(255, 255, 255, 0); buffer.EndVertex();
        }