Beispiel #1
0
 /// <summary>
 /// Loads vertex and fragment shaders from strings.
 /// </summary>
 /// <param name="sVertexShd_">The s vertex SHD_.</param>
 /// <param name="sFragmentShd_">The s fragment SHD_.</param>
 /// <returns>a new instance</returns>
 public static Shader LoadFromStrings(string sVertexShd_, string sFragmentShd_)
 {
     Shader shd = new Shader();
     shd.m_ProgramID = CreaterShader(sVertexShd_, sFragmentShd_);
     if (!shd.IsLoaded())
     {
         shd = null;
     }
     return shd;
 }
Beispiel #2
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("");
        }
Beispiel #3
0
        public void loadShader(string fileName)
        {
            string sVertexShader = @"
                uniform vec2 iResolution;
                varying vec2 uv;
                out vec2 fragCoord;
                void main() {
                    gl_Position = gl_Vertex;
                    uv = gl_Vertex.xy * 0.5f + 0.5f;
                    fragCoord = uv * iResolution;
                }";
            string sFragmentShd = @"
            varying vec2 uv;
            void main() {
                vec2 uv10 = floor(uv * 10.0f);
                if(1.0 > mod(uv10.x + uv10.y, 2.0f))
                    discard;
                gl_FragColor = vec4(1, 1, 0, 0);
            }";

            if (File.Exists(fileName))
            using (StreamReader sr = new StreamReader(fileName))
            {
                sFragmentShd = sr.ReadToEnd();
            }
            shader = Shader.LoadFromStrings(sVertexShader, sFragmentShd);
        }