示例#1
0
        private void RenderHighlightedFace(GameClient gameClient)
        {
            var highlightedBlock = gameClient.HighlightedBlock;
            if (highlightedBlock == null) return;

            var textureEntry = _textureAtlas.GetTextureEntry(gameClient.World[highlightedBlock.BlockPos]);

            _tempTriangles.Clear();

            float highlight = 0.2f;
            if (highlightedBlock.Normal.X < 0) DrawBlockLeft(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);
            if (highlightedBlock.Normal.X > 0) DrawBlockRight(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);
            if (highlightedBlock.Normal.Y < 0) DrawBlockBottom(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);
            if (highlightedBlock.Normal.Y > 0) DrawBlockTop(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);
            if (highlightedBlock.Normal.Z < 0) DrawBlockBack(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);
            if (highlightedBlock.Normal.Z > 0) DrawBlockFront(_tempTriangles, textureEntry, highlightedBlock.BlockPos.X + 0.5f, highlightedBlock.BlockPos.Y + 0.5f, highlightedBlock.BlockPos.Z + 0.5f, highlight);

            GL.UseProgram(_cubeShader.Value.Id);

            GL.UniformMatrix4(0, false, ref _projectionMatrix);
            GL.UniformMatrix4(4, false, ref _modelViewMatrix);

            using (var vertexArray = new VertexArray(_cubeVertexSpecification))
            {
                vertexArray.SetData(_tempTriangles, BufferUsageHint.DynamicDraw);
                vertexArray.Draw();
            }

            GL.UseProgram(0);
        }
示例#2
0
        private void RenderEntities(GameClient gameClient)
        {
            var infos = gameClient.EntityInfos;
            if (infos == null) return;

            GL.UseProgram(_cubeShader.Value.Id);

            GL.UniformMatrix4(0, false, ref _projectionMatrix);
            GL.UniformMatrix4(4, false, ref _modelViewMatrix);

            foreach (var info in infos)
            {
                var offset = info.PositionData.Placement.Pos - EntityPos.Origin;

                float modelWidth = 0.5f * gameClient.PhysicsValues.PlayerWidth;
                float modelHeight = gameClient.PhysicsValues.PlayerHeight;

                if (info.ModelIndex != null)
                {
                    Model model = gameClient.World.ModData.Models[(int)info.ModelIndex];

                    modelWidth = model.Width;
                    modelHeight = model.Height;
                }

                GL.Uniform3(12, (float)offset.X, (float)offset.Y, (float)offset.Z);

                using (var vertexArray = new VertexArray(_cubeVertexSpecification))
                {
                    _tempTriangles.Clear();
                    DrawEntity(_tempTriangles, 0, 0, 0, modelWidth, modelHeight);
                    vertexArray.SetData(_tempTriangles, BufferUsageHint.DynamicDraw);
                    vertexArray.Draw();
                }

                GL.Uniform3(12, 0f, 0f, 0f);
            }

            GL.UseProgram(0);
        }