0

我使用 eclipse CDT 来编写我的 C++ 程序。但是eclipse和GCC编译器不能识别glShaderSource()。我执行以下操作来“加载”标题:

#include <GL/glew.h>
#include "Shader.h"

这就是产生错误的代码:

void Shader::setShaders(const char* vsFile, const char* fsFile) {
    char *vs, *fs;

    v = glCreateShader(GL_VERTEX_SHADER);
    f = glCreateShader(GL_FRAGMENT_SHADER);

    vs = textFileRead(vsFile);
    fs = textFileRead(fsFile);

    const char * vv = vs;
    const char * ff = fs;

    glShaderSource(v, 1, &vv, NULL);
    glShaderSource(f, 1, &ff, NULL);

    free(vs);
    free(fs);

    glCompileShader(v);
    glCompileShader(f);

    p = glCreateProgram();

    glAttachShader(p, v);
    glAttachShader(p, f);

    glLinkProgram(p);
    glUseProgram(p);
}

找不到每个 GL-Function。例如,给出此错误:

Function 'glCreateShader' could not be resolved

Eclipse 说,可以识别 glext-header,我什至可以看一下。其他 GL-Functions 工作(1.0-Functions)。

[ OLD: ] 我已经通过安装 GLext

sudo pacman -S glext

然后安装 Package gtkglext,这是唯一的选择。

我真的没有计划要做什么。也没有额外的 libGLEXT.so 或类似的东西,我只有 libGL、libGLU 和其他。

4

3 回答 3

2

您的问题是,OpenGL API 库不是通过常规导出而是通过扩展机制公开扩展函数。加载扩展是使用函数完成的xxxGetProcAddress,其中xxx特定于平台。由于加载扩展是乏味的,但它的代码可以从 OpenGL 规范自动生成,GLEW 项目正是这样做的。

GLEW ( http://glew.sf.net ) 是一个扩展加载器/包装器库,可以为您完成繁琐的任务。还有其他这样的库,但 GLEW 是迄今为止维护得最好的。

于 2012-02-15T17:29:44.720 回答
0

我推荐GLEW进行扩展加载。

于 2012-02-15T16:43:06.847 回答
0

I've had similar problems with GL extension functions. I managed to fix it by downloading GLEW source and statically linking to it in my project. This was annoying however so I searched deeper in the forums and found this solution. On linux you just need to dedine GL_GLEXT_PROTOTYPES. This solution will not work on Windows! As always it is "easier" on windows so one will need to fight with the glew or glext configuration and linking.

For me it worked when I added it in the project options of QtCreator. Every IDE should have a place with defines in the project/build options. I added this to the list: -DGL_GLEXT_PROTOTYPES

I have #include but I am not sure I need it :) anyways I haven't linked explicitly to any other libraries but GL and GLU.

于 2012-02-19T17:19:40.887 回答