Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="e"></param>
        protected override void OnPaint(PaintEventArgs e)
        {
            GLRenderContext 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
                {
                    GL.Instance.ClearColor(clearColor.x, clearColor.y, clearColor.z, clearColor.w);
                    GL.Instance.Clear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT | GL.GL_STENCIL_BUFFER_BIT);

                    //this.assist.Render(this.RenderTrigger == RenderTrigger.TimerBased, this.Height, this.FPS, this);
                }
                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();

            {
                GL gl = GL.Instance;
                if (gl != null)
                {
                    ErrorCode error = (ErrorCode)gl.GetError();
                    if (error != ErrorCode.NoError)
                    {
                        string str = string.Format("{0}: OpenGL error: {1}", this.GetType().FullName, error);
                        Debug.WriteLine(str);
                        Log.Write(str);
                    }
                }
            }

            this.FPS = 1000.0 / stopWatch.Elapsed.TotalMilliseconds;
        }
        /// <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)
            {
                CSharpGL.GLRenderContext renderContext = this.renderContext;
                if (renderContext != null)
                {
                    renderContext.MakeCurrent();

                    renderContext.SetDimensions(width, height);

                    GL.Instance.Viewport(0, 0, width, height);

                    if (this.designMode)
                    {
                        //this.assist.Resize(width, height);
                    }
                    else
                    {
                        Bitmap bmp = this.bitmap;
                        this.bitmap = new Bitmap(width, height);
                        if (bmp != null)
                        {
                            bmp.Dispose();
                        }
                    }

                    this.Invalidate();
                }
            }
        }
Example #3
0
        /// <summary>
        /// Make render context in this Canvas the current one in the thread.
        /// </summary>
        public void MakeCurrent()
        {
            GLRenderContext renderContext = this.renderContext;

            if (renderContext != null)
            {
                renderContext.MakeCurrent();
            }
        }