3

I'm totally new to OpenGL, so I'm trying to compile my application at home. At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.

I'm trying to build a sphere in my app which contain the includes below:

#include <GL/glut.h>
#include <math.h>
#include <iostream>

So, since it contains Glut.h I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library and make it rock, but I had some problems.

I thought the windows version would come compiled and it didn't. The dlls are not inside the package as I expected to link them in my project properties so I tryed to use CMake to compile the glut but it didn't work. CMake returns to me the following log:

CMake Error: Cannot open file for write: C:/Program Files/Glut 3.7 Build/CMakeCache.txt.tmp
CMake Error: The source directory "C:/Program Files/Glut 3.7/glut-3.7" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
CMake Error: : System Error: No such file or directory
CMake Error: Unable to open cache file for save. C:/Program Files/Glut 3.7 Build/CMakeCache.txt
CMake Error: : System Error: No such file or directory

It says that the folder doesn't contain the CMake file.

My download link to glut (supposed to be windows, not sure cos of the error) is this http://www.opengl.org/resources/libraries/glut/glut37.zip

Normally I programm java, which I dont have so many headaches to setup the IDE..so take it easy please and now I ask:

What am I missing to make my OpenGL code run?

4

3 回答 3

4

Your teacher should help you at the first place.

I would like to inform you that GLUT library was abandoned since 1998. Last version is [3.7].But you are lucky!

"freeglut" is alternative to the OpenGL Utility Toolkit (GLUT) library. Everything you need is here, I recommend reading it all.

And to help you out, here you can find Windows binaries, look for link called: "Download freeglut 2.8.1-1 for MSVC".

After download, you must link the library folder, include folder and copy freeglut.dll to you project folder (inside Debug or Release folder). You can find dll files inside a bin folder. And after that, you can call #include "GL/glut.h" with no problems.

Good luck!

于 2013-10-26T09:01:05.360 回答
2

It doesn't compile with CMake. Open a Visual Studio command prompt and type nmake in the top level directory of the glut source code.

于 2013-10-26T08:31:34.557 回答
-1

At my university I have everything settle by my professor in the lab and there I use Linux. At home I'm using windows 8 with visual studio 2013.

Then the very first thing you absolutely must do is heading to your GPU maker's website, download the newest drivers from there and install them. That is, because the drivers installed by default with Windows 8 lack proper OpenGL functionality.

So, since it contains Glut.h

You mean glut.h – file names are case sensitive on most operating systems (Windows not among them). So for portability reasons you should care to write them with the proper spelling.

I went to http://www.opengl.org/resources/libraries/glut/glut_downloads.php#2 to download the library

The old GLUT library isn't maintained for over a decade. Use an alternative implementation like FreeGLUT and use that.

so I tryed to use CMake to compile the glut but it didn't work.

Okay, here you got no technical problem, but a lack of understanding. Essentially your brain got what I call "IDE rot": All those sugar coating and clicky-pointy action of IDEs obscure what actually is going on when a program is built. You'll have to bit the bullet there and understand how the interaction between the build control generators the build system the compiler and the linker works.

CMake is a build control generator: In CMake you describe the build dependencies of your program sources. From that CMake generates the actual build information for the build system used (GNU make and GCC on Linux; NMake and MSVC++ compiler on Windows for example).

Of course for CMake to work there must be an appropriate CMake configuration present. And in the case of GLUT that's definitely not there (the last official release of GLUT predates the first release of CMake.

Now you should really wonder: Why did you call "cmake" in the first place? I bet, because you always did it so far, or you read it somewhere, without even trying to understand what's going on.

What you did was folloing a Cargo Cult – it somehow resembles the actual process, it looks like it from the outside, but it doesn't yield results. Feynman's speech later coined the term Cargo Cult Programming; interesting enough I was using that term (consistently with its definition, just due to being familiar with Feynman's speech) without knowing that other people already had coined it in exactly the same way. Such a often it happens, that people will come up independently with the same term for it.

Normally I programm Java, which I don't have so many headaches to setup the IDE

Well, that's your problem right there. You only know how to click around in an IDE. Even when programming Java, with an IDE, you should get intimately familiar with the actual build process: Java compiler, JAR file creating, and so on.

What am I missing to make my OpenGL code run?

I bet not very much. It's a lack of understanding how the build process for software works and is controlled. You'll have to bite the bullet and learn that first. And for that I suggest you install Linux or FreeBSD, or at least Cygwin on your computer.

Windows is not a very good system to learn those things, because its been built around clicky GUIs. That is not to say that Windows was a bad operating system. It's juat that you want to have something you can experiment with and quickly go through various iterations of build tool option switches. A GUI can't give you that.

于 2013-10-26T10:10:55.267 回答