0

I am trying to run a very simple example on OpenGlut for my class assignment and for some reason the code is not working on my xcode. I am currently using Xcode 10 on macOS Mojave.

Following is the code:

#include <GLUT/glut.h>

void render()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glBegin(GL_TRIANGLES);
    glVertex2f( -0.5, -0.5 );
    glVertex2f(  0.5, -0.5 );
    glVertex2f(  0.0,  0.5 );
    glEnd();
    glutSwapBuffers();
}

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(800, 600);
    glutCreateWindow("Hello, GL");
    glutDisplayFunc(render);
    glutMainLoop();
    return 0;
}

This is the error message:

2018-09-29 14:38:03.737378-0700 gluttest[18974:837022] MessageTracer: load_domain_whitelist_search_tree:73: Search tree file's format version number (0) is not supported
2018-09-29 14:38:03.738891-0700 gluttest[18974:837022] MessageTracer: Falling back to default whitelist
2018-09-29 14:38:03.857540-0700 gluttest[18974:837022] flock failed to lock maps file: errno = 35
2018-09-29 14:38:03.858276-0700 gluttest[18974:837022] flock failed to lock maps file: errno = 35

To make things more clear, I am adding more information about what I have already tried:

  1. The same code is running absolutely fine on Xcode 10 in High Sierra.
  2. I have changed destination target to macOS 10.8 in Xcode
  3. I have made sure OpenGL and Glut framework binaries are linked to the project.
Milan Jain
  • 459
  • 7
  • 17
  • Are you sure about passing the address of `argc` there?? `glutInit(&argc, argv);` – πάντα ῥεῖ Sep 29 '18 at 21:39
  • Can you please elaborate your comment? The same code is running perfectly on High Sierra on Xcode 10. Please feel free to try on your system. – Milan Jain Sep 29 '18 at 21:41
  • Runs fine on Linux too. How are you setting it up? – Carl Sep 29 '18 at 21:44
  • It may be weird for you but that's how we are supposed to pass. It is an old library and I just need it for an assignment. @Carl: In terms of setting, I have set macOS 10.8 as the destination and linked OpenGL and Glut frameworks to the code. Should I check any other setting as well? – Milan Jain Sep 29 '18 at 21:46

1 Answers1

1

For some reason, the window isn't drawn initially whenever glutMainLoop() is called on Mojave. You can kind of work around this by calling it in the keyboard function:

void keyboard(unsigned char key, int x, int y) {
    glutPostRedisplay();
}

int main(int argc, char** argv) {
    // ... 
    glutKeyboardFunc(keyboard);
    glutMainLoop();
    return 0;
}

EDIT: A better idea:

bool hasDrawn = false;

void display() {
    // ...
    if (!hasDrawn) {
        glutPostRedisplay();
        hasDrawn = true;
    }
}

void main() {
    glutDisplayFunc(display);
}
Luke
  • 4,908
  • 1
  • 37
  • 59
  • Thanks Luke for validating that Glut is giving trouble with Mojave. I tried to redraw the display but with no success. It is still showing a black screen. – Milan Jain Oct 01 '18 at 19:39