0

我只是想使用 SDL 2.0 和 glew 1.9 制作一个 openGL 上下文

构建项目时没有问题,但在调试时,GLEW 初始化失败,我该怎么做才能解决这个问题?

我正在使用视觉工作室 2012

这是输出:

The program '[936] gravitation.exe' has exited with code -1 (0xffffffff).

这是代码:

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

int main(int argc, char **argv)
{
    SDL_Window* window = 0;
    SDL_GLContext contextOpenGL = 0;

    SDL_Event event;
    bool terminate = false;

    GLenum initGLEW = glewInit();

    if( GLEW_OK != initGLEW )
    {
        std::cout << "initialisation error of GLEW : " << glewGetErrorString(initialisationGLEW) << std::endl;

        SDL_GL_DeleteContext(contextOpenGL);
        SDL_DestroyWindow(window);
        SDL_Quit();

        return -1;
    }

    while(!terminate)
    {
    SDL_WaitEvent(&event);

    if(event.window.event == SDL_WINDOWEVENT_CLOSE)
        terminer = true;

        glClear(GL_COLOR_BUFFER_BIT);

        SDL_GL_SwapWindow(window);
    }

    SDL_GL_DeleteContext(contextOpenGL);
    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}
4

1 回答 1

2

我没有看到 OpenGL 窗口,也没有在您的代码中创建 OpenGL 上下文。初始化 GLEW 时,您需要激活 OpenGL 上下文。

于 2012-11-29T19:43:24.497 回答