gpt4 book ai didi

c# - 在 Linux 上使用 Mono-C# 时 glXChooseVisual 失败

转载 作者:太空宇宙 更新时间:2023-11-04 04:26:12 25 4
gpt4 key购买 nike

当我调用“glXChooseVisual”(在 C# 中又名 GLX.ChooseVisual)时,它返回一个 null IntPtr。现在让我困惑的是,当我构建 NeHe Lesson02 时,基本上使用它工作的相同代码(唯一的区别是用 C 编写的)。

此外,当我从 OpenTK 进入代码并发现它调用“glXChooseVisual”时,它返回一个有效的 Visual ptr,但我目前还找不到任何丢失的东西。

另外,让我烦恼的是我在一年前就已经开始工作了。我这样做的原因是为了跨平台 API,它不仅限于 OpenGL,因此任何帮助都会很棒。

我已经在 [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);
}
}
}

最佳答案

不需要指定调用约定吗?像这样:

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

您还可以检查前两次调用是否返回有意义的(非零)值。

关于c# - 在 Linux 上使用 Mono-C# 时 glXChooseVisual 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8741259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com