skip to Main Content

Im trying to run this simple hello world program with openGL and C.
Im running this in a debian subsystem on windows and i think that is part of the problem.

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;
}

but i get this error:

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

2

Answers


  1. It’s looking for an X server. The DISPLAY var would normally be exported to ":0", however, given that this is on Windows, I doubt there is one available.

    If xterm -display :0 does not work, you may be better off installing VirtualBox, and install a proper Linux distro within it.

    Login or Signup to reply.
  2. Maybe you should try installing Xlanch, my wsl2 ubuntu worked after following this instructions: https://github.com/microsoft/WSL/issues/4106

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search