A render context.
Inheritance: HiddenWindowRenderContext
Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnSizeChanged(EventArgs e)
        {
            base.OnSizeChanged(e);

            int width = this.Width, height = this.Height;

            if (width > 0 && height > 0)
            {
                FBORenderContext renderContext = this.renderContext;
                if (renderContext != null)
                {
                    renderContext.MakeCurrent();

                    renderContext.SetDimensions(width, height);

                    OpenGL.Viewport(0, 0, width, height);

                    if (this.designMode)
                    {
                        GLCanvasHelper.ResizeGL(width, height);
                    }

                    this.Invalidate();
                }
            }
        }
Beispiel #2
0
        void ISupportInitialize.EndInit()
        {
            int width = this.Width, height = this.Height;

            if (this.designMode)
            {
                this.assist.Resize(width, height);
            }
            else
            {
                this.KeyPress   += WinGLCanvas_KeyPress;
                this.MouseDown  += WinGLCanvas_MouseDown;
                this.MouseMove  += WinGLCanvas_MouseMove;
                this.MouseUp    += WinGLCanvas_MouseUp;
                this.MouseWheel += WinGLCanvas_MouseWheel;
                this.KeyDown    += WinGLCanvas_KeyDown;
                this.KeyUp      += WinGLCanvas_KeyUp;
            }

            // Create the render context.
            const short bitDepth      = 32;
            var         renderContext = new FBORenderContext(width, height, bitDepth);

            renderContext.MakeCurrent();
            this.renderContext = renderContext;

            // Set the most basic OpenGL styles.
            GL.Instance.ShadeModel(GL.GL_SMOOTH);
            GL.Instance.ClearDepth(1.0f);
            GL.Instance.Enable(GL.GL_DEPTH_TEST);// depth test is disabled by default.
            GL.Instance.DepthFunc(GL.GL_LEQUAL);
            GL.Instance.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
        }
Beispiel #3
0
        private void DestroyRenderContext()
        {
            FBORenderContext renderContext = this.renderContext;

            if (renderContext != null)
            {
                this.renderContext = null;
                renderContext.Dispose();
            }
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            FBORenderContext renderContext = this.renderContext;

            if (renderContext == null)
            {
                base.OnPaint(e);
                return;
            }

            stopWatch.Reset();
            stopWatch.Start();

            //	Make sure it's our instance of openSharpGL that's active.
            renderContext.MakeCurrent();

            if (this.designMode)
            {
                try
                {
                    DesignModeRendering();
                }
                catch (Exception)
                {
                }
            }
            else
            {
                //	If there is a draw handler, then call it.
                DoOpenGLDraw(e);
            }

            //	Blit our offscreen bitmap.
            Graphics graphics      = e.Graphics;
            IntPtr   deviceContext = graphics.GetHdc();

            renderContext.Blit(deviceContext);
            graphics.ReleaseHdc(deviceContext);

            stopWatch.Stop();

            {
                ErrorCode error = (ErrorCode)OpenGL.GetError();
                if (error != ErrorCode.NoError)
                {
                    Debug.WriteLine(string.Format("{0}: OpenGL error: {1}", this.fullname, error));
                }
            }

            this.FPS = 1000.0 / stopWatch.Elapsed.TotalMilliseconds;
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void CreateRenderContext()
        {
            // Initialises OpenGL.
            var renderContext = new FBORenderContext();

            //  Create the render context.
            renderContext.Create(Width, Height, 32, null);

            this.RenderContext = renderContext;

            renderContext.MakeCurrent();

            //  Set the most basic OpenGL styles.
            GL.Instance.ShadeModel(GL.GL_SMOOTH);
            GL.Instance.ClearDepth(1.0f);
            GL.Instance.Enable(GL.GL_DEPTH_TEST);// depth test is disabled by default.
            GL.Instance.DepthFunc(GL.GL_LEQUAL);
            GL.Instance.Hint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
        }
Beispiel #6
0
        private void CreateRenderContext()
        {
            // Initialises OpenGL.
            var renderContext = new FBORenderContext();

            //  Create the render context.
            renderContext.Create(OpenGLVersion, Width, Height, 32, null);

            this.renderContext = renderContext;

            renderContext.MakeCurrent();

            //  Set the most basic OpenGL styles.
            OpenGL.ShadeModel(OpenGL.GL_SMOOTH);
            // 天蓝色背景
            OpenGL.ClearColor(0x87 / 255.0f, 0xce / 255.0f, 0xeb / 255.0f, 0xff / 255.0f);
            OpenGL.ClearDepth(1.0f);
            OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
            OpenGL.DepthFunc(OpenGL.GL_LEQUAL);
            OpenGL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void CreateRenderContext()
        {
            // Initialises OpenGL.
            var renderContext = new FBORenderContext();

            //  Create the render context.
            renderContext.Create(Width, Height, 32, null);

            this.renderContext = renderContext;

            renderContext.MakeCurrent();

            //  Set the most basic OpenGL styles.
            OpenGL.ShadeModel(OpenGL.GL_SMOOTH);
            OpenGL.ClearDepth(1.0f);
            OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
            OpenGL.DepthFunc(OpenGL.GL_LEQUAL);
            OpenGL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
            if (this.designMode)
            {
                GLCanvasHelper.ResizeGL(this.Width, this.Height);
            }
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void CreateRenderContext()
        {
            // Initialises OpenGL.
            var renderContext = new FBORenderContext();

            //  Create the render context.
            renderContext.Create(Width, Height, 32, null);

            this.renderContext = renderContext;

            renderContext.MakeCurrent();

            //  Set the most basic OpenGL styles.
            OpenGL.ShadeModel(OpenGL.GL_SMOOTH);
            OpenGL.ClearDepth(1.0f);
            OpenGL.Enable(OpenGL.GL_DEPTH_TEST);
            OpenGL.DepthFunc(OpenGL.GL_LEQUAL);
            OpenGL.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
            if (this.designMode)
            {
                GLCanvasHelper.ResizeGL(this.Width, this.Height);
            }
        }
Beispiel #9
0
 private void DestroyRenderContext()
 {
     FBORenderContext renderContext = this.renderContext;
     if (renderContext != null)
     {
         this.renderContext = null;
         renderContext.Dispose();
     }
 }