Basic test flickers on OS X Yosemite [solved]

Hi, both a basic test I made myself following the example on the web site, and a pared-down version of simple.c (taking out all the rendering code except glClear) results in a flickering image. It seems that the 2nd buffer doesn’t get cleared. What could I be doing wrong? Here is the code I’m using:

#include <GLFW/glfw3.h>

int main()
{
  glfwInit();

  glfwWindowHint(GLFW_DOUBLEBUFFER, GLFW_TRUE);
  GLFWwindow *const window =
    glfwCreateWindow(640, 480, "test", NULL, NULL);

  glfwMakeContextCurrent(window);
  glfwSwapInterval(1);

  while (!glfwWindowShouldClose(window))
  {
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  glfwDestroyWindow(window);
  glfwTerminate();
  return 0;
}

This is GLFW 3.2.1 installed via MacPorts on OS X v10.10.5, building using clang 7.0.2. Graphics card is an Nvidia GeForce GT 750M.

Ah sorry nevermind this was my own issue. I was building with -lgl rather than with the frameworks pkg-config gave me.

However pkg-config seems to be missing -framework OpenGL:

$ pkg-config --static --libs glfw3
-L/opt/local/lib -lglfw -framework Cocoa -framework IOKit -framework CoreFoundation -framework CoreVideo

Not sure if this is a bug or by design. Regardless manually adding -framework OpenGL gets me a working test, yay!

It’s by design. Since GLFW nowadays supports more APIs than OpenGL and doesn’t know which you will use, it loads things like OpenGL.framework and vulkan-1.dll as needed at runtime instead.

That makes sense, but if I build without -framework OpenGL, I get a screen full of linker errors. e.g.:

$ cc -Wall -Werror -march=corei7 $(pkg-config --static --libs glfw3) -o test *.o
Undefined symbols for architecture x86_64:
  "_glActiveTexture", referenced from:
      _graphics_init in graphics.o
      _graphics_draw in graphics.o
  "_glAttachShader", referenced from:
      _graphics_init in graphics.o

…etc. (–static or not doesn’t matter.) What am I missing?

If you are calling OpenGL without using an extension loader library then your application needs -framework OpenGL. Either method is perfectly fine. It’s just that GLFW itself doesn’t need either. The output of those pkg-config commands only gives you the dependencies of GLFW, and there’s no need to have -framework OpenGL there if you’re going to use ANGLE or MoltenVK or something else.

This is explained somewhat in the pkg-config section of the build guide, but I see there’s no example for macOS. I will update it.

1 Like