问题
Mac OS 10.14 Mojave was just released, and since June, we've known that OpenGL was to be deprecated in the OS. "OpenGL applications will continue to run, but you should switch to Metal," to paraphrase. However, there doesn't seem to be any documentation indicating whether you can still compile with OpenGL or if Apple prevents that or omits the proper development libraries. I am currently developing an OpenGL-based graphics program and cannot risk updating if compilation will no longer work. Has anyone tested this?
EDIT: Does anyone else share Esenthel's experience?
回答1:
I can compile, however after updating to latest Mojave and Xcode, my OpenGL applications simply don't work.
In one case I get a hang during a system GL call, in another case just a black screen. And some errors in the output same as here: https://stackoverflow.com/questions/52507950/unable-to-load-info-plist-error-xcode-10-under-macos-10-14-mojave#=
I recommend that you don't update.
I think there's something broken in Xcode 10 OpenGL libraries.
Edit: It appears that later Mac OS and Xcode updates have fixed the problems.
回答2:
GLFW work around. Similar to other answers, but you do not need to resize your window in the draw loop, just call glfwPollEvents()
first.
window = glfwCreateWindow(width-1, height, "Hello World", NULL, NULL);
glfwPollEvents();
glfwSetWindowSize(window, width, height);
Also, glfwHideWindow()
then glfwShowWindow()
seems to work. Similarly glfwSetWindowPos()
is an alternative. Though setting the window size seems faster than hide/showing the window, and I don't want to move the window position.
回答3:
The code at
http://people.bath.ac.uk/abscjkw/ComputerPrograms/C++programs/OpenGL/MojaveOpenGL.cpp
works fine in Mojave with Xcode 10.0. The window is resized automatically to get rid of the black. OpenGL and GLUT frameworks are added to the project from the usual place, /System/Library/Frameworks
Chris
回答4:
I'm using GLEW, GLUT, OpenGL 2.0 and SDL 2. I can compile and run my OpenGL application. However I had to change my Framework Search Paths to include:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks
where OpenGL and GLUT framework + headers are now placed as I couldn't find any OpenGL/GLUT headers in the old search path System/Library/Frameworks (although the framework was still there, no headers were included). I also had to make sure my includes were GLUT/glut.h instead of just glut.h.
This gives me new warning messages in form of:
[default] Unable to load Info.plist exceptions (eGPUOverrides)" and "saved enable noise cancellation setting is the same as the default (=1)
I haven't checked them yet, and what their implications are.
What really bugs me is what Esenthel says, that there is just a black screen after compiling and running the app. I found that if you drag the app window (I'm not using full screen) then the animation starts to show. Apparently the animation is in the background and all code is evaluating, but there is only a black screen until I drag the window.
EDIT: I'm using Mojave and Xcode 10 (not beta).
回答5:
I am using GLUT and OpenGL. The issue is present on both Xcode 10.0 and 10.1 beta3.
If you resize the window the graphics do appear most of the time.
So I devised a workaround using the reshape callback function. Say I wanted to activate a 1000x1000 window. I activate it with 999x999 and then on reshape I turn it to 1000x1000 as required:
void reshape (int width, int height){
glutReshapeWindow (1000, 1000);
}
And on main:
int main (int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
glutInitWindowSize( 999,999 );
glutInitWindowPosition (0.0f, 0.0f);
glutCreateWindow("example");
glutReshapeFunc (reshape);
glutDisplayFunc(draw);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
Since the reshape callback is triggered before display it is working for now.
回答6:
OpenGL in Mojave as of today (October 21, 2018) is bugged. You have to move the glfw window position in order to actually see what it's rendering.
This workaround code inside the rendering loop worked for me:
if(!init)
{
int x,y;
glfwGetWindowPos(window,&x, &y);
glfwSetWindowPos(window,x+1,y);
init = true;
}
回答7:
The reason why some OpenGL code failed is because in Mojave, your view is automatically layer-backed. If your code is testing for this condition:
[NSGraphicsContext currentContextDrawingToScreen]
It'll return NO and the code under that condition will not run (i.e.: nothing drawn on the screen).
Unfortunately, you can't setWantsLayer to NO in Mojave either, it'll not work.
回答8:
"Fixed" this by downloading Xcode 9.4.1
Compiled in it and got my app with OpenGL view working as it should.
I think it's something with Layer-Backed Views. Because when I scroll my OpenGL view it's became visible under some view.. and flickering. And I see it's drawn correctly behind. But when I stop scroll - it disappears.
回答9:
My workaround in GLFW is to call show window in the main draw loop.
bool needDraw = true;
if (needDraw) {
glfwShowWindow(window);
glfwHideWindow(window);
glfwShowWindow(window);
needDraw = false;
}
回答10:
I also came across this after updating. I'm using glfw. In fact, the created window can show the desired content after resize or move it. I added glfwSetWindowPos(window, 100, 100);
in the main loop to move it for a temporary solution.
回答11:
For some cases moving the window coordinate by +1 doesn't work. In that case, we continuously drag the window programmatically until it is rendered and stop the screen by keyboard press. Add it inside the game loop after swapping buffers.
if (glfwGetKey( window, GLFW_KEY_Q ) == GLFW_RELEASE && !mac_moved){
int x, y;
glfwGetWindowPos(window, &x, &y);
glfwSetWindowPos(window, ++x, y);
} else {
mac_moved = true;
}
Define mac_moved as a static variable somewhere on the top.
static bool mac_moved = false;
来源:https://stackoverflow.com/questions/52509427/mac-mojave-opengl