OpenGL with gl3w

OpenGL with gl3w

本文关键字:gl3w with OpenGL      更新时间:2023-10-16

我正在努力学习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

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

我在Windows 7上使用Visual Studio 2013。

有谁知道我做错了什么吗?

您忘记编译gl3w了

假设你已经:

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

有两种方法:

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

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

编码快乐!