Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

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:

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.

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

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.

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.

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.

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?

Thank you in advance for your help.

like image 435
TATN Avatar asked Nov 07 '13 00:11

TATN


1 Answers

GLFW3 includes <GL/gl.h> by default. In order to include <GL/gl3.h>, you need to stick #define GLFW_INCLUDE_GLCOREARB somewhere before #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:

#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 guide for glfw3. This alleviates the compiler warning too.

like image 90
ryanshow Avatar answered Sep 22 '22 11:09

ryanshow