diff --git a/ComputerGraphicsLab2/Form1.cs b/ComputerGraphicsLab2/Form1.cs index 1649aca..b17d13e 100644 --- a/ComputerGraphicsLab2/Form1.cs +++ b/ComputerGraphicsLab2/Form1.cs @@ -50,22 +50,39 @@ namespace ComputerGraphicsLab2 // Очистка экрана GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); - // Рисование треугольника - GL.Begin(PrimitiveType.Triangles); - - GL.Color3(1.0f, 0.0f, 0.0f); // красная вершина - GL.Vertex2(-1.0f, -1.0f); - - GL.Color3(0.0f, 1.0f, 0.0f); // зеленая вершина - GL.Vertex2(1.0f, -1.0f); - - GL.Color3(0.0f, 0.0f, 1.0f); // синяя вершина - GL.Vertex2(0.0f, 1.0f); - - GL.End(); + drawTriangle(); // Отображение результата glControl1.SwapBuffers(); } + + private void drawTriangle() + { + var z = 4.0f; + var pointsCoint = 3; + var colors = new Vector3[pointsCoint]; + var points = new Vector3[pointsCoint]; + + colors[0] = new Vector3(1.0f, 0.0f, 0.0f); + colors[1] = new Vector3(0.0f, 1.0f, 0.0f); + colors[2] = new Vector3(0.0f, 0.0f, 1.0f); + + points[0] = new Vector3(-1.0f, -1.0f, z); + points[1] = new Vector3(1.0f, -1.0f, z); + points[2] = new Vector3(0.0f, 1.0f, z); + + drawPolygon(points, colors, pointsCoint, BeginMode.Polygon); + } + + private void drawPolygon(Vector3[] points, Vector3[] colors, int n, BeginMode mode) + { + GL.Begin(mode); + for (int i = 0; i < n; i++) + { + GL.Color3(colors[i]); + GL.Vertex2(points[i].X, points[i].Y); + } + GL.End(); + } } } \ No newline at end of file