我只是尝试使用SDL 2.0和glew 1.9
创建一个openGL上下文在构建项目时没有问题,但在调试时,GLEW无法初始化,我该怎么做才能解决这个问题?
我正在使用visual studio 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;
}
答案 0 :(得分:2)
我没有看到OpenGL窗口,也没有在代码中创建OpenGL上下文。初始化GLEW时,您需要激活OpenGL上下文。