简体   繁体   English

OpenGL SuperBible第5版设置问题

[英]OpenGL SuperBible 5th edition set-up problems

Ok, so I've recently got the OpenGL SuperBible, and set up the directories on Code::Blocks to freeglut and GLTools.h but these #include statements will not work: 好的,所以我最近得到了OpenGL SuperBible,并将Code :: Blocks上的目录设置为freeglutGLTools.h但这些#include语句不起作用:

#include <GLtools.h>
#include <GLShaderManager.h>
#include <iostream>
#include <GL/glut.h>

To set the directories I went through "Settings" -> "Compiler and Debugger..." -> "Search Directories" tab and added this under the "Compiler" tab (there's also "Linker" and "resource Compiler" tabs): 要设置目录,我通过“设置” - >“编译器和调试器...” - >“搜索目录”选项卡,并在“编译器”选项卡下添加它(还有“链接器”和“资源编译器”选项卡):

C:\CodeBlocks\SB5\Src\GLTools\include

and

C:\CodeBlocks\SB5\freeglut-2.6.0\include

These are the errors I get: 这些是我得到的错误:

C:\CodeBlocks\SB5\freeglut-2.6.0\include\GL\freeglut_std.h|60|warning: "NOMINMAX" redefined|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\include\c++\mingw32\bits\os_defines.h|46|warning: this is the location of the previous definition|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|225|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|226|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|227|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|228|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|229|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|230|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|231|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|232|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|233|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|234|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|235|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|236|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|237|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|238|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|239|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|240|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|241|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|242|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|243|error: expected constructor, destructor, or type conversion before 'const'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|244|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|245|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|246|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|247|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|248|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|249|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|250|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|251|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|252|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|253|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|254|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|255|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|256|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|257|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|258|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|259|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|260|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|261|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|262|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|263|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|264|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|265|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|266|error: 'GLAPI' does not name a type|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|267|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|268|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|269|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|270|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|271|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|272|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|273|error: expected constructor, destructor, or type conversion before 'void'|
c:\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\GL\glu.h|274|error: expected constructor, destructor, or type conversion before 'void'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build finished: 50 errors, 2 warnings ===|

It seems as though there's some kind of conflict going on between the header files, although it's coming up with errors at glu.h when I didn't even include that. 似乎在头文件之间存在某种冲突,尽管当我甚至没有包含它时,它会在glu.h出现错误。

Please help! 请帮忙! and THANKS! 谢谢! =) =)

I ran into the same problem as you did when trying to compile the Triangle example in the SuperBible (5th Edition). 我在尝试编译SuperBible(第5版)中的Triangle示例时遇到了同样的问题。 I also like to use Code::Blocks with MinGW. 我也喜欢使用Code :: Blocks和MinGW。 I have been doing some research, and I think I've managed to solve most issues. 我一直在做一些研究,我想我已经设法解决了大多数问题。

The first thing to do is to correctly set up our environment. 首先要做的是正确设置我们的环境。 We start by configuring the libraries, freeglut and GLTools. 我们首先配置库,freeglut和GLTools。

Before getting started, make sure you have the latest version of MinGW installed, with MSYS. 在开始之前,请确保使用MSYS安装了最新版本的MinGW。 Check that you added c:/MinGW/bin to the path variable. 检查是否已将c:/ MinGW / bin添加到路径变量中。 Also get a good file extractor like 7z, that can unpack .tar and .gz files. 还可以获得像7z这样的好文件提取器,它可以解压缩.tar和.gz文件。

I'm going to be perhaps too detailed, but these things were not obvious to me until I researched them. 我可能会过于详细,但在研究它们之前,这些事情对我来说并不明显。

To set up freeglut-2.6.0, the first thing we are going to do is compile the static library from the source: 要设置freeglut-2.6.0,我们要做的第一件事是从源代码编译静态库:

  1. Go to freeglut's site and download the latest version (currently 2.6.0) 转到freeglut的网站并下载最新版本(目前为2.6.0)

  2. Create ac:/libs directory, and unpack the freeglut package there. 创建ac:/ libs目录,并在那里解压缩freeglut包。 You should end up with a directory called c:/libs/freeglut-2.6.0. 您应该得到一个名为c:/libs/freeglut-2.6.0的目录。

  3. Run MSYS (c:/MinGW/msys/1.0/msys.bat). 运行MSYS(c:/MinGW/msys/1.0/msys.bat)。 You should be in your home directory (denoted by ~ after your user and host in the top line). 您应该在您的主目录中(在您的用户和主机位于顶行之后用〜表示)。

  4. Type "cd /c/libs/freeglut-2.6.0/src" and press [enter]. 输入“cd /c/libs/freeglut-2.6.0/src”并按[enter]。 The ~ will change to /c/libs/freeglut-2.6.0/src to denote your current working directory. 〜将更改为/c/libs/freeglut-2.6.0/src以表示您当前的工作目录。

  5. Type "gcc -O2 -c -DFREEGLUT_STATIC *.c -I../include" and press [enter]. 输入“gcc -O2 -c -DFREEGLUT_STATIC * .c -I ../ include”并按[enter]。 What we are doing here is calling the gcc compiler, instructing it to use O2 optimization, set the flag FREEGLUT_STATIC, and compile every source file in this directory into .o object files, and to look for headers in "../include". 我们在这里做的是调用gcc编译器,指示它使用O2优化,设置标志FREEGLUT_STATIC,并将此目录中的每个源文件编译为.o目标文件,并在“../include”中查找标头。 That means to go down one level (to /c/libs/freeglut-2.6.0) and look for the /include directory there. 这意味着向下一级(到/c/libs/freeglut-2.6.0)并在那里查找/ include目录。

  6. Type "ar rcs libfreeglut32_static.a *.o" and press enter. 输入“ar rcs libfreeglut32_static.a * .o”并按Enter键。 To the best of my understanding, ar is the utility that compiles static libraries, archive files (.a). 据我所知,ar是编译静态库,归档文件(.a)的实用程序。 We're telling it to create "libfreeglut32_static.a" from every object file (.o) we just compiled in the previous step. 我们告诉它从我们刚刚在上一步中编译的每个目标文件(.o)创建“libfreeglut32_static.a”。

  7. Create a /lib directory in /c/libs/freeglut-2.6.0. 在/c/libs/freeglut-2.6.0中创建/ lib目录。 Then cut the library we just created and paste it in this directory. 然后剪切我们刚刚创建的库并将其粘贴到此目录中。 The final location of the freeglut library should be "c:/libs/freeglut-2.6.0/lib/libfreeglut32_static.a". freeglut库的最终位置应为“c:/libs/freeglut-2.6.0/lib/libfreeglut32_static.a”。

Go to this site for further reference on compiling freeglut with MinGW. 有关使用MinGW编译freeglut的更多参考,请访问此站点

Before getting GLTools working, make sure freeglut works. 在让GLTools工作之前,请确保freeglut有效。

  1. Open Code::Blocks, and close any open projects. 打开Code :: Blocks,关闭所有打开的项目。 Go to "Settings->Compiler and Debugger" and open the "Search Directory" tab. 转到“设置 - >编译器和调试器”,然后打开“搜索目录”选项卡。 In Compiler, add the directory "c:/libs/freeglut-2.6.0/include/". 在编译器中,添加目录“c:/libs/freeglut-2.6.0/include/”。 In Linker, add "c:/libs/freeglut-2.6.0/lib/". 在链接器中,添加“c:/libs/freeglut-2.6.0/lib/”。

  2. Create an empty project. 创建一个空项目。 Add a test.cpp file. 添加test.cpp文件。 Add the single function int main (){return 0;} . 添加单个函数int main (){return 0;}

  3. It should build with no problem. 它应该没有问题。

  4. Add #define FREEGLUT_STATIC and #include <GL/glut.h> . 添加#define FREEGLUT_STATIC#include <GL/glut.h>

  5. Try to compile. 尝试编译。 It will fail. 它会失败。

  6. Right click on the Project and go to "Build Options". 右键单击项目并转到“构建选项”。 Make sure you are editing the options for the whole project, not the Debug or Release targets. 确保您正在编辑整个项目的选项,而不是编辑调试或发布目标。 Move to the Linker tab, and add to Link libraries "freeglut32_static". 移至链接器选项卡,然后添加到链接库“freeglut32_static”。

  7. Try to compile. 尝试编译。 It will fail again. 它会再次失败。 The compiler will throw "undefined reference to" errors, listing a bunch of functions. 编译器将抛出“未定义的引用”错误,列出一堆函数。 Copy the name of the first one, and look it up in google. 复制第一个名称,然后在谷歌中查找。 Go to the microsoft search result (first or second result). 转到Microsoft搜索结果(第一个或第二个结果)。 It will describe the function, and more importantly, tell you what library that function is in. 它将描述该函数,更重要的是,它将告诉您该函数所在的库。

  8. The library will be called "something.lib". 该库将被称为“something.lib”。 Go to Build Options again, and add "something" to the link libraries. 再次转到Build Options,并在链接库中添加“something”。

  9. Try compiling again. 再次尝试编译。 It will fail once more. 它会再次失败。 If you bother to check, you'll see that the first "undefined reference" has changed however. 如果你懒得检查,你会发现第一个“未定义的引用”已经改变了。 Repeat 7 and 8 until it stops failing. 重复7和8直到它停止失败。 The additional libraries you'll have to add to get freeglut working are "Winmm", "Gdi32" and "Opengl32". 为了获得freeglut工作,你必须添加的附加库是“Winmm”,“Gdi32”和“Opengl32”。

  10. Compile once more. 再次编译。 test.exe should be created. 应该创建test.exe。 Yay! 好极了!

Ok, now that we have freeglut working, it's time to break it again. 好了,现在我们已经有了freeglut工作,现在是时候再次打破它了。 We are first going to recreate the GLTools library, since the SB5 only distributes the .lib version. 我们首先要重新创建GLTools库,因为SB5只分发.lib版本。

  1. The SB5 download should have 4 main directories; SB5下载应该有4个主目录; freeglut, linux, visualstudio and src. freeglut,linux,visualstudio和src。 Go into src. 进入src。 Copy the GLTools directory and paste it in "c:/libs". 复制GLTools目录并将其粘贴到“c:/ libs”中。

  2. Create a lib directory within GLTools. 在GLTools中创建一个lib目录。 There should now be three directories within it, /include, /src and /lib. 现在应该有三个目录,/ include,/ src和/ lib。

  3. Bring up MSYS again. 再次启动MSYS。 Type "cd /c/libs/GLTools/src" and press [enter]. 输入“cd / c / libs / GLTools / src”并按[enter]。

  4. Like we did with freeglut, we're going to grab all the tools' code and link it into a single library. 就像我们使用freeglut一样,我们将抓住所有工具的代码并将其链接到一个库中。 Type "g++ -c *.cpp -I../include" and press [enter], followed by "ar rcs libGLTools.a *.o". 输入“g ++ -c * .cpp -I ../include”并按[enter],然后按“ar rcs libGLTools.a * .o”。

  5. Cut the output, libGLTools.a, into "c:/libs/GLTools/lib". 将输出libGLTools.a剪切为“c:/ libs / GLTools / lib”。

  6. We do the same for glew. 我们也为glew做同样的事情。 Type "g++ -c glew.c -I../include" followed by [enter]. 输入“g ++ -c glew.c -I ../include”,然后输入[enter]。 Then "ar rcs libglew.a glew.o". 然后“ar rcs libglew.a glew.o”。

  7. In Code::Blocks, go back to "Settings->Compiler and Debugger" and open the "Search Directory" tab. 在Code :: Blocks中,返回“Settings-> Compiler and Debugger”并打开“Search Directory”选项卡。 In Compiler, add the directory "c:/libs/GLTools/include/". 在编译器中,添加目录“c:/ libs / GLTools / include /”。 In Linker, add "c:/libs/GLTools/lib/". 在Linker中,添加“c:/ libs / GLTools / lib /”。

  8. I promised we'd break what we had done before, didn't I? 我答应过我们打破以前做过的事,不是吗? Add to our test program #include <GLTools.h> and try to build the project. 添加到我们的测试程序#include <GLTools.h>并尝试构建项目。 You should get a slew of "'GLAPI' does not name a type" errors. 你应该得到一大堆“'GLAPI'并没有命名类型”的错误。 This is happening because, at some point (not sure where myself) GLAPI is not getting defined. 这种情况正在发生,因为在某些时候(不确定我自己)GLAPI没有被定义。 Or it is getting defined wrong. 或者它被定义错了。

This is worth investigating, if you've never worked with libraries like this (I haven't, so it's a learning experience for me as well). 这是值得研究的,如果你从未与这样的图书馆合作过(我没有,所以这对我来说也是一次学习经历)。 When we include "glut.h", if you open the header file you'll see it is simply including "freeglut_std.h". 当我们包含“glut.h”时,如果你打开头文件,你会发现它只包含“freeglut_std.h”。 So you open that file, and it has a bunch of preprocessor commands. 所以你打开那个文件,它有一堆预处理器命令。

Run a search for GLAPI in the document, and we find out it doesn't define it here. 在文档中运行搜索GLAPI,我们发现它没有在此定义它。 It does, however, include <GL/gl.h> and <GL/glu.h> . 但它确实包括<GL/gl.h><GL/glu.h> So open gl.h and run a search there. 所以打开gl.h并在那里运行搜索。

Bingo! 答对了! We can see a few commands that play around with our GLAPI definition. 我们可以看到一些与我们的GLAPI定义相关的命令。 This is a little confusing, but we're going to copy what the preprocessor normally does. 这有点令人困惑,但我们将复制预处理器通常所做的事情。 So we have these lines in there: 所以我们在那里有这些线:

/* GLAPI, part 1 (use WINGDIAPI, if defined) */
#if defined(__WIN32__) && defined(WINGDIAPI)
#  define GLAPI WINGDIAPI
#endif

/* GLAPI, part 2 */
#if !defined(GLAPI)
#  if defined(_MSC_VER)                        /* Microsoft Visual C++ */
#    define GLAPI __declspec(dllimport)
#  elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
#    define GLAPI __stdcall
#  else                                        /* Others (e.g. MinGW, Cygwin, non-win32) */
#    define GLAPI extern
#  endif
#endif

We can search freeglut_std.h and find out WINGDIAPI is not defined. 我们可以搜索freeglut_std.h并找出WINGDIAPI没有定义。 So we skip the first block. 所以我们跳过第一个块。 From the second block, we can see that the line we want is #define GLAPI extern . 从第二个块开始,我们可以看到我们想要的行是#define GLAPI extern

What seems to be happening is, then, that one of the headers in GLTools is messing up this definition for us. 那么,似乎正在发生的事情是,GLTools中的一个标题正在为我们弄乱这个定义。 There's little to do but try to figure out where the problem is. 除了试图找出问题所在之外,没有什么可做的。

GLTools doesn't say anything about GLAPI, but includes <windows.h> and <GL/glew.h> before <GL/gl.h> . GLTools没有说GLAPI,但在<GL/gl.h>之前包含<windows.h><GL/glew.h> <GL/gl.h> glew.h defines GLAPI a couple of times, but because there's no identation in the code it's kind of confusing to tell if the code is being entered or not. glew.h多次定义GLAPI,但由于代码中没有标识,因此判断代码是否输入有点令人困惑。 What is clear, though, is that for our purposes GLAPI has to be defined as extern. 但是,很明显,为了我们的目的,GLAPI必须被定义为extern。 So we're going to do a quick hack in our test.cpp and define GLAPI as extern right ahead of the command to include . 因此,我们将在test.cpp中快速入侵,并在命令包含之前将GLAPI定义为extern。

#include <GLTools.h>

#define FREEGLUT_STATIC
#define GLAPI extern
#include <GL/glut.h>

It's still going to be broken, but we should get an exiting NEW error! 它仍然会被打破,但我们应该得到一个退出的新错误! So we compile and.... 所以我们编译和....

Huh. 呵呵。 It compiled with no errors. 它编译没有错误。 That shouldn't have happened. 那不应该发生。 But then, we're not calling any of the functions in GLTools, so maybe it's not so strange. 但是,我们并没有调用GLTools中的任何函数,所以也许它并不那么奇怪。 We'll press our luck and add the second include in triangle.ccp, #include <GLShaderManager.h> . 我们将运气好,并在triangle.ccp, #include <GLShaderManager.h>添加第二个包含。 And compile, and again no errors. 并编译,再没有错误。

Ok, so we are almost ready to build the example. 好的,我们几乎准备好构建示例。 Now we start filling test.cpp with the contents of triangle.cpp, and test when it fails. 现在我们开始使用triangle.cpp的内容填充test.cpp,并在失败时进行测试。 I start by adding 我首先补充说

GLBatch triangleBatch;
GLShaderManager shaderManager;

outside of main, and there we go, a couple of undefined references. 在main之外,我们去了几个未定义的引用。 That's more like it. 这还差不多。 So we open Build options (remember to specify the whole project, not the release or debug targets) and add GLTools to Link libraries. 所以我们打开Build选项(记得指定整个项目,而不是发布或调试目标)并将GLTools添加到Link库。 We do that, and now (as you should be expecting if you've been paying attention) we get a bunch of undefined references to glew functions. 我们这样做,现在(正如你应该期待的那样,如果你一直在关注)我们得到一堆未定义的glew函数引用。

Wee! 凌晨! So exciting. 如此令人兴奋。 So now we add the glew library to the Build options. 所以现在我们将glew库添加到Build选项中。 If you linked glew at the end, we learn something new. 如果你最后联系了glew,我们会学到新的东西。 You have to remember that when linking libraries, those that have their own dependencies have to be linked ahead of the ones they depend on. 您必须记住,在链接库时,那些具有自己的依赖项的库必须在它们依赖的库之前链接。 It would be helpful if we knew what they all depend on ahead of time, so in the future draw a map or something. 如果我们提前知道他们所依赖的东西会很有帮助,所以将来会画出地图或其他东西。

So we want to link freeglut, that depends on winmm, gdi32 and opengl32. 所以我们要链接freeglut,这取决于winmm,gdi32和opengl32。 We also want GLTools, that depends on glew, and glew, that depends on opengl32. 我们也想要GLTools,这取决于glew和glew,这取决于opengl32。 The order to link them in should be, then... freeglut, GLTools, glew, winmm, gdi32 and opengl32. 链接它们的顺序应该是,freeglut,GLTools,glew,winmm,gdi32和opengl32。 Let's see if that works.... 让我们看看它是否有效......

Ha! 哈! It compiled with no errors. 它编译没有错误。 Damn I'm good (not really :( ). 该死的我很好(不是真的:()。

Ok, now that we set up the environment, I copied the rest of the Triangle.cpp file over, saved, build, and got no errors. 好了,现在我们设置了环境,我复制了Triangle.cpp文件的其余部分,保存,构建,并且没有错误。

I've tested these steps in two computers, and they worked. 我已经在两台计算机上测试了这些步骤,但它们都有效。 I think the steps above should enable anyone with Code::Blocks and MinGW to build the tutorials in the OpenGL SuperBible, 5th Edition. 我认为上面的步骤应该允许任何拥有Code :: Blocks和MinGW的人在OpenGL SuperBible,5th Edition中构建教程。

Have been struggling with this problem for a couple days while testing code from a few tutorials. 在测试几个教程中的代码时,几天来一直在努力解决这个问题。 I suppose it's because most of them are made with Visual C/C++ in mind but I really wanted to use C::B with MinGW for this task. 我想这是因为大多数都是用Visual C / C ++制作的,但我真的想用C :: B和MinGW来完成这个任务。

Think I finally found an easy solution to this problem: 想想我终于找到了解决这个问题的简单方法:

1) If you haven't been able to properly install freeglut-2.6.0 for MinGW yet, try grabbing it from here: 1)如果你还没能为minGW正确安装freeglut-2.6.0,试试从这里抓取它:

http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MinGW.zip http://files.transmissionzero.co.uk/software/development/GLUT/freeglut-MinGW.zip

Unpack and make .h and .a files available to your project. 解压缩并为您的项目提供.h和.a文件。 Save .dll for later. 保存.dll以供日后使用。

2) Add these two defines before including glut.h 2)在包含glut.h之前添加这两个定义

#define GLUT_DISABLE_ATEXIT_HACK
#define GLAPI extern
#include <GL/glut.h>

3) Compile your project 3)编译你的项目

4) Before running the executable, copy freeglut.dll to its directory 4)在运行可执行文件之前,将freeglut.dll复制到其目录

5) Happy GL Hacking (at last!) 5)快乐GL黑客(最后!)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM