Example #1
0
 public void Start(IRenderContext ctx)
 {
     Gl                      = (IOpenGLContext)ctx;
     Gl.Frame               += Render;
     Gl.Input.Mouse.Click   += HandleClick;
     Gl.Input.Mouse.Release += HandleRelease;
 }
Example #2
0
 public void BackgroundContextAction(Action action)
 {
     if (IOpenGLContext.HasContext())
     {
         action(); // We have a context already - use that (assuming it is the main one).
     }
     else
     {
         _window.BackgroundContext.Invoke(action);
     }
 }
Example #3
0
        public BackgroundContextWorker(IOpenGLContext backgroundContext)
        {
            _backgroundContext = backgroundContext;
            _running           = true;

            _signal     = new AutoResetEvent(false);
            _work       = new Queue <Action>();
            _invokePool = new ObjectPool <ManualResetEventSlim>(() => new ManualResetEventSlim(), 10);

            _thread = new Thread(Run);
            _thread.Start();
        }
Example #4
0
        public void BackgroundContextAction(Action action, bool alwaysBackground = false)
        {
            // alwaysBackground is ignored, since we cannot switch from the current context.

            if (IOpenGLContext.HasContext())
            {
                action(); // We have a context already - use that (assuming it is the main one).
            }
            else
            {
                _window.BackgroundContext.Invoke(action);
            }
        }
Example #5
0
 public void Start(IRenderContext ctx)
 {
     Gl        = (IOpenGLContext)ctx;
     Gl.Frame += Render;
     Gl.Enable(GlEnableCap.DepthTest);
     Gl.DepthFunc(GlDepthFunction.Lequal);
     Gl.MatrixMode(GlMatrixMode.Projection);
     SetPerspective(Math.PI / 2, 16.0 / 9.0, 1, 10);
     Gl.MatrixMode(GlMatrixMode.Modelview);
     Gl.Translated(0, 0, -CameraDistance);
     Axis    = new double[3];
     Random  = new Random();
     Axis[0] = RandomDouble();
     Axis[1] = RandomDouble();
     Axis[2] = RandomDouble();
 }
Example #6
0
 public void InitializeBackgroundContext(IOpenGLContext baseContext)
 {
     BackgroundContext = new BackgroundContextWorker(baseContext);
 }
Example #7
0
 public void InitializeBackgroundContext(IOpenGLContext baseContext)
 {
     _window.InitializeBackgroundContext(baseContext);
 }
Example #8
0
        public void Start(IRenderContext ctx)
        {
            Gl        = (IOpenGLContext)ctx;
            Gl.Frame += Render;
            uint[] textures = new uint[1];
            Gl.GenTextures(1, textures);
            Texture = textures[0];
            Gl.ActiveTexture(GlTextureUnit.Texture0);
            Gl.BindTexture(GlTextureTarget.Texture2d, Texture);
            byte[] pixels =
            {
                255,   0,   0, 255,
                255, 255,   0, 255,
                0,     0, 255, 255,
                0,   255, 255, 255
            };
            Gl.TexParameteri(GlTextureTarget.Texture2d, GlTextureParameterName.TextureMagFilter, GL.LINEAR);
            Gl.TexParameteri(GlTextureTarget.Texture2d, GlTextureParameterName.TextureMinFilter, GL.LINEAR);
            Gl.TexParameteri(GlTextureTarget.Texture2d, GlTextureParameterName.TextureWrapS, GL.CLAMP_TO_EDGE);
            Gl.TexParameteri(GlTextureTarget.Texture2d, GlTextureParameterName.TextureWrapT, GL.CLAMP_TO_EDGE);
            Gl.TexImage2D(GlTextureTarget.Texture2d, 0, GlInternalFormat.Rgba, 2, 2, 0, GlPixelFormat.Rgba, GlPixelType.UnsignedByte, pixels);
            Gl.GenerateMipmap(GlTextureTarget.Texture2d);
            uint vertexShader   = Gl.CreateShader(GlShaderType.VertexShader);
            uint fragmentShader = Gl.CreateShader(GlShaderType.FragmentShader);

            Gl.ShaderSource(vertexShader, 1, new [] { Encoding.ASCII.GetBytes(VertexShader) }, new [] { Encoding.ASCII.GetByteCount(VertexShader) });
            Gl.CompileShader(vertexShader);
            int[] result = new int[1];
            Gl.GetShaderiv(vertexShader, GlShaderParameterName.CompileStatus, result);
            if (((GlBoolean)result[0]) == GlBoolean.False)
            {
                int[] len = new int[1];
                Gl.GetShaderiv(vertexShader, GlShaderParameterName.InfoLogLength, len);
                byte[] log = new byte[len[0]];
                Gl.GetShaderInfoLog(vertexShader, len[0], len, log);
                Console.Error.WriteLine("Unable to compile vertex shader.");
                Console.Error.Write(Encoding.ASCII.GetString(log));
            }
            Gl.ShaderSource(fragmentShader, 1, new [] { Encoding.ASCII.GetBytes(FragmentShader) }, new [] { Encoding.ASCII.GetByteCount(FragmentShader) });
            Gl.CompileShader(fragmentShader);
            Gl.GetShaderiv(fragmentShader, GlShaderParameterName.CompileStatus, result);
            if (((GlBoolean)result[0]) == GlBoolean.False)
            {
                int[] len = new int[1];
                Gl.GetShaderiv(fragmentShader, GlShaderParameterName.InfoLogLength, len);
                byte[] log = new byte[len[0]];
                Gl.GetShaderInfoLog(fragmentShader, len[0], len, log);
                Console.Error.WriteLine("Unable to compile fragment shader.");
                Console.Error.Write(Encoding.ASCII.GetString(log));
            }
            uint program = Gl.CreateProgram();

            Gl.AttachShader(program, vertexShader);
            Gl.AttachShader(program, fragmentShader);
            Gl.LinkProgram(program);
            Gl.GetProgramiv(fragmentShader, GlProgramPropertyARB.LinkStatus, result);
            if (((GlBoolean)result[0]) == GlBoolean.False)
            {
                int[] len = new int[1];
                Gl.GetProgramiv(program, GlProgramPropertyARB.InfoLogLength, len);
                byte[] log = new byte[len[0]];
                Gl.GetProgramInfoLog(program, len[0], len, log);
                Console.Error.WriteLine("Unable to link program.");
                Console.Error.WriteLine(Encoding.ASCII.GetString(log));
            }
            Gl.DetachShader(program, vertexShader);
            Gl.DetachShader(program, fragmentShader);
            Gl.DeleteShader(vertexShader);
            Gl.DeleteShader(fragmentShader);
            Gl.UseProgram(program);
            int loc = Gl.GetUniformLocation(program, Encoding.ASCII.GetBytes("tex\0"));

            Gl.Uniform1i(loc, 0);
        }