Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trouble porting OpenGL app to Windows

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?

like image 231
Frank Krueger Avatar asked Mar 24 '09 20:03

Frank Krueger


4 Answers

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.

like image 96
BigSandwich Avatar answered Nov 17 '22 20:11

BigSandwich


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.

like image 41
jheriko Avatar answered Nov 17 '22 18:11

jheriko


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.

like image 21
Frank Krueger Avatar answered Nov 17 '22 18:11

Frank Krueger


Microsoft's support for OpenGL stretches only as far as OpenGL-1.1 up to Windows XP, and OpenGL-1.4 starting with Vista. Any OpenGL functionality beyond those must be delivered and supported by the installable client driver (ICD), i.e. the GPU driver's OpenGL implmenentation. To access the advanced functionality, OpenGL provides the so called Extension System, formed by wglGetProcAddress, which is kind of like GetProcAddress for DLLs, but gives access to functions of the OpenGL implementation (=driver).

To make things easier, nice wrapper libraries like GLEW have been developed, which do all the grunt work initializing all the available OpenGL extensions, providing them to the end user.

like image 1
datenwolf Avatar answered Nov 17 '22 20:11

datenwolf