Incorrect porting of an OpenGL application to Windows

I am trying to move an OpenGL application to Windows.

I realized that Windows has a decent OpenGL implementation. But I'm starting to think that this is not so ...

In particular, 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 */ 

Refresh , but it looks like these members will be defined elsewhere.

How can I create buffers if I do not have access to these functions?

The documentation does not indicate that these types of arrays are disabled. How to access real implementation in OpenGL on Windows?

+4
source share
4 answers

#defines are commented out in the header file whenever they are otherwise repeated. Take a look at line 1054 gl.h:

 /* vertex_array */ #define GL_VERTEX_ARRAY 0x8074 

If this #define is really missing, you should probably replace the file with a new copy.

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

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

then you have a function pointer.

+5
source

You can make GLEW a shot:

http://glew.sourceforge.net/

I am pretty sure I used it in my time in the past, and makes such things a little easier and more portable.

+8
source

It appears that buffer functions are only available on Windows as extension methods.

OpenGL provides glext.h , which declares pointers to all of these functions. Then for my application use wglGetProcAddress to get function pointers.

For instance:

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

Fortunately, I only need to do this for 4 functions. Unfortunately, now I have to add platform code to my application.

+2
source

Support for Microsoft OpenGL extends only to OpenGL-1.1, to Windows XP and OpenGL-1.4, starting with Vista. Any functionality of OpenGL, other than those that must be provided and supported by the installed client driver (ICD), that is, the OpenGL driver of the GPU driver. To access the advanced functionality, OpenGL provides a so-called Extension System formed by wglGetProcAddress, which is like GetProcAddress for a DLL, but provides access to the OpenGL implementation functions (= driver).

To simplify the work, beautiful wrapper libraries such as GLEW have been developed that do all the grunt work, initializing all available OpenGL extensions, providing them to the end user.

+1
source

All Articles