glActiveTexture 导致 "has stopped working" 错误

glActiveTexture causes "has stopped working" error

我的 IDE 无法识别 glActiveTexture 方法。 我已经安装了 freeglut 和 GLEW lib,当我构建我的项目时 IDE 没有显示任何错误但是当我 运行 程序时我有这个 "has stopped working" 类型错误。我真的不知道如何解决它以及导致此问题的原因。 另一种想法是 IDE 知道函数的名称(this #thing),但我猜不知道函数本身(它应该是 () 符号,就像在第一个函数中一样)。 glActiveTexture

我希望有人知道这个问题的解决方案。

编辑1 这是我的示例代码:

#define GLEW_STATIC
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glew.h>
#include <GL/gl.h>
#include <GL/glut.h>
#endif

#include <iostream>
#include <stdlib.h>
using namespace std;
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);
    GLenum err = glewInit();
    if (GLEW_OK != err)
    {
        cout<<"Error: "<<glewGetErrorString(err)<<endl;
    }
    else cout<<"Initialized"<<endl;

    return EXIT_SUCCESS;
}

我得到 Error: Missing GL version

这里是 glewinfo:

GLEW version 1.13.0
Reporting capabilities of pixelformat 3
Running on a Intel(R) HD Graphics 4600 from Intel
OpenGL version 4.3.0 - Build 10.18.10.3960 is supported

您需要在调用之前创建 OpenGL 渲染上下文 glewInit:

glutInit(&argc, argv);
glutCreateWindow("My Program");
GLenum err = glewInit();

详情见here