최근에 나는 p/invoke (Linux 플랫폼 용 .NET)를 사용하여 간단한 OpenGL 응용 프로그램을 작성하여 C#에서 작동하는 방법을 알아 냈습니다. (이미 Windows에서 성공적으로 완료했습니다.). 타오 프레임 워크에 대해 들었지만 프로그램과 같은 단순한 "안녕하세요 세상"을 위해 모든 것을 원하지는 않습니다.C# mono p/invoke failure
처음부터 막혔습니다. 나는 그들이 작동하는지 확인하기 위해 일부 GL 함수를 호출했다. 나는 즉시 glClearColor와 glClear를 호출하여 glGetError를 설정했는지 여부를 확인합니다 (OpenGL은 그 시점에서 초기화되지 않았기 때문에).
대신 함수를 호출하면 다음 스택 추적 및 기타 debuginfo가 충돌하고 덤프됩니다. 예외는 발생하지 않습니다.
스택 트레이스 :
at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) <0x00004>
at (wrapper managed-to-native) Calmarius.OGL.OpenGLLibrary.glClearColor (single,single,single,single) <0xffffffff>
at Calmarius.RTS.GameForm.OnPaint (System.Windows.Forms.PaintEventArgs) [0x00000] in /home/calmarius/Development/csharp/RTS/RTS/Form1.cs:60
at System.Windows.Forms.Control.WmPaint (System.Windows.Forms.Message&) <0x000b0>
at System.Windows.Forms.Control.WndProc (System.Windows.Forms.Message&) <0x001e2>
at System.Windows.Forms.ScrollableControl.WndProc (System.Windows.Forms.Message&) <0x0000d>
at System.Windows.Forms.ContainerControl.WndProc (System.Windows.Forms.Message&) <0x00054>
at System.Windows.Forms.Form.WndProc (System.Windows.Forms.Message&) <0x001da>
at ControlWindowTarget.OnMessage (System.Windows.Forms.Message&) <0x00014>
at ControlNativeWindow.WndProc (System.Windows.Forms.Message&) <0x00022>
at System.Windows.Forms.NativeWindow.WndProc (intptr,System.Windows.Forms.Msg,intptr,intptr) <0x001b7>
at System.Windows.Forms.XplatUIX11.DispatchMessage (System.Windows.Forms.MSG&) <0x00016>
at System.Windows.Forms.XplatUI.DispatchMessage (System.Windows.Forms.MSG&) <0x00015>
at System.Windows.Forms.Application.RunLoop (bool,System.Windows.Forms.ApplicationContext) <0x00997>
at System.Windows.Forms.Application.Run (System.Windows.Forms.ApplicationContext) <0x0006a>
at System.Windows.Forms.Application.Run (System.Windows.Forms.Form) <0x00025>
at Calmarius.RTS.Program.Main() [0x0000b] in /home/calmarius/Development/csharp/RTS/RTS/Program.cs:19
at (wrapper runtime-invoke) System.Object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>
glClearColor에 대한 서명은 다음과 같습니다
//gllibname="opengl32.dll" --> mapped to libGL.so
[DllImport(gllibname)]
public static extern void glClearColor(float red, float green, float blue, float alpha);
C 사양은 다음과 같습니다 내가 헤더에 선언을 본대로
void glClearColor(GLclampf red,GLclampf green,GLclampf blue,GLclampf alpha);
GLclampf는 부동입니다.
@ps : 둘 다 아직 나와 함께 있습니다 (Firefox 3.0). – OregonGhost
C#에서 메서드를 선언 한 방법과 pinvoking 할 C 메서드의 서명을 추가해야합니다. –
서명이 추가되었습니다. – Calmarius