[英]OpenGL 4.5 : glClear() doesn't work (using SDL2 and GLEW)
I made a short code in order to clear a SDL2 window with black color using OpenGL 4.5 (GLEW API). 我制作了一个简短的代码,以便使用OpenGL 4.5(GLEW API)清除黑色的SDL2窗口。 However, it works only when I use my Intel chipset (In this case an older OpenGL version should be used). 但是,它仅在我使用我的英特尔芯片组时才有效(在这种情况下,应该使用较旧的OpenGL版本)。 The problem is that if I use my Nvidia GTX 960M, the window is still blank. 问题是如果我使用我的Nvidia GTX 960M,窗口仍然是空白的。 Maybe I forgot to write something which is specific to OpenGL 4.5? 也许我忘了写一些特定于OpenGL 4.5的东西? Have you got any idea about this? 你对此有任何想法吗? Here is the code sample: 这是代码示例:
DisplayContext::DisplayContext(PropertiesDictionary properties)
{
const string windowTitle = properties.getString("window_title");
const int screenX = properties.getNumber("screen_resolution_x");
const int screenY = properties.getNumber("screen_resolution_y");
const bool isFullscreen = properties.getBoolean("fullscreen");
const int gl_majorVersion = properties.getNumber("gl_major_version");
const int gl_minorVersion = properties.getNumber("gl_minor_version");
const int doublebuffer = properties.getNumber("gl_doublebuffer");
const int depthSize = properties.getNumber("gl_depth_size");
const bool isGlewExperimental = properties.getBoolean("glew_experimental");
SDL_Init(SDL_INIT_VIDEO);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, gl_majorVersion); // 4
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, gl_minorVersion); // 5
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, doublebuffer); // TRUE
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depthSize); // 24
window = SDL_CreateWindow(
windowTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screenX, screenY,
SDL_WINDOW_OPENGL | (isFullscreen ? SDL_WINDOW_FULLSCREEN : NULL));
context = SDL_GL_CreateContext(window);
glewExperimental = isGlewExperimental ? GL_TRUE : GL_FALSE; // TRUE
glewInit();
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
SDL_GL_SwapWindow(window);
}
I switched the doublebuffer option to FALSE and it works. 我将doublebuffer选项切换为FALSE并且它可以工作。 I realized that if doublebuffer is ON, I need to do several "swap" before seeing a black window background. 我意识到如果双缓冲器打开,我需要在看到黑色窗口背景之前做几次“交换”。 It makes sense but it's quite strange. 这很有道理,但很奇怪。 By the way I finally use GLFW instead of SDL2. 顺便说一下,我最终使用GLFW而不是SDL2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.