Пример #1
0
        private void RenderPatternCube()
        {
            PatternShaderProgram.Activate();
            GL.PushMatrix();
            GL.Scale(.35, .35, .35);
            GLHelpers.Cube2D(1.99f);
            GL.PopMatrix();

            ShaderProgram.DisableShaders();
        }
Пример #2
0
        /// <summary>Setup the various GL crap</summary>
        private void InitializeGL()
        {
            GLHelpers.ClearColor(ClearColor);
            GL.Enable(EnableCap.DepthTest);

            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.PolygonSmooth);

            //transformInner.Location = new Vector3(0, 0, -4);
            //transformInner.Scale = new Vector3(.8f, .8f, .8f);

            InitializeView();
        }
Пример #3
0
        private void RenderTexturedPlane()
        {
            GL.PushAttrib(AttribMask.TextureBit | AttribMask.EnableBit);
            LightingShaderProgram.Texture1 = FileTexture;
            //FileTexture.Bind();
            LightingShaderProgram.Activate();

            GL.PushMatrix();
            float width = FileTexture.Picture.Width / (float)FileTexture.Picture.Height;

            GLHelpers.PlaneMesh(width, 1, 3, -0.25f);
            GL.PopMatrix();

            ShaderProgram.DisableShaders();
            GL.PopAttrib();
        }
Пример #4
0
        private void GLElement_GLRenderStarted(object sender, EventArgs e)
        {
            #region FBO start
            if (UseFrameBuffer)
            {
                FBO.Activate();
                FBO.FBOInitializeView(GLElement1.PerspectiveProjection, TransformOuter.Location.Z);
            }
            else
            {
                FBO.Deactivate();
            }
            #endregion

            RenderToBuffer();

            #region FBO finish
            if (UseFrameBuffer)
            {
                FBO.Deactivate();

                GLElement1.InitializeView();
                GL.ClearColor(0, .3f, .5f, 1);
                GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
                GL.LoadIdentity();

                // Now bind the texture to use it
                GL.ActiveTexture(TextureUnit.Texture0);
                FBO.Bind();
                GLHelpers.Color4(Colors.Black); // to prevent it from being transparent

                // Tranform
                TransformOuter.Apply();

                // Render with shader
                LightingShaderProgram.Texture1 = FBO.Texture;
                LightingShaderProgram.Activate();
                //GLHelpers.Plane(1.3, 1.3, 0); // put it on a plane
                GLHelpers.Cube2D(1.7); // put it on a cube

                // Do some cleanup
                TransformOuter.Remove();
                Texture2D.Disable2DTextures();
                ShaderProgram.DisableShaders();
            }
            #endregion
        }
Пример #5
0
        /// <summary>Render the inner scene</summary>
        private void RenderToBuffer()
        {
            // transform
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GLElement1.TransformInner.Apply();

            // set up
            GLHelpers.ClearColor(GLElement1.ClearColor);
            GLHelpers.Color4(Colors.White);
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.ShadeModel(ShadingModel.Smooth);
            GL.Enable(EnableCap.PointSmooth);

            // render the content
            if (chkSFM.IsChecked.HasValue && chkSFM.IsChecked.Value)
            {
                RenderSFM();
            }
            if (chkPatternCube.IsChecked.HasValue && chkPatternCube.IsChecked.Value)
            {
                RenderPatternCube();
            }
            if (chkTexturedCube.IsChecked.HasValue && chkTexturedCube.IsChecked.Value)
            {
                RenderTexturedCube(chkLightCubes.IsChecked.HasValue & chkLightCubes.IsChecked.Value);
            }
            if (chkTexturedPlane.IsChecked.HasValue && chkTexturedPlane.IsChecked.Value)
            {
                RenderTexturedPlane();
            }
            if (chkMouseControl.IsChecked.HasValue && chkMouseControl.IsChecked.Value)
            {
                DrawUserStudySelection();
            }

            // cleanup
            GLElement1.TransformInner.Remove();
            ShaderProgram.DisableShaders();
            GL.ActiveTexture(TextureUnit.Texture0);
            Texture2D.Disable2DTextures();
        }
Пример #6
0
        private void RenderTexturedCube(bool useShader)
        {
            GL.PushAttrib(AttribMask.TextureBit | AttribMask.EnableBit);
            if (useShader)
            {
                GLHelpers.Color4(Colors.Transparent);
                LightingShaderProgram.Texture1 = CirclesTexture;
                LightingShaderProgram.Activate();
            }
            else
            {
                GLHelpers.Color4(Colors.Black);
                GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Replace);
                //GL.TexEnv(TextureEnvTarget.TextureEnv, TextureEnvParameter.TextureEnvMode, (int)TextureEnvMode.Decal);
                CirclesTexture.Bind();
            }

            var transformCube = new TransformGL(new Vector3(-.4f, -.4f, 0));

            transformCube.Apply();
            GLHelpers.Cube2D(.5);
            transformCube.Remove();

            transformCube.Location = new Vector3(0, 0, 0);
            transformCube.Apply();
            GLHelpers.Cube2D(.25);
            transformCube.Remove();

            transformCube.Location = new Vector3(.2f, .2f, 0);
            transformCube.Apply();
            GLHelpers.Cube2D(.125);
            transformCube.Remove();

            transformCube.Location = new Vector3(.3f, .3f, 0);
            transformCube.Apply();
            GLHelpers.Cube2D(.06125);
            transformCube.Remove();

            // cleanup
            ShaderProgram.DisableShaders();
            GL.PopAttrib();
        }
Пример #7
0
        /// <summary>
        /// Creates the frame buffer.
        /// </summary>
        protected override void CreateFrameBuffer()
        {
            if (this.counter > 1)
            {
                return;
            }

            this.counter++;

            if (this.isPaused)
            {
                return;
            }

            if (!UIDevice.CurrentDevice.CheckSystemVersion(8, 0) &&
                (UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeLeft || UIApplication.SharedApplication.StatusBarOrientation == UIInterfaceOrientation.LandscapeRight))
            {
                this.Bounds = new RectangleF(0, 0, (float)this.Bounds.Height, (float)this.Bounds.Width);
            }

            this.screenWidth  = (int)(this.Bounds.Width * this.ContentScaleFactor);
            this.screenHeight = (int)(this.Bounds.Height * this.ContentScaleFactor);

            base.CreateFrameBuffer();

            if (this.depthFramebuffer > 0)
            {
                GL.DeleteFramebuffers(1, ref this.depthFramebuffer);
                this.depthFramebuffer = 0;
            }

            GL.BindFramebuffer(FramebufferTarget.Framebuffer, this.Framebuffer);

            GL.GenRenderbuffers(1, out this.depthFramebuffer);
            GL.BindRenderbuffer(RenderbufferTarget.Renderbuffer, this.depthFramebuffer);
            GL.RenderbufferStorage(RenderbufferTarget.Renderbuffer, RenderbufferInternalFormat.DepthComponent16, this.screenWidth, this.screenHeight);
            GL.FramebufferRenderbuffer(FramebufferTarget.Framebuffer, FramebufferSlot.DepthAttachment, RenderbufferTarget.Renderbuffer, this.depthFramebuffer);

            GLHelpers.InitExtensionList();
        }
Пример #8
0
        public UnoGLControl()
        {
            Toolkit.Init(new ToolkitOptions
            {
                Backend = PlatformBackend.PreferNative
            });

            SetStyle(ControlStyles.Opaque, true);
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);

            DoubleBuffered = false;
            Dock           = DockStyle.Fill;

            _glWindow  = Utilities.CreateWindowsWindowInfo(Handle);
            _glContext = GLHelpers.CreateContext(_glWindow);
            _glContext.SwapInterval = 0; // We do vsync in the form

            CoreWindow = new WinFormsPlatformWindow(this);
            CoreGC     = new WinFormsGraphicsContext(this);
            GL         = new GL();
        }
Пример #9
0
 private void DrawUserStudySelection()
 {
     GL.LineWidth(4);
     GLHelpers.Color4(Color.FromArgb(50, 255, 0, 0));
     Texture2D.Disable2DTextures();
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
     using (OpenGL.GLDraw.Begin(BeginMode.Quads))
     {
         GL.Vertex3(MouseQuadrant.Left, MouseQuadrant.Top, -.02f);
         GL.Vertex3(MouseQuadrant.Right, MouseQuadrant.Top, -.02f);
         GL.Vertex3(MouseQuadrant.Right, MouseQuadrant.Bottom, -.02f);
         GL.Vertex3(MouseQuadrant.Left, MouseQuadrant.Bottom, -.02f);
     }
     GLHelpers.Color4(Color.FromArgb(50, 255, 0, 0));
     GL.LineWidth(12);
     using (OpenGL.GLDraw.Begin(BeginMode.Quads))
     {
         GL.Vertex3(SelectedQuadrant.Left, SelectedQuadrant.Top, -.01f);
         GL.Vertex3(SelectedQuadrant.Right, SelectedQuadrant.Top, -.01f);
         GL.Vertex3(SelectedQuadrant.Right, SelectedQuadrant.Bottom, -.01f);
         GL.Vertex3(SelectedQuadrant.Left, SelectedQuadrant.Bottom, -.01f);
     }
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
 }