確保您的體系結構使用了正確的庫。所以對於x86,確保你有x86庫。對於x64請確保您有x64庫。確保將啓動項目的架構設置爲架構,以使用配置管理器來匹配庫。在一臺64位的機器上,默認情況下,它通常會被設置爲「任何CPU」的combile。將其更改爲正確的平臺。
這就是我的做法: 創建一個新的測試風格應用程序。我想做一個64位應用程序,所以我使用配置管理器來將我的啓動應用程序設置爲x64。使用NuGet安裝opentk.glcontrol。它會自動將OpenTK解析爲依賴項並進行安裝。
下面是一些代碼添加控制和背景顏色設置爲天藍色:
using OpenTK;
using OpenTK.Graphics.OpenGL4;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private OpenTK.GLControl _glControl;
public Form1()
{
InitializeComponent();
_glControl = new OpenTK.GLControl();
_glControl.Dock = DockStyle.Fill;
this.Controls.Add(_glControl);
_glControl.Load += control_Load;
_glControl.Paint += control_Paint;
}
private void control_Paint(object sender, PaintEventArgs e)
{
_glControl.SwapBuffers();
}
private void control_Load(object sender, EventArgs e)
{
GL.ClearColor(Color.SkyBlue);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
}
}
}