如何在xcode中构建c ++ openGL项目?

时间:2014-08-18 10:31:35

标签: xcode macos opengl glfw glew

我试图在XCode 5中创建一个openGL项目,以便我可以在我的Mac上学习NeHe tutes。

我一直在关注www.open.gl的步骤 以下是我试过的步骤......

  • 我自制了glfw3,glew和glm
  • 我制作了一个新的静态C / C ++项目。
  • 我制作了一个主文件。
  • 我添加了openGL框架。
  • -framework openGL编译器标志添加到主文件中。
  • 我向用户搜索路径添加了brews路径,并始终搜索这些路径。
  • 我在主文件中包含了glfw,并尝试运行代码打开一个窗口。
  • 只有glew文件出现在lib中,但项目构建和运行成功但没有任何反应。
  • 也没有错误。

我在这里缺少什么?

#include "main.h"

#include <glfw3.h>
#include <thread>

int main()
{
    glfwInit();
//    std::this_thread::sleep_for(std::chrono::seconds(3));

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);

    glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);

    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", nullptr, nullptr); // Windowed
//    GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL", glfwGetPrimaryMonitor(), nullptr); // Fullscreen

    glfwMakeContextCurrent(window);

    while(!glfwWindowShouldClose(window))
    {
        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
        glfwSetWindowShouldClose(window, GL_TRUE);


    glfwTerminate();
}

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:0)

我不确定问题是什么,但本教程简单(使用cmake)并且现在正在使用: http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/
本教程说&#34; Mac OS不支持OpenGL 3.3。最近使用MacOS 10.7 Lion和兼容GPU的Mac可以运行OpenGL 3.2,但不能运行3.3&#34;所以这可能是我的问题。