OpenGL 与 gl3w

Gre*_*ack 1 c++ opengl linker sfml

我正在尝试学习 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;
}
Run Code Online (Sandbox Code Playgroud)

我收到以下链接器错误。

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
Run Code Online (Sandbox Code Playgroud)

我仔细检查了我是否正确链接了库。

我使用 Visual Studio 2013 在 Windows 7 上工作。

有谁知道我做错了什么?

Iva*_*rop 5

你忘了编译gl3w。

假设你已经:

  • 抓取python脚本
  • 运行它: python gl3w_gen.py
  • 找到gl3w.h glcorearb.hgl3w.c生成文件

有两种方式:

第一种方式。只需在您的项目中包含这些文件,它就会与您自己的源代码一起编译。请注意,您需要保留GL文件夹或手动修复包含在gl3w.c.

第二种方式。创建新项目,在其中添加所有三个文件并编译为静态库。然后将它链接到您的应用程序(或者只是在命令行或 makefile 中编译它,无论如何)。

快乐编码!