【问题标题】:glew setup in sfml and opengl program doesnt worksfml 和 opengl 程序中的 glew 设置不起作用
【发布时间】:2016-01-23 20:46:05
【问题描述】:

我正在尝试将 SFML 与 OpenGL 一起使用,并且我的设置运行良好。然后我看到要使用现代 OpenGL 函数,我还需要包含 glew。我尝试了一整天来设置这个东西,但它不起作用。

这就是我所做的:

#define GLEW_STATIC
#include <GL/glew.h>
#include <SFML/OpenGL.hpp>
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>

using namespace std;

sf::RenderWindow window(sf::VideoMode(1280, 760), "SFML works!");
sf::Event Event;
sf::Shader defaultShader;

GLfloat vertices[] = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f
};

GLuint VBO, VAO;
int main()
{
    glewInit();
    glGenVertexArrays(1, &VAO);
    glGenBuffers(1, &VBO);
    glBindVertexArray(VAO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
    return 0;
}

我得到了这些错误:

undefined reference to '__glewGenVertexArrays'
undefined reference to '__glewGenBuffers'
undefined reference to '__glewBindVertexArray'

glewInit()外,我使用的所有函数都以此类推。

我使用了 SFML 2.3。我去了 Code::Blocks 项目设置和

  1. 链接sfml包含文件夹
  2. 链接了sfml
  3. 声明sfml_static

如何设置glew? (glew 包含在 SFML 中,所以我只是用

#define GLEW_STATIC
#include <GL/glew.h>

我的代码应该可以工作,但它没有。

【问题讨论】:

    标签: c++ opengl codeblocks sfml glew


    【解决方案1】:

    您需要静态链接 GLEW 库

    命令行:

    g++ appname -lGLEW -lsfml-system -lsfml-window -lsfml-graphics
    

    代码块:

    右键单击您的项目->构建选项->添加->输入 GLEW 库的路径->确定

    【讨论】:

    • 我在 windows 上..我也包括了那些..sfml 工作正常。它的 glew 不工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多