コード例 #1
0
        /// <summary>
        /// 在多个buffer中拾取一个图元
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="pickableElements"></param>
        public static void Render4Picking(RenderEventArgs arg, params PickableRenderer[] pickableElements)
        {
            if (arg.RenderMode != RenderModes.ColorCodedPicking)
            {
                throw new ArgumentException();
            }

            // record clear color
            var originalClearColor = new float[4];

            OpenGL.GetFloat(GetTarget.ColorClearValue, originalClearColor);

            // 白色意味着没有拾取到任何对象
            // white color: nothing picked.
            OpenGL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            // restore clear color
            OpenGL.ClearColor(originalClearColor[0], originalClearColor[1], originalClearColor[2], originalClearColor[3]);

            uint renderedVertexCount = 0;

            foreach (var pickable in pickableElements)
            {
                if (pickable == null)
                {
                    continue;
                }

                pickable.PickingBaseId = renderedVertexCount;

                //  render the element for picking.
                pickable.Render(arg);

                uint rendered = renderedVertexCount + pickable.GetVertexCount();
                if (renderedVertexCount <= rendered)
                {
                    renderedVertexCount = rendered;
                }
                else
                {
                    throw new Exception(string.Format(
                                            "Too many geometries({0} + {1} > {2}) for color coded picking.",
                                            renderedVertexCount, pickable.GetVertexCount(), uint.MaxValue));
                }
            }

            OpenGL.Flush();
        }
コード例 #2
0
        protected override void OnPaint(PaintEventArgs e)
        {
            RenderContext renderContext = this.renderContext;

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

            stopWatch.Restart();

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

            if (this.designMode)
            {
                // 天蓝色背景
                OpenGL.ClearColor(0x87 / 255.0f, 0xce / 255.0f, 0xeb / 255.0f, 0xff / 255.0f);

                GLCanvasHelper.ResizeGL(this.Width, this.Height);

                GLCanvasHelper.DrawPyramid();
            }
            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();

            this.FPS = 1000.0 / stopWatch.Elapsed.TotalMilliseconds;
        }
コード例 #3
0
ファイル: GLSceneCanvas.cs プロジェクト: hhxx1314/CSharpGL
        /// <summary>
        ///
        /// </summary>
        protected virtual void DesignModeRender()
        {
            // Sky blue fore background.
            //OpenGL.ClearColor(0x87 / 255.0f, 0xce / 255.0f, 0xeb / 255.0f, 0xff / 255.0f);
            OpenGL.ClearColor(0, 0, 0, 0);

            //  Clear the color and depth buffer.
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            GLCanvasHelper.DrawClock();

            OpenGL.DrawText(10,
                            10, Color.White, "Courier New",// "Courier New",
                            25.0f, this.GetType().FullName);
            if (this.RenderTrigger == RenderTrigger.TimerBased)
            {
                OpenGL.DrawText(10,
                                this.Height - 20 - 1, Color.Red, "Courier New",// "Courier New",
                                20.0f, string.Format("FPS: {0}", this.FPS.ToShortString()));
            }
        }
コード例 #4
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);
        }
コード例 #5
0
        private List <IColorCodedPicking> Render4Picking(RenderEventArgs arg)
        {
            // record clear color
            var originalClearColor = new float[4];

            OpenGL.GetFloat(GetTarget.ColorClearValue, originalClearColor);

            // white color means nothing picked.
            OpenGL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            // restore clear color
            OpenGL.ClearColor(originalClearColor[0], originalClearColor[1], originalClearColor[2], originalClearColor[3]);

            uint renderedVertexCount = 0;
            var  pickedRendererList  = new List <IColorCodedPicking>();

            RenderPickableObject(this.rootObject, arg, ref renderedVertexCount, pickedRendererList);

            OpenGL.Flush();

            return(pickedRendererList);
        }
コード例 #6
0
        /// <summary>
        /// 在此Buffer中的图元进行N选1
        /// select a line from triangle/quad/polygon in this renderer.
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="indexBufferPtr">indicates the primitive to pick a line from.</param>
        internal void Render4InnerPicking(RenderEventArgs arg, IndexBufferPtr indexBufferPtr)
        {
            // record clear color
            var originalClearColor = new float[4];

            OpenGL.GetFloat(GetTarget.ColorClearValue, originalClearColor);

            // 白色意味着没有拾取到任何对象
            // white color: nothing picked.
            OpenGL.ClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            OpenGL.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT | OpenGL.GL_STENCIL_BUFFER_BIT);

            // restore clear color
            OpenGL.ClearColor(originalClearColor[0], originalClearColor[1], originalClearColor[2], originalClearColor[3]);

            this.ColorCodedRender(arg, indexBufferPtr);

            OpenGL.Flush();

            //var filename = string.Format("Render4InnerPicking{0:yyyy-MM-dd_HH-mm-ss.ff}.png", DateTime.Now);
            //Save2PictureHelper.Save2Picture(0, 0,
            //    e.CanvasRect.Width, e.CanvasRect.Height, filename);
        }
コード例 #7
0
 /// <summary>
 ///
 /// </summary>
 protected override void SwitchOff()
 {
     OpenGL.ClearColor(original[0], original[1], original[2], original[3]);
 }