【问题标题】:SDL + OpenGL: access violation when creating bufferSDL + OpenGL:创建缓冲区时访问冲突
【发布时间】:2016-11-22 18:58:50
【问题描述】:

我正在尝试使用 SDL 创建一个窗口,然后使用 GLEW 和 OpenGL 对其进行绘制。

到目前为止,我已经创建了一个窗口并使用 OpenGL 对其进行了初始化,但是当我尝试创建缓冲区时,我得到了一个有线异常。

我的代码如下所示:

#include <GL\glew.h>
#include <SDL.h>
#include <iostream>

int main(int argc, char** argv)
{

    SDL_Window* window;
    SDL_Init(SDL_INIT_EVERYTHING);

    //creating SDL window
    window = SDL_CreateWindow("",100,100,500,400,SDL_WINDOW_OPENGL);

    //setting up opengl
    SDL_GL_CreateContext(window);
    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
    glClearColor(0.6f, 0.0f, 0.0f, 1.0f);

    //check if glew was initialized properly
    if (glewInit() == GLEW_OK)
        std::cout << "glew ok" << std::endl;
    else
        goto end;

    ////////////////////////////////////////////////I'm Getting The Error Here
    GLuint bufferID;////////////////////////////////
    glCreateBuffers(1,&bufferID);///////////////////
    glDeleteBuffers(1,&bufferID);///////////////////

    SDL_Event sdlEvent;

    //event loop
    while (1)
        while (SDL_PollEvent(&sdlEvent))
            if (sdlEvent.type == SDL_QUIT)
                goto end;

    end:
        SDL_Quit();

    return 0;
}

错误:Exception thrown at 0x00000000 in opengl_project.exe: 0xC0000005: Access violation executing location 0x00000000.

【问题讨论】:

  • glCreateBuffers() 仅在 GL 4.5 中,您真的获得了 GL 4.5 上下文吗?
  • 嗯,我不知道如何检查?是我的opengl dll文件过时了吗?还是在发光?
  • 我刚试过,我得到了 4.3 版。所以我使用的是过时的版本,但它是过时的还是过时的?因为我不知道在哪里可以得到另一个 opengl32.dll
  • 另外,如果它已经过时了,那么我电脑上的其他使用 opengl 的程序还可以工作吗?

标签: c++ opengl buffer sdl glew


【解决方案1】:

问题在于 opengl 已过时(4.3 版),而 glCreateBuffers 是 4.5+ 的功能

如果您遇到类似的问题,解决方案可能是更新您的图形驱动程序或仅使用 glGenBuffers(1.5 版以上)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多