问题
I'm trying to get OpenGL4Net working with C# in Microsoft Visual Studio Comunity 2015.
I've downloaded this file: https://sourceforge.net/projects/ogl4net/files/Rev.%2037/x64/
And followed these instructions: https://sourceforge.net/p/ogl4net/wiki/Tutorials/
At first with a console application but then starting again with a Windows Form application as it seems as if it was going to be using the window from that as opposed to making its own.
So far the various refrances have been added, form1.cs is untouched and Program.cs looks like this:
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());
}
}
/*
The compiler seems unhappy about the comment at the end of the code, however the main issue is that I recieve the error:
The type or namespace name 'WM_PAINT' does not exist in the namespace 'Windows' (are you missing an assembly reference?)
I've been unable to find what reference I need for WM_PAINT online, including a reference for System.Windows did not help.
Q: How can I solve this and am I setting this up correctly?
回答1:
WM_PAINT
is described in detail in its MSDN entry:
https://msdn.microsoft.com/en-us/library/windows/desktop/dd145213(v=vs.85).aspx
The article however omits its POD value, being the Integer constant "15".
回答2:
Had this problem earlier, the example forgets to add the reference, the case should be:
case OpenGL4NET.Windows.WM_PAINT: Render(); break;
(Would comment if rep allowed me too)
来源:https://stackoverflow.com/questions/38833678/opengl4net-wm-paint-does-not-exist