示例#1
0
        public override void Create()
        {
            VAO = new("Cubemap VAO");
            VBO = new("Cubemap VBO");

            VAO.Bind();

            VBO.Bind(BufferTarget.ArrayBuffer);

            VBO.Data(skyboxVertices, BufferUsageHint.DynamicDraw);

            var VS = File.ReadAllText("EngineResources/Shaders/Cubemap/cubemap.vert");
            var FS = File.ReadAllText("EngineResources/Shaders/Cubemap/cubemap.frag");

            var VP = new GLShader(VS, GLShaderType.Vertex);
            var FP = new GLShader(FS, GLShaderType.Fragment);

            CubemapShader = new GLShaderProgram()
                            .Label("Cubemap Shader")
                            .Attach(VP)
                            .Attach(FP)
                            .Link();

            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);

            GL.BindVertexArray(0);
        }
示例#2
0
        private unsafe void SetUp()
        {
            VAO = new("Mesh VAO");
            VBO = new("Mesh VBO");
            EBO = new("Mesh EBO");

            VAO.Bind();
            VBO.Bind(BufferTarget.ArrayBuffer);

            // Buffer the vertex data into the VBO.
            var verarr = CollectionsMarshal.AsSpan(Vertices);

            GL.BufferData(BufferTarget.ArrayBuffer, verarr.Length * sizeof(Vertex), ref verarr[0], BufferUsageHint.StaticDraw);

            EBO.Bind(BufferTarget.ElementArrayBuffer);

            // Buffer the element array into the EBO.
            var indarr = CollectionsMarshal.AsSpan(Indices);

            GL.BufferData(BufferTarget.ElementArrayBuffer, indarr.Length * sizeof(uint), ref indarr[0], BufferUsageHint.StaticDraw);

            SetupPointers();

            GL.BindVertexArray(0);
        }
示例#3
0
        public void Initialize(WorldRenderer worldRenderer)
        {
            IVBOs          = new GLFloatBuffer[6];
            VAOs           = new FloatVertexArrayObject[6];
            TriangleCounts = new int[6];

            for (int i = 0; i < 6; i++)
            {
                VAOs[i]  = new FloatVertexArrayObject();
                IVBOs[i] = new GLFloatBuffer(hint: BufferUsageHint.DynamicDraw);

                VAOs[i].Bind();

                GL.BindBuffer(BufferTarget.ArrayBuffer, worldRenderer.VBOs[i]);

                VAOs[i].Attribute(0, 3, false, 5, 0);
                VAOs[i].Attribute(1, 2, false, 5, 3);

                IVBOs[i].Bind();

                VAOs[i].Attribute(2, 3, false, 4, 0);
                VAOs[i].Attribute(3, 1, false, 4, 3);

                GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

                VAOs[i].AttributeDivisor(2, 1);
                VAOs[i].AttributeDivisor(3, 1);

                GL.BindVertexArray(0);
            }

            mesh = new List <float> [6];

            for (int i = 0; i < 6; i++)
            {
                mesh[i] = new List <float>();
            }

            Initialized = true;
        }