Microsoft Visual Studio Comunity 2015 で OpenGL4Net を C# で動作させようとしています。
このファイルをダウンロードしました: https://sourceforge.net/projects/ogl4net/files/Rev.%2037/x64/
そして、次の指示に従いました: https://sourceforge.net/p/ogl4net/wiki/Tutorials/
最初はコンソール アプリケーションを使用しますが、独自のウィンドウを作成するのではなく、そこからウィンドウを使用するように思われるため、Windows フォーム アプリケーションで再び開始します。
これまでのところ、さまざまな参照が追加されています。form1.cs はそのままで、Program.cs は次のようになります。
using System;
using System.Collections.Generic;
//using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenGL4NET;
namespace pads2
{
class Program : Form
{
RenderingContext rc;
static void Main(string[] args)
{
Program program = new Program();
program.Init();
Application.Run(program);
}
// required for open GL
void Init()
{
rc = RenderingContext.CreateContext(this);
SetStyle(ControlStyles.AllPaintingInWmPaint, true);
}
void Render()
{
gl.Clear(GL.COLOR_BUFFER_BIT);
// here is the right place to draw all your scene
rc.SwapBuffers();
}
// change window size
protected override void OnSizeChanged(EventArgs e)
{
gl.Viewport(0, 0, ClientSize.Width, ClientSize.Height);
// projection matrix may also need adjusting
}
// required for open GL
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case Windows.WM_PAINT: Render(); break;
default: base.WndProc(ref m); break;
}
}
}
}
/*
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
/*
コンパイラはコードの最後のコメントに不満を持っているようですが、主な問題は次のエラーが表示されることです。
タイプまたは名前空間名「WM_PAINT」が名前空間「Windows」に存在しません (アセンブリ参照がありませんか?)
System.Windows の参照を含め、WM_PAINT に必要な参照をオンラインで見つけることができませんでした。
Q: どうすればこれを解決できますか? また、正しく設定していますか?