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

I am trying to configure GLFW3 for my OpenGL project on Xcode 5 (Mac OSX 10.8.4). I successfully installed and linked my project with GLFW3 without any problems. I even got a window that was successfully created with the project, and I was able to detect mouse and keyboard inputs with the window, so I believe that I connected GLFW3 correctly (or at least it seemed so).

However, a problem arose when I tried to draw an object. This was a piece of code in which an error appeared:

#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, it made me believe that somehow GLFW3 could not connect these functions (?). When I typed "glGen ..." in Xcode, I saw only 4 functions in a popup:

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

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

Similarly for "glBind ...", when I enter the name in Xcode, only in the popup they were displayed:

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

No where I saw glBindVertexArray () in the list.

So it seems that glGenVertexArrays () and glBindVertexArray () are missing. But how could they miss such important features? Therefore, most likely, I missed something myself.

I'm just wondering if anyone has encountered this problem with GLFW3 with Xcode 5 before? By the way, I do not use glew or other OpenGL support tools. I use only GLFW3.

I would appreciate any hint or pointer to this problem.

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

Thank you in advance for your help.

+6
source share
2 answers

You need to enable <OpenGL/gl3.h> in OS X to use the basic OpenGL 3.2 API calls. Keep in mind that if you include both <OpenGL/gl.h> and <OpenGL/gl3.h> , you may get a compiler warning because gl3.h has two purposes:

  • Provides functions, enumerations, and typedef for the OpenGL 3.2 kernel
  • Eliminates obsolete functions, enumerations, and typedef, which are mostly invalid in OpenGL 3.2


They are effectively mutually exclusive, the correct title 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>
+15
source

GLFW3 includes <GL/gl.h> by default. To enable <GL/gl3.h> , you need to insert #define GLFW_INCLUDE_GLCOREARB somewhere earlier #include <GLFW/glfw3.h>

On Mac OSX, to install GLFW3 using homebrew, the define macro will use OpenGL/gl3.h before inclusion. This can be seen in the header file:

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

Definition parameters are described in the build guide for glfw3. It also facilitates compiler warning.

+10
source

Source: https://habr.com/ru/post/957550/


All Articles