visual-studio 在 Visual C++ Express Edition 中使用 GLUT

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14264/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:22:03  来源:igfitidea点击:

Using GLUT with Visual C++ Express Edition

visual-studiovisual-c++openglglut

提问by Ashwin Nanjappa

What are the basic steps to compile an OpenGL application using GLUT (OpenGL Utility Toolkit)under Visual C++ Express Edition?

在 Visual C++ Express Edition 下使用GLUT(OpenGL Utility Toolkit)编译 OpenGL 应用程序的基本步骤是什么?

采纳答案by Ashwin Nanjappa

  1. If you don't have Visual C++ Express Edition (VCEE), download and install VCEE.
  2. The default install of Visual C++ Express Edition builds for the .Net platform. We'll need to build for the Windows platform since OpenGL and GLUT are not yet fully supported under .Net. For this we need the Microsoft Platform SDK. (If you're using an older version of VCEE, download and install the Microsoft Platform SDK. Visual C++ Express Edition will need to be configured to build for Windows platform. All these instructions are available here.)
  3. If you don't have GLUT, download and unzip Nate Robin's Windows port of GLUT.
  4. Add glut.hto your Platform SDK/include/GL/directory
  5. Link the project with glut.lib. (Go to VCEE Project Properties -> Additional Linker Directoriesand add the directory which has glut.lib.
  6. Add glut.dllto the Windows/System32directory, so that all programs using GLUT can find it at runtime.
  1. 如果您没有 Visual C++ Express Edition (VCEE),请下载并安装VCEE
  2. Visual C++ Express Edition 的默认安装是为 .Net 平台构建的。我们需要为 Windows 平台构建,因为 OpenGL 和 GLUT 在 .Net 下还没有完全支持。为此,我们需要 Microsoft Platform SDK。(如果您使用的是旧版本的 VCEE,请下载并安装Microsoft PlatformSDK。Visual C++ Express Edition 需要配置为针对 Windows 平台构建。所有这些说明都可以在这里找到。)
  3. 如果您没有 GLUT,请下载并解压缩 Nate Robin 的GLUTWindows 端口
  4. glut.h添加到您的Platform SDK/include/GL/目录
  5. 将项目与glut.lib链接。(转到 VCEE项目属性 -> 附加链接器目录并添加具有glut.lib的目录。
  6. glut.dll添加到Windows/System32目录中,以便所有使用 GLUT 的程序在运行时都能找到它。

Your program which uses GLUT or OpenGL should compile under Visual C++ Express Edition now.

您使用 GLUT 或 OpenGL 的程序现在应该可以在 Visual C++ Express Edition 下编译。

回答by Baxissimo

The GLUT port on Nate Robin's site is from 2001 and has some incompatibilities with versions of Visual Studio more recent than that (.NET 2003 and up). The incompatibility manifests itself as errors about redefinition of exit(). If you see this error, there are two possible solutions:

Nate Robin 站点上的 GLUT 端口是 2001 年的,并且与较新的 Visual Studio 版本(.NET 2003 及更高版本)存在一些不兼容。这种不兼容性表现为重新定义 的错误exit()。如果您看到此错误,有两种可能的解决方案:

  1. Replace the exit()prototype in glut.hwith the one in your stdlib.hso that they match. This is probably the best solution.
  2. An easier solution is to #define GLUT_DISABLE_ATEXIT_HACKbefore you #include <gl/glut.h>in your program.
  1. 更换exit()原型glut.h与一个在你stdlib.h让它们匹配。这可能是最好的解决方案。
  2. 一个更简单的解决方案是在你的程序#define GLUT_DISABLE_ATEXIT_HACK之前#include <gl/glut.h>

(Due credit: I originally saw this advice on the TAMU help desk website.)

(应有的信用:我最初是在TAMU 帮助台网站上看到此建议的。)

I've been using approach #1 myself since .NET 2003 came out, and have used the same modified glut.hwith VC++ 2003, VC++ 2005 and VC++ 2008.

自从.NET 2003问世以来,我自己一直在使用方法#1,并且使用了glut.h与VC++ 2003、VC++ 2005和VC++ 2008相同的修改。

Here's the diff for the glut.h I use which does #1 (but in appropriate #ifdef blocksso that it still works with older versions of Visual Studio):

这是我使用的 glut.h 的差异 #1(但适当,#ifdef blocks以便它仍然适用于旧版本的 Visual Studio):

--- c:\naterobbins\glut.h       2000-12-13 00:22:52.000000000 +0900
+++ c:\updated\glut.h    2006-05-23 11:06:10.000000000 +0900
@@ -143,7 +143,12 @@

 #if defined(_WIN32)
 # ifndef GLUT_BUILDING_LIB
-extern _CRTIMP void __cdecl exit(int);
+/* extern _CRTIMP void __cdecl exit(int);  /* Changed for .NET */
+#  if _MSC_VER >= 1200
+extern _CRTIMP __declspec(noreturn) void __cdecl exit(int);
+#  else
+extern _CRTIMP void __cdecl exit(int);
+#  endif
 # endif
 #else
 /* non-Win32 case. */