public static void ResizeGL(double width, double height) { // Set the projection matrix. OpenGL.MatrixMode(OpenGL.GL_PROJECTION); // Load the identity. OpenGL.LoadIdentity(); //// Create a perspective transformation. //OpenGL.gluPerspective(60.0f, width / height, 0.01, 100.0); mat4 projectionMatrix = glm.perspective(glm.radians(60.0f), (float)(width / height), 0.01f, 100.0f); OpenGL.MultMatrixf((projectionMatrix * viewMatrix).ToArray()); // Set the modelview matrix. OpenGL.MatrixMode(OpenGL.GL_MODELVIEW); }
//static PyramidVAOElement pyramidVAOElement = new PyramidVAOElement(); //static GLCanvasHelper() //{ // pyramidVAOElement.Initialize(); //} //public static void DrawWithElement() //{ // pyramidVAOElement.Render(new RenderEventArgs(RenderModes.Render, this.camera)); //} public static void ResizeGL(double width, double height) { // Set the projection matrix. OpenGL.MatrixMode(OpenGL.GL_PROJECTION); // Load the identity. OpenGL.LoadIdentity(); // Create a perspective transformation. OpenGL.gluPerspective(60.0f, width / height, 0.01, 100.0); // Use the 'look at' helper function to position and aim the camera. OpenGL.gluLookAt(-5, 5, -5, 0, 0, 0, 0, 1, 0); // Set the modelview matrix. OpenGL.MatrixMode(OpenGL.GL_MODELVIEW); }
/// <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); }