3

I am running a simple application to open a window and show some points in it in xcode 13. Everything seems to work fine, no import errors, all correct includes and dynamic libraries etc... but upon running the app the error is

freeglut (/Users/sukhacoder02/Library/Developer/Xcode/DerivedData/Test-gxuvnapyfsfufeeabywtmpmjgbtg/Build/Products/Debug/Test): failed to open display ''
Program ended with exit code: 1

The code is

#define GL_SILENCE_DEPRECATION
//#include <GLFW/glfw3.h>
#include <GL/glut.h>

void display() {
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 0.0);

    glBegin(GL_POINTS);
    glVertex2f(10.0, 10.0);
    glVertex2f(150.0, 80.0);
    glVertex2f(100.0, 20.0);
    glVertex2f(200.0, 100.0);
    glEnd();
    glFlush();
}

void myinit() {
    glClearColor(1.0, 1.0, 1.0, 1.0);
    glColor3f(1.0, 0.0, 0.0);
    glPointSize(5.0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0.0, 499.0, 0.0, 499.0);
}

int main(int argc, char** argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(0, 0);
    glutCreateWindow("Points");
    glutDisplayFunc(display);

    myinit();
    glutMainLoop();
    return 0;
}

I've read many solutions but they all are complex and trying to do some ssh on server etc... Some suggest display environment variable setting, I've also tried, but nothing seems to work. Any help would be highly appreciated. Thanks.

0 Answers0