我正在努力学习 OpenGL。我将 SFML 窗口模块用于上下文,将 gl3w 用作我的加载库。我经常使用 SFML,因此按照本教程为 OpenGL 设置它不是问题:http://www.sfml-dev.org/tutorials/2.0/window-opengl.php
我可以毫无问题地运行示例代码。我链接了 OpenGL 所需的一切(opengl32.lib 和 glu32.lib + sfml*.lib)。
然后我按照这个答案得到了 gl3w : How to set up gl3w on Windows? .
但现在如果我尝试运行这段代码,它主要是来自 SFML 的示例代码
#include <SFML/gl3w.h>
#include <SFML/Window.hpp>
static const GLfloat red[] = { 1.0f, 0.f, 0.f, 1.f };
int main()
{
// create the window
sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, sf::ContextSettings(32));
window.setVerticalSyncEnabled(true);
gl3wInit(); //ignore return value for now
// load resources, initialize the OpenGL states, ...
// run the main loop
bool running = true;
while (running)
{
// handle events
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
{
// end the program
running = false;
}
else if (event.type == sf::Event::Resized)
{
//adjust the viewport when the window is resized
glViewport(0, 0, event.size.width, event.size.height);
}
}
glClearBufferfv(GL_COLOR, 0, red);
// end the current frame (internally swaps the front and back buffers)
window.display();
}
// release resources...
return 0;
}
我收到以下链接器错误。
1>OpenGL.obj : error LNK2019: unresolved external symbol _gl3wInit referenced in function _main
1>OpenGL.obj : error LNK2001: unresolved external symbol _gl3wViewport
1>OpenGL.obj : error LNK2001: unresolved external symbol _gl3wClearBufferfv
我仔细检查了我是否正确链接了这些库。
我在使用 Visual Studio 2013 的 Windows 7 上工作。
谁知道我做错了什么?
最佳答案
你忘了编译 gl3w。
假设您已经:
- 抓取 python 脚本
- 运行它:
python gl3w_gen.py
- 找到
gl3w.h
glcorearb.h
和gl3w.c
文件生成
有两种方式:
第一种方式。只需将这些文件包含在您的项目中,这样它就会与您自己的源代码一起编译。请注意,您需要保留 GL
文件夹或手动修复包含在 gl3w.c
中的内容。
第二种方式。 创建新项目,将所有三个文件添加到其中并编译为静态库。然后将它链接到您的应用程序(或者只是在命令行或 makefile 中编译它,等等)。
编码愉快!
关于c++ - 使用 gl3w 的 OpenGL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22436937/