繁体   English   中英

带有gl3w的OpenGL

[英]OpenGL with gl3w

我正在尝试学习OpenGL。 我正在使用SFML窗口模块作为上下文,并使用gl3w作为加载库。 我经常使用SFML,因此按照本教程针对OpenGL进行设置不是问题: http : //www.sfml-dev.org/tutorials/2.0/window-opengl.php

我可以运行示例代码而没有任何问题。 我链接了OpenGL需要的所有内容(opengl32.lib和glu32.lib + sfml * .lib)。

然后我按照这个答案得到gl3w: 如何在Windows上设置gl3w?

但是现在,如果我尝试运行此代码,这主要是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.hgl3w.c文件

有两种方法:

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

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

编码愉快!

暂无
暂无

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

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