Esempio n. 1
0
        public void RenderScreenSpace(RenderInfo info, Matrix4x4 transformMatrix, Viewport viewport)
        {
            if (info.showAnnotations)
            {
                Font font = new Font("Calibri", 12.0f * 0.75f);
                List <DebugRenderPrimitive> primitivesToRender = GetCachedPrimitives();
                foreach (DebugRenderPrimitive primitive in primitivesToRender)
                {
                    if (primitive.Annotation != null && primitive.Annotation.IsValidAt(info.time))
                    {
                        Vector3 screenPosition = GeometryMath.Project(primitive.WorldBounds.Center, transformMatrix, viewport);
                        if (screenPosition.z >= 0.0)
                        {
                            Size    textSize     = TextRenderer.MeasureText(primitive.Annotation.Text, font);
                            Vector3 textHalfSize = new Vector3((double)textSize.Width, (double)textSize.Height, 0.0) * 0.5;

                            OpenGLDrawHelper.FillRectangle(DebugRenderControl.gl, screenPosition - textHalfSize, screenPosition + textHalfSize, primitive.Annotation.Color.Brightness > 0.5 ? new Color32(0, 0, 0, 255) : new Color32(255, 255, 255, 255), false);

                            DebugRenderControl.gl.DrawText((int)(screenPosition.x - textHalfSize.x) + 2, (int)(screenPosition.y - textHalfSize.y * 0.4),
                                                           primitive.Annotation.Color.R, primitive.Annotation.Color.G, primitive.Annotation.Color.B,
                                                           "Calibri", 12.0f, primitive.Annotation.Text);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the OpenGLDraw event of the OpenGLControl control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="args">The <see cref="SharpGL.SceneGraph.OpenGLEventArgs"/> instance containing the event data.</param>
        private void OpenGLControl_OpenGLDraw(object sender, RenderEventArgs args)
        {
            OpenGL gl = openGLControl.OpenGL;

            gl.ClearColor((float)ClearColor.R_Double, (float)ClearColor.G_Double, (float)ClearColor.B_Double, (float)ClearColor.A_Double);
            gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);

            UpdateCamera();

            // Render grid (helper)
            if (RenderInfo.showGrid)
            {
                OpenGLDrawHelper.DrawGrid_XY(gl, Session.DebugRenderStorage.GetBounds(RenderInfo.time), 4, 5, GridColor);
            }

            // Render 3D
            RenderInfo.time = Session.PlaybackPosition;
            Session.DebugRenderStorage.Render(RenderInfo);

            lock (RenderInfo)
            {
                // Render selection
                if (RenderInfo.Selection != null)
                {
                    int     second         = DateTime.Now.Second;
                    Color32 selectionColor = second % 2 == 0 ? new Color32(255, 255, 255, 255) : new Color32(0, 0, 0, 255);

                    OpenGLDrawHelper.DrawBounds(gl, RenderInfo.Selection.Primitive.WorldBounds, selectionColor, true);

                    if (RenderInfo.Selection.SelectedTriangleIndex >= 0)
                    {
                        Vector3 a, b, c;
                        if (RenderInfo.Selection.Primitive.GetTriangle(RenderInfo.Selection.SelectedTriangleIndex, RenderInfo.Selection.SelectedTriangleIsOpaque, out a, out b, out c))
                        {
                            if (!RenderInfo.Selection.SelectedTriangleIsOpaque)
                            {
                                selectionColor.A_Double = 0.5;
                            }

                            OpenGLDrawHelper.DrawTriangle(gl, a, b, c, selectionColor, true);
                        }
                    }
                }

                // Render highlight

                if (RenderInfo.Highlight != null)
                {
                    int     second         = DateTime.Now.Second;
                    Color32 selectionColor = second % 2 == 0 ? new Color32(255, 255, 0, 255) : new Color32(128, 128, 128, 255);

                    OpenGLDrawHelper.DrawBounds(gl, RenderInfo.Highlight.Primitive.WorldBounds, selectionColor, true);

                    if (RenderInfo.Highlight.SelectedTriangleIndex >= 0)
                    {
                        Vector3 a, b, c;
                        if (RenderInfo.Highlight.Primitive.GetTriangle(RenderInfo.Highlight.SelectedTriangleIndex, RenderInfo.Highlight.SelectedTriangleIsOpaque, out a, out b, out c))
                        {
                            if (!RenderInfo.Highlight.SelectedTriangleIsOpaque)
                            {
                                selectionColor.A_Double = 0.5;
                            }

                            OpenGLDrawHelper.DrawTriangle(gl, a, b, c, selectionColor, true);
                        }
                    }
                }
            }

            // Render 2D (Screen-space)
            gl.PushAttrib(OpenGL.GL_ENABLE_BIT);
            gl.Disable(OpenGL.GL_DEPTH_TEST);

            double aspect = Viewport.width / Viewport.height;

            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Perspective(60.0, aspect, 0.0, 10.0);

            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();

            OpenGLDrawHelper.DrawAxis(gl, new Vector3(-1.0 * aspect, -1.0, -2.0), CurrentCamera.Direction, CurrentCamera.UpDirection, 0.2);
            gl.MatrixMode(OpenGL.GL_PROJECTION);
            gl.LoadIdentity();
            gl.Ortho2D(0, Viewport.width, 0, Viewport.height);

            gl.MatrixMode(OpenGL.GL_MODELVIEW);
            gl.LoadIdentity();

            Session.DebugRenderStorage.RenderScreenSpace(RenderInfo, ProjectionMatrix, Viewport);

            gl.PopAttrib();
        }