Ortho() приватный Метод

private Ortho ( double left, double right, double bottom, double top, double zNear, double zFar ) : void
left double
right double
bottom double
top double
zNear double
zFar double
Результат void
Пример #1
0
        /// <summary>
        /// 实施传统方式的投影
        /// </summary>
        /// <param name="camera"></param>
        public static void LegacyGLProjection(this ICamera camera)
        {
            //	Load the projection identity matrix.
            OpenGL.MatrixMode(OpenGL.GL_PROJECTION);
            OpenGL.LoadIdentity();

            //	Perform the projection.
            switch (camera.CameraType)
            {
            case CameraType.Perspecitive:
                IPerspectiveCamera perspectiveCamera = camera;
                OpenGL.gluPerspective(perspectiveCamera.FieldOfView, perspectiveCamera.AspectRatio, perspectiveCamera.Near, perspectiveCamera.Far);
                break;

            case CameraType.Ortho:
                IOrthoCamera orthoCamera = camera;
                OpenGL.Ortho(orthoCamera.Left, orthoCamera.Right, orthoCamera.Bottom, orthoCamera.Top, orthoCamera.Near, orthoCamera.Far);
                break;

            default:
                break;
            }

            //  Perform the look at transformation.
            OpenGL.gluLookAt((double)camera.Position.x, (double)camera.Position.y, (double)camera.Position.z,
                             (double)camera.Target.x, (double)camera.Target.y, (double)camera.Target.z,
                             (double)camera.UpVector.x, (double)camera.UpVector.y, (double)camera.UpVector.z);

            //	Back to the modelview matrix.
            OpenGL.MatrixMode(OpenGL.GL_MODELVIEW);
        }
Пример #2
0
        /// <summary>
        /// Draws the text.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="color"></param>
        /// <param name="faceName"></param>
        /// <param name="fontSize"></param>
        /// <param name="text"></param>
        public static void DrawText(int x, int y, Color color, string faceName, float fontSize, string text)
        {
            IntPtr renderContext = Win32.wglGetCurrentContext();
            IntPtr deviceContext = Win32.wglGetCurrentDC();

            //  Get the font size in pixels.
            var fontHeight = (int)(fontSize * (16.0f / 12.0f));

            //  Do we have a font bitmap entry for this OpenGL instance and face name?
            var result = (from fbe in fontBitmapEntries
                          where fbe.HDC == deviceContext &&
                          fbe.HRC == renderContext &&
                          String.Compare(fbe.FaceName, faceName, StringComparison.OrdinalIgnoreCase) == 0 &&
                          fbe.Height == fontHeight
                          select fbe).ToList();

            //  Get the FBE or null.
            var fontBitmapEntry = result.FirstOrDefault();

            //  If we don't have the FBE, we must create it.
            if (fontBitmapEntry == null)
            {
                fontBitmapEntry = CreateFontBitmapEntry(faceName, fontHeight);
            }

            int[]  viewport = OpenGL.GetViewport();
            double width    = viewport[2];
            double height   = viewport[3];

            //  Create the appropriate projection matrix.
            OpenGL.MatrixMode(OpenGL.GL_PROJECTION);
            OpenGL.PushMatrix();
            OpenGL.LoadIdentity();

            OpenGL.Ortho(0, width, 0, height, -1, 1);

            //  Create the appropriate modelview matrix.
            OpenGL.MatrixMode(OpenGL.GL_MODELVIEW);
            OpenGL.PushMatrix();
            OpenGL.LoadIdentity();
            //GL.Color(color.R, color.G, color.B);
            //GL.RasterPos2i(x, y);

            //GL.PushAttrib(GL.GL_LIST_BIT | GL.GL_CURRENT_BIT |
            //    GL.GL_ENABLE_BIT | GL.GL_TRANSFORM_BIT);
            OpenGL.Color3ub(color.R, color.G, color.B);
            //GL.Disable(GL.GL_LIGHTING);
            //GL.Disable(GL.GL_TEXTURE_2D);
            //GL.Disable(GL.GL_DEPTH_TEST);
            OpenGL.RasterPos2i(x, y);

            //  Set the list base.
            OpenGL.ListBase(fontBitmapEntry.ListBase);

            //  Create an array of lists for the glyphs.
            var lists = text.Select(c => (byte)c).ToArray();

            //  Call the lists for the string.
            OpenGL.CallLists(lists.Length, OpenGL.GL_UNSIGNED_BYTE, lists);
            OpenGL.Flush();

            ////  Reset the list bit.
            //GL.PopAttrib();

            //  Pop the modelview.
            OpenGL.PopMatrix();

            //  back to the projection and pop it, then back to the model view.
            OpenGL.MatrixMode(OpenGL.GL_PROJECTION);
            OpenGL.PopMatrix();
            OpenGL.MatrixMode(OpenGL.GL_MODELVIEW);
        }