# SDL2, OpenGL, Nvidia laptop screen tearing

EDIT 2017-05-14 dvb. Issue still active to this very day, see geforce forum link in main question.

Note 3: "Stoltverd" has posted a "fix guide" on geforce forum. It has workarounds for non-OpenGL games.

https://forums.geforce.com/default/topic/1008527/geforce-mobile-gpus/-guide-diagonal-screen-tearing-problems-with-optimus-nvidias-control-panel-not-working-like-it-should-need-a-fix-get-in-here/

Note 4: My workaround for OpenGL games: use HDMI output to external monitor. (In my case, the only game I care about is my own, and I use a big cheap HDMI TV for demo.)

EDIT 2016-03-06.

Note 1: Apparently this is a known issue with Nvidia. If you've found here due to same problem, please stoke the collective "please fix it" by filing a "question" at https://nvidia.custhelp.com/app/ask.

Note 2: Doesn't happen on external monitor. Also doesn't happen on internal display if external monitor is mirroring. (Surprise.)

I'm developing my game directly in C++, OpenGL, and SDL2.

On an Alienware 15 R2 laptop with Nvidia GTX 965M, I get screen tearing in a curious diagonal line like shown below. It goes across the window top left to bottom right.

The image below is taken during a screen fade-in, so shows just a brightness line. But it happens between any two different frames.

If my window is full screen, the line goes top-left to bottom-right of the whole screen.

Same code runs fine (no tearing) on: All macs, same laptop on Intel integrated GPU, desktop PC with Nvidia 730.

Same laptop looks fine with other games, Chrome+Shadertoy, &c.

Main loop looks something like:

// setup code
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetSwapInterval(1);
flags = SDL_WINDOW_OPENGL;
SDL_CreateWindow(... ,flags);
// main loop
while(1) {
this->checkEvents();
SDL_GL_SwapWindow(this->mainWindow);
this->doGlDrawing();
}


Grepping forums, I've seen reports of some OpenGL games showing this on Alienware & other Dell laptops.

All suggestions welcome! Thanks.

Edit 2016-02-20, some links to similar user-side reports: https://forums.geforce.com/default/topic/903422/geforce-mobile-gpus/diagonal-screen-tearing-issues-on-gtx-860m-870m-960m-965m-970m-980m-/

http://en.community.dell.com/owners-club/alienware/f/3746/t/19658623

• What FPS is the game updating graphics at when you get this artifact? I've noticed in OpenGL and Vulkan if you move things around too quickly you can get some odd artifacts that don't show up when you fix your frames to 144-90 maximum. – user5665 May 7 '16 at 9:41
• @MattJensJensen This happens when the framerate is locked to screen refresh (60). It is correctly locked, but something in the hardware puts a consistent whole-viewport diagonal tear. – david van brink May 9 '16 at 3:58
• You're locking frame rate with Vsync AND manually sleeping enough each frame? – user5665 May 9 '16 at 10:22
• I wish you the best with it, I hope they fix it soon, I've been waiting for driver fixes from nvidia for the GM200 GPUs in SLI for months. – user5665 May 11 '16 at 1:58
• I noticed this on one of my laptops. I switched from Nvidia to Intel graphics and it seems to work fine. – Begui Aug 6 '18 at 17:11

I don't know SDL at all, though I do know a little of OpenGL. Have you tried enabling VSync? I did some research, and you could accomplish this by passsing in SDL_HINT_RENDER_VSYNC to SDL_CreateRenderer(). This is where I found this information: https://wiki.libsdl.org/SDL_HINT_RENDER_VSYNC

• Yes, using SDL's calls to enable v-sync, yes. This usually works great, locks frame rate to 60 fps and eliminates tearing. Except on this Nvidia Alienware platform and the similar platforms reported in the linked threads. Disabling rsync actually hides the diagonal line (but introduces the usual kinds of tearing from going >60fps). – david van brink Feb 21 '16 at 2:58
• Can you get a clearer picture of the problem? – JavaLich Feb 21 '16 at 13:28
• It is literally the angled line that makes the upper diagonal half of the window lighter than the lower half. That is the entirety of the problem. The upper half shows the previous frame, and the lower half shows the latest frame. However, it is desired that at any instant, the entire window (or screen if full screen) shows the same, preferably latest, frame. – david van brink Feb 21 '16 at 23:10