Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/140.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ OpenGL glGetIntegerv GL_MAX_VERTEX_ATTRIBS分割错误_C++_Opengl - Fatal编程技术网

C++ OpenGL glGetIntegerv GL_MAX_VERTEX_ATTRIBS分割错误

C++ OpenGL glGetIntegerv GL_MAX_VERTEX_ATTRIBS分割错误,c++,opengl,C++,Opengl,我正在学习OpenGL,面临着这个问题: 源代码: #include <iostream> #include <glad/glad.h> int nrAttributes; int main() { glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes); std::cout << "max vertex: " << nrAttributes << std::

我正在学习OpenGL,面临着这个问题:

源代码:

#include <iostream>
#include <glad/glad.h>

int nrAttributes;

int main()
{
    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);

    std::cout << "max vertex: " << nrAttributes << std::endl;

    return 0;
}
我使用的是linux mint 18.04 x64

GL信息:
glxinfo|grep OpenGL

OpenGL vendor string: X.Org
OpenGL renderer string: AMD TURKS (DRM 2.50.0 / 4.13.0-38-generic, LLVM 5.0.0)
OpenGL core profile version string: 3.3 (Core Profile) Mesa 17.2.8
OpenGL core profile shading language version string: 3.30
OpenGL core profile context flags: (none)
OpenGL core profile profile mask: core profile
OpenGL core profile extensions:
OpenGL version string: 3.0 Mesa 17.2.8
OpenGL shading language version string: 1.30
OpenGL context flags: (none)
OpenGL extensions:
OpenGL ES profile version string: OpenGL ES 3.0 Mesa 17.2.8
OpenGL ES profile shading language version string: OpenGL ES GLSL ES 3.00
OpenGL ES profile extensions:
当我运行代码时,我得到以下输出:

Segmentation fault (core dumped)

有人能解释一下为什么会发生这种情况吗?

正如@rabbi76所指出的,我需要一个有效的上下文来调用opengl函数

这是工作代码,希望它能帮助其他人

#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

    int nrAttributes;
    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);
    std::cout << "Maximum nr of vertex attributes supported: " << nrAttributes << std::endl;

    return 0;
}
#包括
#包括
#包括
int main()
{
glfwInit();
GLFWwindow*window=glfwCreateWindow(800600,“LearnOpenGL”,NULL,NULL);
glfwMakeContextCurrent(窗口);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
int属性;
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS和nrAttributes);

std::调用任何OpenGL指令是否需要有效且最新的。另请参阅和@rabbi76哦,是的,你是对的。感谢你指出。愚蠢的错误抱歉:|配置了上下文,并且它可以工作。:)我应该从堆栈中删除该问题吗?因为这是我愚蠢的错误
#include <iostream>
#include <glad/glad.h>
#include <GLFW/glfw3.h>

int main()
{
    glfwInit();
    GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
    glfwMakeContextCurrent(window);
    gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);

    int nrAttributes;
    glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);
    std::cout << "Maximum nr of vertex attributes supported: " << nrAttributes << std::endl;

    return 0;
}