簡體   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