Windows下使用GLEW使用OpenGL扩展 [英] Using GLEW to use OpenGL extensions under Windows

查看:61
本文介绍了Windows下使用GLEW使用OpenGL扩展的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在 Windows 上使用 OpenGL 扩展痛苦的方式.GLEW 是更简单的方法吗?我如何开始使用它?

I've been using OpenGL extensions on Windows the painful way. Is GLEW the easier way to go? How do I get started with it?

推荐答案

是的,OpenGL Extension Wrangler Library (GLEW) 是在 Windows 上使用 OpenGL 扩展的一种轻松方式.以下是如何开始:

Yes, the OpenGL Extension Wrangler Library (GLEW) is a painless way to use OpenGL extensions on Windows. Here's how to get started on it:

确定您希望使用的 OpenGL 扩展和扩展 API.OpenGL 扩展注册表中列出了 OpenGL 扩展.

Identify the OpenGL extension and the extension APIs you wish to use. OpenGL extensions are listed in the OpenGL Extension Registry.

检查您的显卡是否支持您要使用的扩展.为您的显卡下载并安装最新的驱动程序和 SDK.

Check if your graphic card supports the extensions you wish to use. Download and install the latest drivers and SDKs for your graphics card.

最新版本的 NVIDIA OpenGL SDK 附带 GLEW.如果您正在使用它,那么您无需执行以下某些步骤.

Recent versions of NVIDIA OpenGL SDK ship with GLEW. If you're using this, then you don't need to do some of the following steps.

下载 GLEW 并解压.

将 GLEW bin 路径添加到您的 Windows PATH 环境变量.或者,您也可以将 glew32.dll 放在 Windows 获取其 DLL 的目录中.

Add the GLEW bin path to your Windows PATH environment variable. Alternatively, you can also place the glew32.dll in a directory where Windows picks up its DLLs.

将 GLEW include 路径添加到编译器的包含目录列表中.

Add the GLEW include path to your compiler's include directory list.

将 GLEW lib 路径添加到编译器的库目录列表中.

Add the GLEW lib path to your compiler's library directory list.

指示您的编译器在链接期间使用 glew32.lib.如果您使用的是 Visual C++ 编译器,那么一种方法是将以下行添加到您的代码中:

Instruct your compiler to use glew32.lib during linking. If you're using Visual C++ compilers then one way to do this is by adding the following line to your code:

#pragma comment(lib, "glew32.lib")

在您的代码中添加 #include 行.确保它位于其他 GL 头文件的包含内容之上.(如果您包含 glew.h,您实际上可能不需要包含 GL 头文件.)

Add a #include <GL/glew.h> line to your code. Ensure that this is placed above the includes of other GL header files. (You may actually not need the GL header files includes if you include glew.h.)

在初始化 GLUT 或 GL 后使用 glewInit() 初始化 GLEW.如果失败,则说明您的设置有问题.

Initialize GLEW using glewInit() after you've initialized GLUT or GL. If it fails, then something is wrong with your setup.

if (GLEW_OK != glewInit())
{
    // GLEW failed!
    exit(1);
}

检查您希望使用的扩展程序现在是否可以通过 GLEW 获得.为此,您可以检查 GLEW 公开的名为 GLEW_your_extension_name 的布尔变量.

Check if the extension(s) you wish to use are now available through GLEW. You do this by checking a boolean variable named GLEW_your_extension_name which is exposed by GLEW.

示例:

if (!GLEW_EXT_framebuffer_object)
{
    exit(1);
}

就是这样!您现在可以在代码中使用 OpenGL 扩展调用,就像它们自然存在于 Windows 中一样.

That's it! You can now use the OpenGL extension calls in your code just as if they existed naturally for Windows.

这篇关于Windows下使用GLEW使用OpenGL扩展的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆