2012-01-05 2 views
0

"glXChooseVisual"(C#에서 GLX.ChooseVisual이라고 함)을 호출하면 null IntPtr을 반환합니다. 이제는 NeHe lesson02를 기본적으로 작동하는 동일한 코드 (C로 작성된 유일한 차이점)를 사용하여 빌드하면 혼란 스럽습니다.리눅스에서 Mono-C#을 사용할 때 glXChooseVisual이 실패 함

또한 OpenTK에서 코드를 훑어보고 "glXChooseVisual"을 호출하면 유효한 Visual ptr을 반환하지만 아직 누락 된 항목을 찾을 수 없습니다.

또한 1 년 전에 내가 과거에 이런 작업을했는지 어떤 버그가 있습니다. 내가이 일을하는 이유는 OpenGL에 국한되지 않는 크로스 플랫폼 API에 대한 것이므로 어떤 도움이 좋을 것입니다.

[Ubuntu 11.10 Nvidia 5700] 및 [Fedora 16 Nvidia 6100]에서이 모든 작업을 시도했지만 모두 실패했습니다. Mono-C# 콘솔 응용 프로그램에서이 코드를 복사하여 지난 후에 테스트해볼 수 있습니다.

using System; 
using System.Runtime.InteropServices; 

namespace TestGL 
{ 
    static class GLX 
    { 
     [DllImport("libX11", EntryPoint = "XOpenDisplay", ExactSpelling = true)] 
     public static extern IntPtr XOpenDisplay(IntPtr display_name); 

     [DllImport("libX11", EntryPoint = "XDefaultScreen", ExactSpelling = true)] 
     public static extern int XDefaultScreen(IntPtr dpy); 

     [DllImport("libGL", EntryPoint = "glXChooseVisual", ExactSpelling = true)] 
     public static extern IntPtr ChooseVisual(IntPtr dpy, int screen, int[] attribList); 

     public const int RGBA = 4; 
     public const int DOUBLEBUFFER =5; 
     public const int RED_SIZE = 8; 
     public const int GREEN_SIZE = 9; 
     public const int BLUE_SIZE = 10; 
     public const int ALPHA_SIZE = 11; 
     public const int DEPTH_SIZE = 12; 
     public const int None = 0x8000; 
    } 

    class MainClass 
    { 
     public static void Main (string[] args) 
     { 
      Console.WriteLine ("Hope this works!"); 

      //Get DC 
      IntPtr dc = GLX.XOpenDisplay(new IntPtr(0)); 
      int screen = GLX.XDefaultScreen(dc); 

      //Set BackBuffer format 
      int[] attrListDbl = 
      { 
       GLX.RGBA, 
       GLX.DOUBLEBUFFER, 
       GLX.RED_SIZE, 8, 
       GLX.GREEN_SIZE, 8, 
       GLX.BLUE_SIZE, 8, 
       GLX.DEPTH_SIZE, 16, 
       0 
      }; 

      IntPtr visual = GLX.ChooseVisual(dc, screen, attrListDbl); 
      if (visual == IntPtr.Zero) 
      { 
       int[] attrListSgl = 
       { 
        GLX.RGBA, 
        GLX.RED_SIZE, 8, 
        GLX.GREEN_SIZE, 8, 
        GLX.BLUE_SIZE, 8, 
        GLX.DEPTH_SIZE, 16, 
        0 
       }; 

       visual = GLX.ChooseVisual(dc, screen, attrListSgl); 
      } 

      if (visual == IntPtr.Zero) 
      { 
       Console.WriteLine("Failed to get visual."); 
      } 
      else 
      { 
       Console.WriteLine("Yahoo.");  
      } 

      //ctx = GLX.CreateContext(dc, visual, new IntPtr(0), true); 
      //GLX.MakeCurrent(dc, handle, ctx); 
     } 
    } 
} 

답변

0

문제점을 발견했습니다. 왜 내가 1 년 전에이 문제가 없었는지 모르겠지만 "libgl"을 "libgl.so.1"로 변경해야만합니다.

0

호출 규칙을 지정하지 않아도됩니까? 이와 같이 :

[DllImport("libGL", ... , CallingConvention=CallingConvention.Cdecl)] 

처음 두 번 호출이 의미있는 (0이 아닌) 값을 반환하는지 확인할 수도 있습니다.

+0

아니요 문제를 해결하지 못했습니다. 호출에 여러 오버로드가있는 메서드 인 경우 "Cdecl"이 사용됩니다. 나는 그 적용이 여기 있다고 생각하지 않는다. 그리고 예 "dc"ptr과 "screen"은 유효한 객체를 반환하고, iv'e는 확인하기 위해 다른 방법으로 검사했습니다. 매우 이상합니다. – zezba9000

관련 문제