SOIL: 'Unable to open file' in C++ and OpenGL with Xcode

依然范特西╮ 提交于 2019-12-04 17:12:50

Ok, after hours of searching and playing with Xcode, I finally got it ...

First problem was that the image resources in the projects navigator in Xcode are not automatically in your applications path after buildung. So you have to click on your project in your project navigator (it's the root of all files in the project navigator). Then select your target, click on the tab "Build Phases". Now it's important to add a completely new build phase! Click on "Add Build Phase" button and select "Add copy files". You will get a new "Copy files" element. Destination should be automatically "Resources". Now click on the "+" and add all image files you want to use in your application. They will now be copied on build to your application path or, if you have set up, to the subpath. If you set up no subpath the path to your image will be the root directory of your app so you can just access the file via "filename.png" or whatever.

Second problem was the EXC_BAD_ACCESS ... The LoadGLTextures() function was just on the wrong place ... The new code (just the main function changed, so I just paste the main) is:

int main(int argc, char** argv)
{
    glutInit(&argc, argv);

    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(640, 480);

    windowId = glutCreateWindow("GLUT Program");

    LoadGLTextures();

    //glutFullScreen();

    glutKeyboardFunc(keyPressed);
    glutKeyboardUpFunc(keyUp);
    glutSpecialFunc(keySpecialPressed);
    glutSpecialUpFunc(keySpecialUp);
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);

    glutMainLoop();
    return EXIT_SUCCESS;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!