hz rabotaet
This commit is contained in:
parent
378e9cb979
commit
f81baf7f3e
5 changed files with 52 additions and 28 deletions
9
ComputerGraphicsLab2/Form1.Designer.cs
generated
9
ComputerGraphicsLab2/Form1.Designer.cs
generated
|
|
@ -17,7 +17,6 @@ namespace ComputerGraphicsLab2
|
|||
{
|
||||
components.Dispose();
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
|
|
@ -40,6 +39,8 @@ namespace ComputerGraphicsLab2
|
|||
this.glControl1.Size = new System.Drawing.Size(776, 426);
|
||||
this.glControl1.TabIndex = 0;
|
||||
this.glControl1.VSync = false;
|
||||
this.glControl1.Load += new System.EventHandler(this.glControl1_Load);
|
||||
this.glControl1.Paint += new System.Windows.Forms.PaintEventHandler(this.glControl1_Paint);
|
||||
//
|
||||
// Form1
|
||||
//
|
||||
|
|
@ -48,13 +49,13 @@ namespace ComputerGraphicsLab2
|
|||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Controls.Add(this.glControl1);
|
||||
this.Name = "Form1";
|
||||
this.Text = "Form1";
|
||||
this.Text = "OpenGL Triangle";
|
||||
this.Load += new System.EventHandler(this.Form1_Load);
|
||||
this.ResumeLayout(false);
|
||||
}
|
||||
|
||||
private OpenTK.GLControl glControl1;
|
||||
|
||||
#endregion
|
||||
|
||||
private OpenTK.GLControl glControl1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,14 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using OpenTK.Graphics.OpenGL;
|
||||
using OpenTK.Input;
|
||||
using System.Drawing;
|
||||
using BeginMode = OpenTK.Graphics.OpenGL.BeginMode;
|
||||
using ClearBufferMask = OpenTK.Graphics.OpenGL.ClearBufferMask;
|
||||
using GL = OpenTK.Graphics.OpenGL.GL;
|
||||
|
||||
namespace ComputerGraphicsLab2
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
private int CubeSize = 128;
|
||||
private bool glLoaded = false;
|
||||
|
||||
public Form1()
|
||||
{
|
||||
|
|
@ -22,27 +17,55 @@ namespace ComputerGraphicsLab2
|
|||
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
var width = 512;
|
||||
var height = 512;
|
||||
|
||||
var left = (width - CubeSize) / 2;
|
||||
var right = left + CubeSize;
|
||||
var bottom = (height - CubeSize) / 2;
|
||||
var top = bottom + CubeSize;
|
||||
|
||||
GL.ClearColor(Color.White);
|
||||
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
|
||||
GL.Color3(255, 0, 0);
|
||||
GL.Begin(BeginMode.Quads);
|
||||
GL.Vertex2(left, bottom);
|
||||
GL.Vertex2(left, top);
|
||||
GL.Vertex2(right, bottom);
|
||||
GL.Vertex2(right, top);
|
||||
GL.End();
|
||||
// Форма загружена
|
||||
}
|
||||
|
||||
private void glControl1_Load(object sender, EventArgs e)
|
||||
{
|
||||
glLoaded = true;
|
||||
|
||||
// Настройка OpenGL
|
||||
GL.ClearColor(Color.White);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
|
||||
// Настройка viewport
|
||||
GL.Viewport(0, 0, glControl1.Width, glControl1.Height);
|
||||
|
||||
// Настройка проекции
|
||||
GL.MatrixMode(MatrixMode.Projection);
|
||||
GL.LoadIdentity();
|
||||
GL.Ortho(-2.0, 2.0, -2.0, 2.0, -1.0, 1.0);
|
||||
|
||||
GL.MatrixMode(MatrixMode.Modelview);
|
||||
GL.LoadIdentity();
|
||||
|
||||
// Принудительная перерисовка
|
||||
glControl1.Invalidate();
|
||||
}
|
||||
|
||||
private void glControl1_Paint(object sender, PaintEventArgs e)
|
||||
{
|
||||
if (!glLoaded) return;
|
||||
|
||||
// Очистка экрана
|
||||
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();
|
||||
|
||||
// Отображение результата
|
||||
glControl1.SwapBuffers();
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
ComputerGraphicsLab2/Lib/OpenTK.Compatibility.dll
Normal file
BIN
ComputerGraphicsLab2/Lib/OpenTK.Compatibility.dll
Normal file
Binary file not shown.
BIN
ComputerGraphicsLab2/Lib/OpenTK.GLControl.dll
Normal file
BIN
ComputerGraphicsLab2/Lib/OpenTK.GLControl.dll
Normal file
Binary file not shown.
BIN
ComputerGraphicsLab2/Lib/OpenTK.dll
Normal file
BIN
ComputerGraphicsLab2/Lib/OpenTK.dll
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue