【问题标题】:freeglut: failed to open display '', linux subsystemfreeglut:无法打开显示'',linux子系统
【发布时间】:2022-01-05 21:00:49
【问题描述】:

我正在尝试使用 openGL 和 C 运行这个简单的 hello world 程序。 我在 Windows 上的 debian 子系统中运行它,我认为这是问题的一部分。

Main.c

#include<stdio.h>
#include<GL/glut.h>
void displayMe(void)
{
        glClear(GL_COLOR_BUFFER_BIT);
        glBegin(GL_POLYGON);
        glVertex3f(0.5, 0.0, 0.5);
        glVertex3f(0.5, 0.0, 0.0);
        glVertex3f(0.0, 0.5, 0.0);
        glVertex3f(0.0, 0.0, 0.5);
        glEnd();
        glFlush();
}
int main(int argc, char** argv){
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_SINGLE);
        glutInitWindowSize(400, 300);
        glutInitWindowPosition(100, 100);
        glutCreateWindow("Hello world!");
        glutDisplayFunc(displayMe);
        glutMainLoop();
        return 0;
}

但我收到此错误:

freeglut (./firstOpenGlApp): failed to open display ''

【问题讨论】:

    标签: c opengl debian windows-subsystem-for-linux freeglut


    【解决方案1】:

    它正在寻找 X 服务器。 DISPLAY 变量通常会导出到“:0”,但是,鉴于这是在 Windows 上,我怀疑是否有可用的。

    如果xterm -display :0 不起作用,您最好安装 VirtualBox,并在其中安装适当的 Linux 发行版。

    【讨论】:

    • xterm 无法正常工作,但我想试试虚拟机!
    【解决方案2】:

    也许你应该尝试安装 Xlanch,我的 wsl2 ubuntu 在按照以下说明运行:https://github.com/microsoft/WSL/issues/4106

    【讨论】:

    • 考虑解释为什么 Xlanch 会帮助解决这个特定问题。此答案是仅链接答案,没有解释。
    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
    猜你喜欢
    • 2017-11-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 2017-10-20
    • 2018-08-12
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    相关资源
    最近更新 更多