2016-08-08 26 views
0

的後續行動: OpenGL4Net WM_PAINT does not exist?OpenGL4Net System.BadImageFormatException

我仍然密切關注:https://sourceforge.net/p/ogl4net/wiki/Tutorials

的程序,因爲它目前爲:

using System; 
using System.Collections.Generic; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using OpenGL4NET; 

namespace pads2 
{ 
    class Program : Form 
    { 
     private const int WM_PAINT = 15; 
     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 WM_PAINT: Render(); break; 
       default: base.WndProc(ref m); break; 
      } 
     } 
    } 
} 

問:假如我正確實施教程,我能做些什麼關於線program.Init();上的錯誤System.BadImageFormatException

此外:

其他信息:無法加載文件或程序集 'OpenGL4Net, 版本= 4.3.37.24文化=中性公鑰=空' 或它 的一個依賴。試圖加載格式不正確的程序。

這可能是由於警告:

有正在建造「MSIL」項目 的處理器架構和參考 「OpenGL4Net」的處理器架構之間的不匹配,「 AMD64" 。這種不匹配可能會導致運行時失敗。 請考慮通過配置管理器更改 項目的目標處理器架構,以便使其處理器項目和引用之間 架構,或採取與匹配 的目標處理器架構的處理器架構引用一個 依賴你項目。

然而,根據:

How do I fix the Visual Studio compile error, "mismatch between processor architecture"?

這不應該是一個問題。下載OpenGL4Net DLL時只有(32或64)位選項。

鑑於Microsoft中間語言與處理器不同,我嘗試在發佈模式而不是調試模式下運行,但它沒有區別。

回答

1

編譯時使用什麼構建配置?你下載了什麼版本的OpenGL4Net? 32或64位版本?

嘗試設置構建配置以匹配引用程序集的預期目標cpu(因此,根據OpenGL4Net的下載,32位或64位)。

查看C# compiling for 32/64 bit, or for any cpu?的詳細解釋。

+0

這是在「調試」(嘗試過「發佈」)和「任何CPU」。我剛剛在構建配置中創建了一個特殊的「64位CPU」,它工作正常!看起來VS並不默認你的CPU和OS設置的CPU類型。 | Discworld - Sam Vimes - 「儘管你知道只有通過嘗試每一種可能的方式來達到目的,但是你知道你錯了,這真是太好了。」 – alan2here

相關問題