コード例 #1
0
        static void DrawGradient(Controls.OpenGL.GLControl glControl)
        {
            if (SceneBackground == null)
            {
                SceneBackground           = new STLModel3D();
                SceneBackground.Triangles = new TriangleInfoList();

                var gradientColor1 = new Byte4Class(255, 19, 20, 21);
                var gradientColor2 = new Byte4Class(255, 39, 42, 61);

                var triangle = new Triangle();
                triangle.Vectors[0].Position = new Vector3Class(-1f, -1f, 0f);
                triangle.Vectors[0].Color    = gradientColor2;
                triangle.Vectors[1].Position = new Vector3Class(1f, 1f, 0);
                triangle.Vectors[1].Color    = gradientColor1;
                triangle.Vectors[2].Position = new Vector3Class(-1f, 1f, 0);
                triangle.Vectors[2].Color    = gradientColor1;

                SceneBackground.Triangles[0].Add(triangle);

                triangle = new Triangle();
                triangle.Vectors[0].Position = new Vector3Class(-1f, -1f, 0f);
                triangle.Vectors[0].Color    = gradientColor2;
                triangle.Vectors[1].Position = new Vector3Class(1f, -1f, 0);
                triangle.Vectors[1].Color    = gradientColor2;
                triangle.Vectors[2].Position = new Vector3Class(1f, 1f, 0);
                triangle.Vectors[2].Color    = gradientColor1;

                SceneBackground.Triangles[0].Add(triangle);

                SceneBackground.Loaded = true;
                SceneBackground.BindModel();
                SceneBackground.UpdateBinding();
            }

            GL.Viewport(0, 0, glControl.Width, glControl.Height);
            GL.MatrixMode(MatrixMode.Projection);
            GL.LoadIdentity();
            GL.MatrixMode(MatrixMode.Modelview);
            GL.LoadIdentity();
            GL.Disable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Lighting);
            GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);

            GL.EnableClientState(ArrayCap.ColorArray);
            GL.EnableClientState(ArrayCap.VertexArray);

            foreach (var vboIndex in SceneBackground.VBOIndexes)
            {
                GL.BindBuffer(BufferTarget.ArrayBuffer, vboIndex);
                GL.ColorPointer(4, ColorPointerType.UnsignedByte, Vertex.Stride, new IntPtr(0));
                GL.VertexPointer(3, VertexPointerType.Float, Vertex.Stride, 4);
                GL.DrawArrays(PrimitiveType.Triangles, 0, SceneBackground.Triangles[0].Count * 3);
            }

            GL.DisableClientState(ArrayCap.ColorArray);
            GL.DisableClientState(ArrayCap.VertexArray);

            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Lighting);
        }
コード例 #2
0
        public static void RenderAsModelView(Controls.OpenGL.GLControl glControl, float cameraRotationX, float cameraRotationZ, float cameraZoom, float panX, float panY, bool thumbnailRendering = false, bool thumbnailLarge = false)
        {
            try
            {
                if (glControl.Context.IsCurrent)
                {
                    GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit | ClearBufferMask.ColorBufferBit);

                    if (!thumbnailRendering)
                    {
                        DrawGradient(glControl);

                        //GL.ClearColor(Settings.Default.SceneBackgroundColor);
                        if (UserProfileManager.UserProfiles[0].SelectionOptions_Enable_XYZ_Axis)
                        {
                            DrawOrientationGizmo();
                        }
                    }
                    else
                    {
                        if (!thumbnailLarge)
                        {
                            GL.ClearColor(Color.White);
                        }
                        else
                        {
                            GL.ClearColor(Color.FromArgb(230, 230, 230, 230));
                        }
                    }

                    int w = glControl.Width;
                    int h = glControl.Height;

                    float aspectRatio = (float)w / (float)h;

                    GL.Viewport(0, 0, w, h);

                    ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView(0.55f, aspectRatio, 1, 2000);

                    GL.MatrixMode(MatrixMode.Projection);
                    GL.LoadIdentity();
                    GL.LoadMatrix(ref ProjectionMatrix);

                    GL.MatrixMode(MatrixMode.Modelview);
                    GL.LoadIdentity();

                    OrbitCamera = new OrbitCameraController(CameraPositionTargetCenter);
                    OrbitCamera.MouseMove(cameraRotationX, cameraRotationZ);
                    OrbitCamera.Pan(panX, panY);
                    OrbitCamera.Scroll(_defaultCameraDistance + cameraZoom);

                    var lookat = OrbitCamera.GetCameraView();
                    CameraPosition = OrbitCamera.GetCameraPosition();

                    //GL.Matrix
                    GL.LoadMatrix(ref lookat);
                }
            }
            catch (Exception exc)
            {
                Debug.WriteLine(exc.Message);
            }
        }