glutInit, etc.

I am learning OPenGL coding from the book “OPenGL Programing Guide” by Sheiner and in chapter 4 regarding color and shading, he mentions calls as follows:

glutInit(…);
glutInitDisplay(…);
glutInitWindowSize(…);
others

I am getting unidentified variables on all of these elements when I try to compile the routines. I suspect that they are defined in an include file but not sure. I have the following includes:

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <stdio.h>
#include <math.h>

Any ideas? Sid Kraft

Functions beginning with glut are part of the GLUT library (GL Utility Toolkit). These are not a part of OpenGL. OpenGL (as you probably read) does not interface with the windowing system, and GLUT is a simple library that does that. You should include <gl/glut.h> and link with the GLUT library, possibly by adding -lGLUT to your linker options (this will depend on your environment).

I see you have a <windows.h> include reference … since you are in windows it may be helpful for you to see Using Glut in Windows if you are using VisualStudio toolset.

Note there are other toolsets / “environments”, the -lglut reference is helpful for users of GNU Compiler Collection used on Linux, MacOS w/ fink, and Windows MinGW users, Dev-C++, to name a few.

todayman:

Sid Kraft here: I included <gl\glut.h> in my program, when I tried to compile, gave me “no such include exists”??? What am I doing wrong?

Well, quite simply, gl/glut.h isn’t there. It may be in another location; on my Mac, it’s in GLUT/glut.h . You may also not have GLUT installed. You can get it here. I’m not familiar with your environment (I’m on Mac) so I can’t really help more with this kind of issue. You need to find GLUT, installing it if it’s not there, and then properly reference it from your source.

What compiler are you using? What OS?

Did you follow the instructions at Using GLut with Windows? What is the full path to the location of the GLUT.h file you installed to your hard drive after following the instruction on that link?

Note do not use the "" slash in ANSI C with the include directives. That may work on some compilers and fail with others. Strictly speaking in ANSI C using a "" in an include directive is undefined. The correct path delimiter to use is the “/” forward slash. I suspect that still won’t solve your problem but it is good practice to follow the ANSI standards to avoid problems later on.

Use: #include <GL/glut.h>
Do not use:#include <GL\glut.h>
This is a general rule that applies to all “#include <path/path/header.h>” not just GLUT.

What really needs to be done is to tell your compiler where in its “include” path to find the “GL/glut.h” file that you downloaded and installed to your hardrive. You will have to do the same with the “library” path specification also.

Well todayman: I finally got gl.glut.h downloaded and included. I compiled successfully but now when I go to “link” the linker says “cannot find glut32.lib”, seems like I take 3 steps forward, 4 steps back. I would think that WinXP Pro with SP3 would have all of the updates??? Maybe I am too optimistic - ha. Any ideas? Sid Kraft
P.S. Are some mistakes in the gl.glut.h, had to correct before it would execute???

You haven’t answered my questions so it is hard to help. Especially what compiler are you using?

If you use gcc then its easy since you just have to specify the library path to the folder where you saved your library. If you put it in c:\foo\bar then you would have
g++ -L/c/foo/bar main.o – but better than that with gcc tools you usually see the libraries in standard locations like /usr/local/lib and header in /usr/local/include. But you are not using gcc I suppose so this is for another audience that may see this post. I use dev-c++ in windows because it is gcc based.

If you are using a Microsoft specific compiler, you have to make sure you copy files to the correct library folder:
For Visual Studio 2008: (from link VS2008+GLUT)
glut32.dll to"Windows\System”
glut32.lib to “Program Files\Microsoft Visual Studio 9.0\VC\lib”
glut.h to “Program Files\Microsoft Visual Studio 9.0\VC\include\GL”

For Visual Studio 2003 (from link Using Glut with Windows):
glut32.dll for Windows XP | Server 2003 to "C:\WINDOWS\system"
or for Windows 2000: to "C:\WINNT\system"
glut32.lib to “C:\Program Files\Microsoft Visual Studio NET 2003\Vc7\PlatformSDK\Lib”
glut.h to “C:\Program Files\Microsoft Visual Studio NET 2003\Vc7\PlatformSDK\Include\GL”

You get the point – you have to know what Microsoft compiler/what version/what year compiler you are using and put the *.lib, *.dll, *.h files in the “correct” places.

Notice how messy Microsoft is with its compilers – every new version changes where its standard libraries / headers are expected to be. You can get around that if you fiddle with the “link” menu options and set the library path… Anyhow I use linux/gcc or windows/dev-c++ tools to avoid all this microsoft crust. But that is beside the point. Any external libraries not a part of the OS will have to be treated this way – GLUT in Windows is no exception.