我假设这是一个上下文问题,但我无法弄清楚问题是什么......
SDL_Window *window = SDL_CreateWindow("Default", 0, 0, 480, 320, SDL_WINDOW_SHOWN | SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_OPENGL);
Assert(window, "Could not create window");
SDL_GLContext context = SDL_GL_CreateContext(window);
Assert(context, "Could not create context");
glViewport(0, 0, 480, 320);
if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE){
Assert(0, "Failure with framebuffer generation");
}
glClearColor(0, 104.0/255.0, 55.0/255.0, 1.0);
if(glGetError() != GL_NO_ERROR){
Assert(0, "Could not set clear color");
}
glClear(GL_COLOR_BUFFER_BIT);
GLuint shaderHandle = glCreateShader(GL_VERTEX_SHADER);
Assert(shaderHandle, "Could not create shader handle");
Assert(glGetString(GL_SHADING_LANGUAGE_VERSION), "Cant get glstring, somethings wrong");
着色器句柄为0,这意味着它不起作用,当我读到它时,当glGetString返回NULL时,它是一个坏符号。怎么了?
答案 0 :(得分:4)
forums.libsdl.org上的优秀人员给了我答案。致电
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
是必要的。