예제 #1
0
        public Macroblock(World GW)
        {
            this.Size       = ChunkSize;
            this.ShaderProg = GlobalShaderProg;
            this.Atlas      = GlobalAtlas;
            this.GW         = GW;

            Clr = new Vector3((float)RND.Next(0, 100) / 100, (float)RND.Next(0, 100) / 100, (float)RND.Next(0, 100) / 100);

            ChunkMatrix = Matrix4.Identity;
        }
예제 #2
0
        public VertexArray(Prog GLProgram, Matrix4 MViewMat,
                           Vector3[] Vert, uint[] Inds = null, Vector3[] Cols = null, Vector2[] UV = null, Vector4[] BlockInds = null)
        {
            ID = GL.GenVertexArray();
            GL.BindVertexArray(ID);

            ModelMatrix = MViewMat;
            GLProg      = GLProgram;

            Indices = new VertexBuffer <uint>(BufferTarget.ElementArrayBuffer, BufferUsageHint.StaticDraw);
            Verts   = new VertexBuffer <Vector3>(BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            Verts.SetAttribute(GLProg.Attrib("Position"));
            Colors    = new VertexBuffer <Vector3>(BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            UVs       = new VertexBuffer <Vector2>(BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);
            BlockData = new VertexBuffer <Vector4>(BufferTarget.ArrayBuffer, BufferUsageHint.StaticDraw);

            Set(Vert, Inds, Cols, UV, BlockInds);
        }
예제 #3
0
        protected override void OnLoad(EventArgs e)
        {
            MakeCurrent();
            this.Icon = Icon.ExtractAssociatedIcon("Content/terminal.ico");

            X = Screen.Wi / 2 - Width / 2;
            Y = Screen.Hi / 2 - Height / 2;
            InitOpenGL();

            Prog ScrProg = new Prog(Shader.FF("Content/Shaders/screen.frag.glsl", ShaderType.FragmentShader),
                                    Shader.FF("Content/Shaders/screen.vert.glsl", ShaderType.VertexShader));

            ScrQuad = new VertexArray(ScrProg, Matrix4.Identity, new Vector3[] {
                new Vector3(-1, -1, -1),
                new Vector3(1, -1, -1),
                new Vector3(1, 1, -1),
                new Vector3(-1, 1, -1)
            }, null, null, new Vector2[] {
                new Vector2(0, 0),
                new Vector2(1, 0),
                new Vector2(1, 1),
                new Vector2(0, 1),
            });
            ScrQuad.Use(true, false, true, false);

            Scr = new Framebuffer(this, Width, Height);
            ScrQuad.SetTexture(Scr.Color);
            ScrQuad.SetTexture2(Scr.DepthStencil);

            Macroblock.GlobalShaderProg = new Prog(
                Shader.FromFile("Content/Shaders/block.frag.glsl", ShaderType.FragmentShader),
                Shader.FromFile("Content/Shaders/block.vert.glsl", ShaderType.VertexShader));
            Macroblock.GlobalAtlas = new Texture("Content/Textures/block_atlas.png");

            GameWorld = new World(this);
            GameWorld.Load(0);

            Entity.Create <CaptionFPSCounter>(this);
            Entity.Create <Player>(this);
        }
예제 #4
0
        public World(Renderer R)
        {
            this.R      = R;
            WorldSize   = 10;           // 24
            WorldHeight = 16;           // 16

            Chunks = new Macroblock[WorldSize, WorldSize, WorldHeight];

            Prog SkyboxShader = new Prog(Shader.FF("Content/Shaders/skybox.vert.glsl", ShaderType.VertexShader),
                                         Shader.FF("Content/Shaders/skybox.frag.glsl", ShaderType.FragmentShader));

            float UW = 1f / 6;
            float SS = 10;

            Skybox = new VertexArray(SkyboxShader, Matrix4.Identity, new Vector3[] {
                // Top
                new Vector3(-SS, -SS, SS),
                new Vector3(-SS, SS, SS),
                new Vector3(SS, SS, SS),
                new Vector3(SS, -SS, SS),
                // Bottom
                new Vector3(-SS, -SS, -SS),
                new Vector3(SS, -SS, -SS),
                new Vector3(SS, SS, -SS),
                new Vector3(-SS, SS, -SS),
                // Forward
                new Vector3(-SS, -SS, -SS),
                new Vector3(-SS, -SS, SS),
                new Vector3(SS, -SS, SS),
                new Vector3(SS, -SS, -SS),
                // Right
                new Vector3(-SS, SS, -SS),
                new Vector3(-SS, SS, SS),
                new Vector3(-SS, -SS, SS),
                new Vector3(-SS, -SS, -SS),
                // Back
                new Vector3(SS, SS, -SS),
                new Vector3(SS, SS, SS),
                new Vector3(-SS, SS, SS),
                new Vector3(-SS, SS, -SS),
                // Left
                new Vector3(SS, -SS, -SS),
                new Vector3(SS, -SS, SS),
                new Vector3(SS, SS, SS),
                new Vector3(SS, SS, -SS),
            }, UV: new Vector2[] {
                //1
                new Vector2(UW * 1, 1),
                new Vector2(UW * 1, 0),
                new Vector2(UW * 0, 0),
                new Vector2(UW * 0, 1),
                //2
                new Vector2(UW * 2, 0),
                new Vector2(UW * 1, 0),
                new Vector2(UW * 1, 1),
                new Vector2(UW * 2, 1),
                //3
                new Vector2(UW * 3, 1),
                new Vector2(UW * 3, 0),
                new Vector2(UW * 2, 0),
                new Vector2(UW * 2, 1),
                //4
                new Vector2(UW * 4, 1),
                new Vector2(UW * 4, 0),
                new Vector2(UW * 3, 0),
                new Vector2(UW * 3, 1),
                //5
                new Vector2(UW * 5, 1),
                new Vector2(UW * 5, 0),
                new Vector2(UW * 4, 0),
                new Vector2(UW * 4, 1),
                //6
                new Vector2(UW * 6, 1),
                new Vector2(UW * 6, 0),
                new Vector2(UW * 5, 0),
                new Vector2(UW * 5, 1),
            });

            Skybox.SetTexture(new Texture("Content/Textures/skybox1.png"));
        }