views:

989

answers:

3

I am trying to move an OpenGL app to Windows.

It was my understanding that Windows had a decent OpenGL implementation. But I'm starting to think that it doesn't...

Specifically, I use array buffers and glDrawArrays.

When I tried to compile my code in Visual Studio 2008 Pro, I received the following errors:

vertexbuffers.cpp(31) : error C3861: 'glGenBuffers': identifier not found
vertexbuffers.cpp(32) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
vertexbuffers.cpp(32) : error C3861: 'glBindBuffer': identifier not found
vertexbuffers.cpp(33) : error C2065: 'GL_ARRAY_BUFFER' : undeclared identifier
vertexbuffers.cpp(33) : error C2065: 'GL_STATIC_DRAW' : undeclared identifier
vertexbuffers.cpp(33) : error C3861: 'glBufferData': identifier not found

When I examined <GL\gl.h> (contained in C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl), I saw:

/* ClientArrayType */ 
/*      GL_VERTEX_ARRAY */
/*      GL_NORMAL_ARRAY */
/*      GL_COLOR_ARRAY */

Update but it would seem that those contants get defined elsewhere.

How am I supposed to generate buffers if I don't have access to those functions?

The documentation doesn't say that those array types are disabled. How do I get access to the real implementation on OpenGL on Windows?

+2  A: 

The #defines are commented out in the header file whenever they would otherwise be repeated. Look at line 1054 of gl.h:

/* vertex_array */
#define GL_VERTEX_ARRAY                   0x8074

If this #define is actually missing then you should probably replace the file with a fresh copy.

If you look at the documentation for glGenBuffers you will see that it is only available in OpenGL 1.5 and higher. The header file for Windows only comes with OpenGL 1.2 and you should use the extension mechanism to access the newer functionality. If you call wglGetProcAddress with the function name, e.g.

void (__stdcall *glGenBuffers)(GLsizei,GLuint*) =
    wglGetProcAddress("glGenBuffers");

then you have a pointer to the function.

jheriko
You have better eyes than me. Thank you for the reference. Unfortunately, I still have errors revolving around glBindBuffer.
Frank Krueger
edited after i looked at the errors you were recieving. unfortunately the header is 1.2 only, but there are easy fixes. :)
jheriko
+2  A: 

It would seem that the buffer functions are only available on Windows as extension methods.

OpenGL provides glext.h that declares pointers to all of these functions. It is then up to my app to use wglGetProcAddress to get pointers to the functions.

For example:

PFNGLGENBUFFERSPROC myglBindBuffers = 
    (PFNGLGENBUFFERSPROC)wglGetProcAddress("glGenBuffersARB");

Thankfully, I only have to do it for about 4 functions. Unfortunately, I now have to add platform-dependent code to my app.

Frank Krueger
+2  A: 

You might give GLEW a shot:

http://glew.sourceforge.net/

I'm pretty sure I used it at some time in the past, and makes this sort of thing a little easier and more portable.

BigSandwich
Great link, thank you very much.
Frank Krueger