SDL2+Opengles2.0使用,SDL_GL_SwapWindow()立即刷新问题

这里写自定义目录标题

SDL2+Opengles2.0使用,SDL_GL_SwapWindow()立即刷新问题

初始化sdl2 + Opengles2.0

使用了glad库,库在线生成模板地址:https://glad.dav1d.de/
加入项目后sdl2初始化:
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
//SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

//Use OpenGL 2.1
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);

//注意加入SDL_WINDOW_OPENGL参数
window = SDL_CreateWindow(NULL, G_windowRect.x, G_windowRect.y, deviceSize.w, deviceSize.h, winflag | SDL_WINDOW_OPENGL);

//创建opengl上下文
G_GLEScontext = SDL_GL_CreateContext(window);

//初始化glad,注意这个函数跟你的选择的版本有关,见glad.c文件中对应的函数
gladLoadGLES2Loader((GLADloadproc)SDL_GL_GetProcAddress);

//sdl2中设置为立即刷新模式
//问题也出在这,即使设置为立即刷新模式,SDL_GL_SwapWindow也很可能不是立即刷新的
SDL_GL_SetSwapInterval(0);

//测试下是否立即刷新
glClearColor(0.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(window);

//如果不是,加入这个
glFinish(); //多少能解决问题,原因不明,sdl2版本2.0.12

上一篇:python生成XML文件代码


下一篇:【前端安全】JavaScript防http劫持与XSS