"glXChooseVisual" (別名 C# では GLX.ChooseVisual) を呼び出すと、null IntPtr が返されます。今私を混乱させているのは、基本的に動作するのと同じコードを使用して NeHe レッスン 02 をビルドするときです (唯一の違いは C で記述されていることです)。
また、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);
}
}
}