OpenGL程序在WSL下显示黑屏?

问题描述 投票:0回答:1

当我在 WSL 下运行代码时,我只得到一个黑色窗口:

即使 glxgears 也工作得很好,我的代码不应该是问题,因为它在虚拟机中运行没有错误。

#include <stdio.h>
#include <stdlib.h>

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

static void renderScene(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
             glVertex2f(-1.0f,-1.0f);
             glVertex2f(-1.0f,1.0f);
             glVertex2f(1.0f,1.0f);

     glEnd();
     glutSwapBuffers();
}

static void setupRC(void)
{
     glClearColor(0.0f,0.0f,1.0f,1.0f);
}

int main(int argc, char* argv[])
{
     glutInit(&argc,argv);
     glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
     glutInitWindowSize(400,400);
     glutCreateWindow("Hello OpenGL");
     glutDisplayFunc(renderScene);

     setupRC();
     glutMainLoop();
     return 0;
}

我尝试了多个“修复”,但每个“修复”都没有改变任何东西。 “修复”是:

  • 我使用 本指南
  • 创建了一个 VcXsrv 服务器
  • 设置导出 LIBGL_ALWAYS_INDIRECT=0
c opengl windows-subsystem-for-linux glut
1个回答
0
投票

我只需要重新安装 freeglut-dev3。好像是安装的问题

© www.soinside.com 2019 - 2024. All rights reserved.