public void Draw() { GL.Enable(EnableCap.DepthTest); GL.Disable(EnableCap.CullFace); bool isLighting = GL.IsEnabled(EnableCap.Lighting); bool isTexture = GL.IsEnabled(EnableCap.Texture2D); bool isBlend = GL.IsEnabled(EnableCap.Blend); GL.Disable(EnableCap.Lighting); uint ndim = VertexArray.Dimension; //////////////////////////////////////////////////////////////// // モデルの描画 ///////////// // vertex arrayを登録する GL.EnableClientState(ArrayCap.VertexArray); GL.VertexPointer((int)ndim, VertexPointerType.Double, 0, VertexArray.VertexCoordArray); if (isTexture && VertexArray.UVCoordArray != null) { GL.EnableClientState(ArrayCap.TextureCoordArray); GL.TexCoordPointer(2, TexCoordPointerType.Double, 0, VertexArray.UVCoordArray); GL.MatrixMode(MatrixMode.Texture); GL.LoadIdentity(); GL.Translate(-TexCentX, -TexCentY, 0.0); } GL.PointSize(PointSize); GL.LineWidth(LineWidth); for (int idp = 0; idp < DrawParts.Count; idp++) { CadObject2DDrawPart dp = DrawParts[idp]; if (dp.ShowMode == -1) { continue; } double height = dp.Height; double dispX = dp.DispX; double dispY = dp.DispY; if (dp.Type == CadElementType.Vertex) { GL.Disable(EnableCap.Texture2D); if (dp.ShowMode == 1) { GL.Color3(1.0, 1.0, 0.0); } else if (dp.ShowMode == 2) { GL.Color3(SelectedColor); } else { GL.Color3(0.0, 0.0, 0.0); } GL.Translate(0.0, 0.0, height); dp.DrawElements(); GL.Translate(0.0, 0.0, -height); if (isTexture) { GL.Enable(EnableCap.Texture2D); } } if (dp.Type == CadElementType.Edge) { GL.Disable(EnableCap.Texture2D); GL.LineWidth(LineWidth); if (IsAntiAliasing) { GL.Enable(EnableCap.LineSmooth); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Hint(HintTarget.LineSmoothHint, HintMode.DontCare); } if (dp.ShowMode == 1) { GL.Color3(1.0, 1.0, 0.0); } else if (dp.ShowMode == 2) { GL.Color3(SelectedColor); } else { //2019-03-11 エッジの色 FIX //GL.Color3(0, 0, 0); GL.Color3(dp.Color); } GL.Translate(0.0, 0.0, height); dp.DrawElements(); if (dp.ShowMode > 0) { // draw ctrl point GL.Begin(PrimitiveType.Points); for (int icp = 0; icp < dp.CtrlPoints.Count; icp++) { OpenTK.Vector2d cp = dp.CtrlPoints[icp]; GL.Vertex3(cp.X, cp.Y, 0.0); } GL.End(); // draw line between ctrl point and point GL.Enable(EnableCap.LineStipple); GL.LineStipple(1, 0xF0F0); GL.PolygonStipple(Mask); GL.LineWidth(1); GL.Begin(PrimitiveType.Lines); uint sVI = dp.Indexs[0]; uint eVI = dp.Indexs[dp.ElemCount * dp.ElemPtCount - 1]; double[] va = VertexArray.VertexCoordArray; OpenTK.Vector2d sPt = new OpenTK.Vector2d(va[sVI * 2 + 0], va[sVI * 2 + 1]); OpenTK.Vector2d ePt = new OpenTK.Vector2d(va[eVI * 2 + 0], va[eVI * 2 + 1]); if (dp.CurveType == CurveType.CurveArc) { OpenGLUtils.GLVertex2(sPt); OpenGLUtils.GLVertex2(dp.CtrlPoints[0]); OpenGLUtils.GLVertex2(ePt); OpenGLUtils.GLVertex2(dp.CtrlPoints[0]); } if (dp.CurveType == CurveType.CurveBezier) { OpenGLUtils.GLVertex2(sPt); OpenGLUtils.GLVertex2(dp.CtrlPoints[0]); OpenGLUtils.GLVertex2(ePt); OpenGLUtils.GLVertex2(dp.CtrlPoints[1]); } GL.End(); GL.Disable(EnableCap.LineStipple); } GL.Translate(0.0, 0.0, -height); GL.Disable(EnableCap.LineSmooth); GL.Disable(EnableCap.Blend); if (isTexture) { GL.Enable(EnableCap.Texture2D); } } else if (dp.Type == CadElementType.Loop) { GL.Disable(EnableCap.Blend); if (dp.ShowMode > 0) { GL.Enable(EnableCap.PolygonStipple); GL.PolygonStipple(Mask); if (dp.ShowMode == 1) { GL.Color3(1.0, 1.0, 0.0); } else if (dp.ShowMode == 2) { GL.Color3(SelectedColor); } GL.Translate(0.0, 0.0, +height + 0.001); dp.DrawElements(); GL.Translate(0.0, 0.0, -height - 0.001); GL.Disable(EnableCap.PolygonStipple); } if (dp.ShowMode != 0) { continue; } GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, dp.Color); GL.Color3(dp.Color); GL.Translate(+dispX, +dispY, +height); dp.DrawElements(); GL.Translate(-dispX, -dispY, -height); } } GL.DisableClientState(ArrayCap.VertexArray); GL.DisableClientState(ArrayCap.TextureCoordArray); if (isLighting) { GL.Enable(EnableCap.Lighting); } else { GL.Disable(EnableCap.Lighting); } if (isBlend) { GL.Enable(EnableCap.Blend); } else { GL.Disable(EnableCap.Blend); } if (isTexture) { GL.Enable(EnableCap.Texture2D); } else { GL.Disable(EnableCap.Texture2D); } }
public void Draw() { GL.ShadeModel(ShadingModel.Smooth); GL.Disable(EnableCap.CullFace); GL.LineWidth(1); GL.Color3(0, 0, 0); int[] viewport = new int[4]; GL.GetInteger(GetPName.Viewport, viewport); double asp = (viewport[2] + 1.0) / (viewport[3] + 1.0); GL.MatrixMode(MatrixMode.Projection); GL.PushMatrix(); GL.LoadIdentity(); GL.Ortho(-asp, asp, -1, 1, -1, 1); GL.MatrixMode(MatrixMode.Modelview); GL.PushMatrix(); GL.LoadIdentity(); double intervalN = 17.0; uint divC = 20; GL.Scale(ScaleX, ScaleY, 1.0); GL.Translate(((asp - 0.05) / ScaleX - 9), ((1 - 0.05) / ScaleY - 11.5 * 1.7), 1.0); GL.Begin(PrimitiveType.Quads); for (int i = 0; i < divC; i++) { double val0 = (ColorMap.MaxValue - ColorMap.MinValue) * (1.0 / divC) * (i + 0) + ColorMap.MinValue; double val1 = (ColorMap.MaxValue - ColorMap.MinValue) * (1.0 / divC) * (i + 1) + ColorMap.MinValue; double[] color0 = ColorMap.GetColor(val0); double[] color1 = ColorMap.GetColor(val1); GL.Color3(color0); GL.Vertex2(-3, intervalN * (1.0 / divC) * i); GL.Vertex2(-0, intervalN * (1.0 / divC) * i); GL.Color3(color1); GL.Vertex2(-0, intervalN * (1.0 / divC) * (i + 1)); GL.Vertex2(-3, intervalN * (1.0 / divC) * (i + 1)); } GL.End(); GL.Color3(0, 0, 0); GL.Translate(0, -0.5, 0); uint divN = 10; double maxAbs = Math.Abs(ColorMap.MaxValue) > Math.Abs(ColorMap.MinValue) ? Math.Abs(ColorMap.MaxValue) : Math.Abs(ColorMap.MinValue); int exp = (int)Math.Log10(maxAbs); double pow = Math.Pow(10.0, exp); for (int i = 0; i < divN + 1; i++) { double val = (ColorMap.MaxValue - ColorMap.MinValue) * i / divN + ColorMap.MinValue; string str = string.Format("{0,5:N2}", val / pow); OpenGLUtils.DrawString(str, FontSize); GL.Translate(0, +intervalN / divN, 0); } { string str = string.Format("[x10{0}{1}]", (exp >= 0 ? "+" : ""), exp); OpenGLUtils.DrawString(str, FontSize); } GL.MatrixMode(MatrixMode.Projection); GL.PopMatrix(); GL.MatrixMode(MatrixMode.Modelview); GL.PopMatrix(); }