Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include OpenGL Libraries in C++, Windows 7

I am reading through a "Getting Started with OpenGL" tutorial and I came across this text:

"If you are using C/C++, then you must first set up a build environment (Visual Studio project, GNU makefile, CMake file, etc) that can link to OpenGL. Under Windows, you need to statically link to a library called OpenGL32.lib (note that you still link to OpenGL32.lib if you're building a 64-bit executable. The "32" part is meaningless). Visual Studio, and most Windows compilers, come with this library."

I am just trying to write my source files using vim, I don't want to use an IDE like VS, and from my understanding the OpenGL libraries come with Windows 7 (correct me if I'm wrong). After this point the article doesn't really go into any more detail about how to include the OpenGL libraries, and my real question is, how do I include and use the OpenGL libraries in my source files?

Is it as simple as writing #include <name of lib> or do I need to do something else with my Programming environment like editing my path variables?

Edit: I'm using the MinGW g++/gcc compiler

like image 930
kjh Avatar asked Sep 11 '12 19:09

kjh


1 Answers

To get access to the include files, you need a special support library. There are more than one of these, but I would recommend GLEW. You can find the GLEW interface at http://glew.sourceforge.net/.

The reason for this is that only a very old version of OpenGL headers are available as default on Windows. The newer interface is available indirectly; you have to ask for function addresses. This is however done by GLEW for you.

So you only have to include < GL/glew.h>, and do some initialization with glewInit();

This is compatible with both Linux and Windows, especially as you use MinGW. When linking, I use the following:

MY_LIBS = -lglew32 -lopengl32 -lWs2_32 -lole32 -lcomctl32 -lgdi32 -lcomdlg32 -luuid

I can recommend the use of a generic makefile, see http://sourceforge.net/projects/gcmakefile/

Notice that you also have to setup a context for OpenGL, before initializing GLEW. This is done differently depending on the environment. It is done when you open a window. For portable libraries, I can recommend the glfw library or freeglut.

like image 99
Lars Pensjö Avatar answered Sep 21 '22 00:09

Lars Pensjö