works in separate functions
This commit is contained in:
parent
f81baf7f3e
commit
14dccc7081
1 changed files with 30 additions and 13 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue