Esempio n. 1
0
        public Visual()
        {
            // Vertex positions
            float[] positions =
            {
                1.0f, -1.0f,
                1.0f, 1.0f,
                -1.0f, -1.0f,
                -1.0f, 1.0f
            };
            // Reserve a name for the buffer object.
            bufferQuad = GL.GenBuffer();
            // Bind it to the GL_ARRAY_BUFFER target.
            GL.BindBuffer(BufferTarget.ArrayBuffer, bufferQuad);
            // Allocate space for it (sizeof(positions)
            GL.BufferData(BufferTarget.ArrayBuffer
                , (IntPtr) (sizeof(float) * positions.Length), positions, BufferUsageHint.StaticDraw);

            GL.BindVertexArray(bufferQuad);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.VertexPointer(2, VertexPointerType.Float, 0, 0);
            GL.BindVertexArray(0);
            GL.BindBuffer(BufferTarget.ArrayBuffer, 0);

            GL.Disable(EnableCap.DepthTest);
            GL.ClearColor(1, 0, 0, 0);

            surface = new GLTools.Texture(1, 1);

            string sVertexShader = @"
                varying vec2 uv;
                void main() {
                    gl_Position = gl_Vertex;
                    uv = gl_Vertex.xy * 0.5f + 0.5f;
                }";
            string sFragmentShd = @"
            varying vec2 uv;
            uniform sampler2D tex;
            void main() {
                gl_FragColor = texture(tex, uv);
            }";
            shaderCopy = Shader.LoadFromStrings(sVertexShader, sFragmentShd);

            loadShader("");
        }
Esempio n. 2
0
        public void update(float timeSec, int mouseX, int mouseY, bool leftButton, int width, int height)
        {
            surface = GLTools.Texture.Resize(ref surface, width, height);
            surface.BeginUpdate();

            var resolution = new Vector2(width, height);
            GL.Viewport(0, 0, width, height);
            shader.Begin();
            GL.Uniform1(shader.GetUniformLocation("iGlobalTime"), timeSec);
            GL.Uniform2(shader.GetUniformLocation("iResolution"), resolution);
            GL.Uniform3(shader.GetUniformLocation("iMouse"), new Vector3(mouseX, mouseY, leftButton ? 1.0f : 0.0f));
            GL.Clear(ClearBufferMask.ColorBufferBit);
            GL.BindVertexArray(bufferQuad);
            GL.DrawArrays(PrimitiveType.TriangleStrip, 0, 4);
            GL.BindVertexArray(0);
            shader.End();

            surface.EndUpdate();
        }
Esempio n. 3
0
 public static Texture Resize(ref Texture surface, int width, int height)
 {
     if(width != surface.Width || height != surface.Height)
     {
         surface.Dispose();
         surface = new Texture(width, height);
     }
     return surface;
 }