xcode Mac OSX 10.8.4 上带有 GLFW3 的现代 OpenGL - 缺少 glGenVertexArrays() 和 glBindVertexArray()?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19825582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 04:16:05  来源:igfitidea点击:

Modern OpenGL with GLFW3 on Mac OSX 10.8.4 - missing glGenVertexArrays() and glBindVertexArray()?

xcodemacosopengl

提问by TATN

I'm trying to setup GLFW3 for my OpenGL project on Xcode 5 (Mac OSX 10.8.4). I have successfully installed and linked my project to GLFW3 no problem. I even got a window successfully created with the project, and I were able to detect mouse and keyboard inputs with the window, so I believe that I got GLFW3 hooked up correctly (or at least it seemed so).

我正在尝试在 Xcode 5 (Mac OSX 10.8.4) 上为我的 OpenGL 项目设置 GLFW3。我已成功安装并将我的项目链接到 GLFW3,没问题。我什至用该项目成功创建了一个窗口,并且我能够检测到该窗口的鼠标和键盘输入,所以我相信我正确地连接了 GLFW3(或者至少看起来是这样)。

However, the problem occured when I tried to draw an object. This was the code snippet where the error showed up:

但是,当我尝试绘制对象时出现问题。这是出现错误的代码片段:

#include <GLFW/glfw3.h>    

void LoadObject()
{
    glGenVertexArrays(1, &VAO_myObj); // ERROR : Use of undeclared identifier 'glGenVertexArrays'
    glBindVertexArray(VAO_myObj);     // ERROR : Use of undeclared identifier 'glBindVertexArray'


    glGenBuffers(1, &VBO_myObj);                // No error
    glBindBuffer(GL_ARRAY_BUFFER, VBO_myObj);   // No error

    glBufferData(blah blah blah);      // No error

    glEnableVertexAttribArray(0);      // No error
    glVertexAttribPointer(blah);       // No error


    glBindBuffer(GL_ARRAY_BUFFER, 0);  // No error
    glBindVertexArray(0);              // ERROR : Use of undeclared identifier 'glBindVertexArray'
}

So, this led me to believe that somehow GLFW3 failed to link to those functions (?). When I typed "glGen..." to Xcode, I only saw the following 4 functions on the popup window:

所以,这让我相信 GLFW3 以某种方式未能链接到这些功能(?)。当我在 Xcode 中输入“glGen...”时,我只在弹出窗口中看到了以下 4 个函数:

void glGenBuffers(GLsizei n, GLuint * buffers)
GLuint glGenLists(GLsizei range)
void glGenQueries(GLsizei n, GLuint * ids)
void glGenTextures(GLsizei n, GLuint * textures)

So, it was most likely that glGenVertexArrays() was indeed missing from the library.

因此,很可能 glGenVertexArrays() 确实从库中丢失了。

Similarly for "glBind...", when I type the name to Xcode, only these showed up on the popup window:

与“glBind...”类似,当我在 Xcode 中输入名称时,只有这些显示在弹出窗口中:

void glBindAttribLocation(GLuint program, GLuint index, const GLchar * name)
void glBindBuffer(GLenum target, GLuint buffer)
void glBindTexture(GLenum target, GLuint texture)

No where did I see the glBindVertexArray() on the list.

我没有在哪里看到列表中的 glBindVertexArray()。

So, it seems that glGenVertexArrays() and glBindVertexArray() are missing. But how could they have missed such important functions? So, it's most likely that I myself am missing something here.

因此,似乎缺少 glGenVertexArrays() 和 glBindVertexArray() 。但是他们怎么会错过这么重要的功能呢?所以,很可能我自己在这里遗漏了一些东西。

I'm just wondering if any one has encountered this issue with GLFW3 with Xcode 5 before? By the way, I'm not using glew or any other OpenGL support stuff. I'm only using GLFW3.

我只是想知道以前是否有人在 Xcode 5 中使用 GLFW3 遇到过这个问题?顺便说一句,我没有使用glew 或任何其他OpenGL 支持的东西。我只使用 GLFW3。

I would appreciate any hint or pointer regarding this issue.

我将不胜感激有关此问题的任何提示或指示。

On the side note, which tool (beside glfw) would you recommend to get a window up on a Mac for a modern (shader-based) OpenGL project?

在旁注中,您建议使用哪种工具(glfw 旁边)在 Mac 上为现代(基于着色器的)OpenGL 项目打开一个窗口?

Thank you in advance for your help.

预先感谢您的帮助。

回答by Andon M. Coleman

You need to include <OpenGL/gl3.h>on OS X in order to use OpenGL 3.2 core API calls. Be aware that if you include both <OpenGL/gl.h>and <OpenGL/gl3.h>you may receive a compiler warning, this is because gl3.hserves two purposes:

您需要<OpenGL/gl3.h>在 OS X上包含才能使用 OpenGL 3.2 核心 API 调用。请注意,如果您同时包含两者<OpenGL/gl.h>并且<OpenGL/gl3.h>您可能会收到编译器警告,这是因为有gl3.h两个目的:

  1. Provides the functions, enums and typedefs for core OpenGL 3.2
  2. Eliminates deprecated functions, enums and typedefs that are invalid in core OpenGL 3.2
  1. 为核心 OpenGL 3.2 提供函数、枚举和类型定义
  2. 消除了在核心 OpenGL 3.2 中无效的不推荐使用的函数、枚举和类型定义


They are effectively mutually exclusive, the proper header depends on the context version you are using:


它们实际上是互斥的,正确的标头取决于您使用的上下文版本:

  • MacOS X 10.7+: (OpenGL: 2.1)

    • #include <OpenGL/gl.h>


  • MacOS X 10.7+: (OpenGL: 3.2 core)

    • #include <OpenGL/gl3.h>
  • MacOS X 10.7+:(OpenGL:2.1

    • #include <OpenGL/gl.h>


  • MacOS X 10.7+:(OpenGL:3.2核心

    • #include <OpenGL/gl3.h>

回答by ryanshow

GLFW3 includes <GL/gl.h>by default. In order to include <GL/gl3.h>, you need to stick #define GLFW_INCLUDE_GLCOREARBsomewhere before #include <GLFW/glfw3.h>

GLFW3<GL/gl.h>默认包含。为了包含<GL/gl3.h>,您需要在#define GLFW_INCLUDE_GLCOREARB某处之前粘贴#include <GLFW/glfw3.h>

On the Mac OSX installation of GLFW3, using homebrew, the define macro before the the include will use OpenGL/gl3.h. It can be see within the header file:

在 GLFW3 的 Mac OSX 安装上,使用自制软件,include 之前的定义宏将使用OpenGL/gl3.h. 可以在头文件中看到:

#if defined(__APPLE__)
 #if defined(GLFW_INCLUDE_GLCOREARB)
  #include <OpenGL/gl3.h>
  #if defined(GLFW_INCLUDE_GLEXT)
   #include <OpenGL/gl3ext.h>
  #endif
...

The define options are outlined in the build guidefor glfw3. This alleviates the compiler warning too.

在glfw3的构建指南中概述了定义选项。这也减轻了编译器警告。