public void DrawSelection(uint iDraw) { bool isBlend = GL.IsEnabled(EnableCap.Blend); bool isLineSmooth = GL.IsEnabled(EnableCap.LineSmooth); bool isTexture = GL.IsEnabled(EnableCap.Texture2D); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.LineSmooth); GL.Disable(EnableCap.Texture2D); uint ndim = VertexArray.Dimension; GL.PushName(iDraw); // モデルの描画 GL.EnableClientState(ArrayCap.VertexArray); GL.VertexPointer((int)ndim, VertexPointerType.Double, 0, VertexArray.VertexCoordArray); for (int idp = 0; idp < DrawParts.Count; idp++) { CadObject2DDrawPart dp = DrawParts[idp]; double height = dp.Height; GL.PushName(idp); GL.Translate(0.0, 0.0, +height); dp.DrawElements(); if (dp.Type == CadElementType.Edge && dp.ShowMode == 2) { for (int icp = 0; icp < dp.CtrlPoints.Count; icp++) { OpenTK.Vector2d cp = dp.CtrlPoints[icp]; GL.PushName(icp); GL.Begin(PrimitiveType.Points); OpenGLUtils.GLVertex2(cp); GL.End(); GL.PopName(); } } GL.Translate(0.0, 0.0, -height); GL.PopName(); } GL.DisableClientState(ArrayCap.VertexArray); GL.PopName(); 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.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); } }