Example #1
0
        public void Compile(string renderCode, OpenTK.GLControl control)
        {
            Logger.ClearLog();

            string vShaderSource = Properties.Resources.VertexShader;
            string fShaderBegin  = Properties.Resources.RayMarchBegin;
            string fShaderEnd    = Properties.Resources.RayMarchMain;

            string fShaderSource = fShaderBegin + Environment.NewLine + renderCode + Environment.NewLine + fShaderEnd;

            if (vShaderSource == null)
            {
                Logger.Append("Failed load shaders from files");
                return;
            }

            if (!ShaderLoader.InitShaders(vShaderSource, fShaderSource, out program))
            {
                Logger.Append("Failed to initialize the shaders");
                return;
            }

            ShaderLoader.UpdateUniforms(program, control.Width, control.Height);

            nVertices = InitVertexBuffers();
            if (nVertices <= 0)
            {
                Logger.Append("Failed to write the positions of vertices to a vertex shader");
                return;
            }

            GL.ClearColor(Color.DarkSlateBlue);
            canDraw = true;
        }
Example #2
0
        public void Paint(OpenTK.GLControl control)
        {
            GL.Viewport(0, 0, control.Width, control.Height);
            GL.Clear(ClearBufferMask.ColorBufferBit);
            ShaderLoader.UpdateUniforms(program, control.Width, control.Height);

            if (canDraw)
            {
                GL.DrawArrays(PrimitiveType.Triangles, 0, nVertices);
            }

            GL.Flush();
            control.SwapBuffers();
        }