我正在使用 LoadLibrary/GetProcAddress/wglGetProcAddress 在 C# 中加載 OpenGL。出于某種原因,它無法加載 的指標glBlendFunc,以及該點之后的其他隨機指標。我已經瀏覽了我的代碼一個小時的大部分時間,所有這些失敗的部分看起來都完全正常嗎?
加載函式指標并將其轉換為委托的代碼。
public override T GetFunction<T>(string name)
{
IntPtr pointer = wglGetProcAddress(name);
if (pointer == IntPtr.Zero)
pointer = GetProcAddress(Handle, name);
return Marshal.GetDelegateForFunctionPointer<T>(pointer);
}
呼叫 的代碼示例GetFunction。
BlendEquationSeparate = Loader.GetFunction<glBlendEquationSeparate>("glBlendEquationSeparate");
BlendEquationSeparatei = Loader.GetFunction<glBlendEquationSeparatei>("glBlendEquationSeparatei");
BlendFunc = Loader.GetFunction<glBlendFunc>("glBlendFunc");
BlendFunci = Loader.GetFunction<glBlendFunci>("glBlendFunci");
BlendFuncSeparate = Loader.GetFunction<glBlendFuncSeparate>("glBlendFuncSeparate");
BlendFuncSeparatei = Loader.GetFunction<glBlendFuncSeparatei>("glBlendFuncSeparatei");
委托代碼示例。
public delegate void glBlendEquationSeparate(BlendEquationMode modeRGB, BlendEquationMode modeAlpha);
public static glBlendEquationSeparate BlendEquationSeparate;
public delegate void glBlendEquationSeparatei(UInt32 buf, BlendEquationMode modeRGB, BlendEquationMode modeAlpha);
public static glBlendEquationSeparatei BlendEquationSeparatei;
public delegate void glBlendFunc(BlendingFactorSrc sfactor, BlendingFactorDest dfactor);
public static glBlendFunc BlendFunc;
public delegate void glBlendFunci(UInt32 buf, BlendingFactorSrc sfactor, BlendingFactorDest dfactor);
public static glBlendFunci BlendFunci;
public delegate void glBlendFuncSeparate(BlendingFactorSrc srcRGB, BlendingFactorDest dstRGB, BlendingFactorSrc srcAlpha, BlendingFactorDest dstAlpha);
public static glBlendFuncSeparate BlendFuncSeparate;
public delegate void glBlendFuncSeparatei(UInt32 buf, BlendingFactorSrc srcRGB, BlendingFactorDest dstRGB, BlendingFactorSrc srcAlpha, BlendingFactorDest dstAlpha);
public static glBlendFuncSeparatei BlendFuncSeparatei;
我正在使用的 DllImports
[DllImport("kernel32")]
public static extern IntPtr LoadLibrary(string fileName);
[DllImport("kernel32")]
public static extern IntPtr GetProcAddress(IntPtr module, string procName);
[DllImport("opengl32.dll", EntryPoint = "wglGetProcAddress", ExactSpelling = true)]
public static extern IntPtr wglGetProcAddress(string lpszProc);
所有的列舉都是非常標準的,不需要背景關系。我喜歡加載常用的庫:LoadLibrary(opengl32.dll);。誰能向我解釋我哪里出錯了?
uj5u.com熱心網友回復:
我找到了一個有點奇怪的解決方案。如果我將代碼移動到靜態建構式,使其在程式開始時運行,它會突然起作用。我不知道為什么我的第一種方法不起作用。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/402380.html
標籤:
上一篇:遷移到.NET5后,out引數顯示錯誤“使用未分配的區域變數”
下一篇:web瀏覽器及網頁概念
