Exemplo n.º 1
0
        public AxisPreview(KauWindow window, int size = 60, int border = 25)
        {
            this.size            = size;
            this.border          = border;
            Events.WindowResize += OnResize;
            OnResize(window);

            using (var loader = new KauRock.Loaders.Shader()) {
                loader.AddRaw("axis-preview.vert", vertShader, ShaderType.VertexShader);
                loader.AddRaw("axis-preview.frag", fragShader, ShaderType.FragmentShader);
                shader = loader.Load("axis-preview.vert", "axis-preview.frag");
            }

            vertexArray   = GL.GenVertexArray();
            vertexBuffer  = GL.GenBuffer();
            elementBuffer = GL.GenBuffer();
            GL.BindVertexArray(vertexArray);

            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);
            GL.BufferData(BufferTarget.ArrayBuffer, sizeof(float) * verts.Length, verts, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ElementArrayBuffer, elementBuffer);
            GL.BufferData(BufferTarget.ElementArrayBuffer, sizeof(uint) * tris.Length, tris, BufferUsageHint.StaticDraw);

            int stride = sizeof(float) * 6;

            GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, stride, 0);
            GL.EnableVertexAttribArray(0);
            GL.VertexAttribPointer(1, 3, VertexAttribPointerType.Float, false, stride, stride / 2);
            GL.EnableVertexAttribArray(1);
        }
Exemplo n.º 2
0
        public SkyDome()
        {
            GenerateDome(18, 6, 28, out Vertex[] verts, out int[] tris);
            triangleCount = tris.Length;

            // Load the frag and vert shaders from a string.
            using (var loader = new KauRock.Loaders.Shader()) {
                loader.AddRaw("sky.frag", fragShader, ShaderType.FragmentShader);
                loader.AddRaw("sky.vert", vertShader, ShaderType.VertexShader);

                shader = loader.Load("sky.frag", "sky.vert");
            }

            // Create our VertexArray.
            vertexArray  = GL.GenVertexArray();
            vertexBuffer = GL.GenBuffer();

            GL.BindVertexArray(vertexArray);
            GL.BindBuffer(BufferTarget.ArrayBuffer, vertexBuffer);

            // Use named storage (struct) for our vertex data.
            GL.NamedBufferStorage(vertexBuffer, Vertex.Size * verts.Length, verts, BufferStorageFlags.MapWriteBit);

            // Tell GL where to get 'aPosition' from in our shader data.
            int aPosition = shader.GetAttribLocation("aPosition");

            GL.VertexArrayAttribBinding(vertexArray, aPosition, 0);
            GL.EnableVertexArrayAttrib(vertexArray, aPosition);
            GL.VertexArrayAttribFormat(
                vertexArray,
                aPosition,                  // The attribute that we are going to set.
                3,                          // The size of the attribute (3 floats).
                VertexAttribType.Float,     // The type of attribute (floats).
                false,                      // Don't need to normalize as it's already normalized.
                0                           // The offset of the item.
                );

            // Tell GL where to get 'aColor' from in our shader data.
            int aColor = shader.GetAttribLocation("aColor");

            GL.VertexArrayAttribBinding(vertexArray, aColor, 0);
            GL.EnableVertexArrayAttrib(vertexArray, aColor);
            GL.VertexArrayAttribFormat(
                vertexArray,
                aColor,                     // The attribute that we are going to set.
                3,                          // The size of the attribute (3 floats).
                VertexAttribType.Float,     // The type of attribute (floats).
                false,                      // Don't need to normalize as it's already normalized.
                3 * sizeof(float)           // The offset of the item.
                );

            GL.VertexArrayVertexBuffer(vertexArray, 0, vertexBuffer, System.IntPtr.Zero, Vertex.Size);

            // Give GL our triangle structure.
            elementBuffer = GL.GenBuffer();
            GL.BindBuffer(BufferTarget.ElementArrayBuffer, elementBuffer);
            GL.BufferData(BufferTarget.ElementArrayBuffer, sizeof(int) * tris.Length, tris, BufferUsageHint.StaticDraw);

            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);
            GL.BindVertexArray(0);
        }