1
\$\begingroup\$

I'm working in a toy BSP (quake3 version) renderer. I started creating the context and handling the input with GLFW but then I switched over SDL. The performance change was amazing with SDL leading with 100+ fps.

But when rendering some surfaces from far now I'm getting some strange and ugly artifacts in the borders or junctions. The only thing that I changed from GLFW to SDL was the initialization (code bellow) and the input handling but the OpenGL Draw calls are the same.

Why am I getting these artifacts when rendering polygons with OpenGL and SDL from far distance?

This only happens with some surfaces (mostly the ones without textures, only vertex colors) but there are some tiny surfaces (pendants or flags) that also have the same problem. Also, not all the borders of the same faces have the problem.

if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
    cout << "Failed to init SDL Video" << endl;
};

SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS,   SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 4);


_window = SDL_CreateWindow("BSP Test", 0, 0, width, height,
                            SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL);

if (_window == nullptr) {
    SDL_Quit();
    return false;
}

SDL_GLContext ctx = SDL_GL_CreateContext(_window);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glGetIntegerv(GL_MAX_PATCH_VERTICES, &ee);
cout << "Max patch vertices : " << ee << endl;

glPatchParameteri(GL_PATCH_VERTICES, 9);

cout << "GL ERROR LOAD  :" << glGetError() << endl;

glClearColor(0.0f, 0.0f, 0.01f, 1.0f);

glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
glFrontFace(GL_CCW);
glEnable(GL_DEPTH_TEST);
glEnable(GL_MULTISAMPLE);
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_LINE_SMOOTH);

SDL_GL_SetSwapInterval(0);

matrices.proj = glm::perspective(glm::radians(100.0f), (float) width / (float) height, 1.0f, 4000.0f);

camera.position = glm::vec3{-41.415211f, 320.293121f, -537.225281f};

return true;

Near Far Notice the ugly black triangles in the borders of the terrain

\$\endgroup\$
  • \$\begingroup\$ "The performance change was amazing" smells a little fishy. The choice of GLFW or SDL should have negligible performance impact. Their primary purpose (at least how you seem to be using them) is just to create a context. Input handling shouldn't affect things much. Are you sure you're requesting the same context parameters & pixel format? It's hard to tell what the output is supposed to look like but it does look like some kind of z-fighting artifacts, which could be explained if SDL is giving you less depth buffer resolution than GLFW \$\endgroup\$ – bcrist Oct 14 '15 at 3:24
  • \$\begingroup\$ You were right about the deep buffer size, it seems that GLFW by defaults is set in 32 , and SDL 16, I made the change and everything looks fine. but the performance differences is the same. The most noticeably difference in performance is in full-screen (both desktop and exclusive full-screen) the swapbuffer function in GLFW toked twice the time that its counter part in SDL. i had seen many forums post about the issue present in OSX. \$\endgroup\$ – Patricio Villalobos Oct 14 '15 at 5:49
  • \$\begingroup\$ @bcrist if you answer the question i can mark it resolved with yours. \$\endgroup\$ – Patricio Villalobos Oct 14 '15 at 5:52
2
\$\begingroup\$

As @bcrist pointed out, the depth buffer bits is set by default to 16 with SDL. changing that value to 24 or 32 solved the problem, giving more precision to the depth test.

SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.