{"action":"created","issue":{"url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/687","labels_url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/687/labels{/name}","comments_url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/687/comments","events_url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/687/events","html_url":"https://github.com/CorsixTH/CorsixTH/pull/687","id":57268220,"number":687,"title":"Fix #370 (zoom glitches on some platforms)","user":{"login":"pwaller","id":438648,"avatar_url":"https://avatars.githubusercontent.com/u/438648?v=3","gravatar_id":"","url":"https://api.github.com/users/pwaller","html_url":"https://github.com/pwaller","followers_url":"https://api.github.com/users/pwaller/followers","following_url":"https://api.github.com/users/pwaller/following{/other_user}","gists_url":"https://api.github.com/users/pwaller/gists{/gist_id}","starred_url":"https://api.github.com/users/pwaller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pwaller/subscriptions","organizations_url":"https://api.github.com/users/pwaller/orgs","repos_url":"https://api.github.com/users/pwaller/repos","events_url":"https://api.github.com/users/pwaller/events{/privacy}","received_events_url":"https://api.github.com/users/pwaller/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-11T02:17:58Z","updated_at":"2015-02-12T01:53:11Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/CorsixTH/CorsixTH/pulls/687","html_url":"https://github.com/CorsixTH/CorsixTH/pull/687","diff_url":"https://github.com/CorsixTH/CorsixTH/pull/687.diff","patch_url":"https://github.com/CorsixTH/CorsixTH/pull/687.patch"},"body":"The `m_pZoomTexture` was being used as a render target even though\r\nit was uninitialized. This sometimes worked out, depending on your\r\nplatform, and other times not.\r\n\r\nThe fix is to initialize the zoom buffer to transparent and then use\r\nSDL_BLENDMODE_BLEND when it is time to flush the zoom buffer.\r\n\r\nFixes #370\r\n\r\nI've played the game briefly and this resolves all of the graphical glitching-making-it-unplayable issues I know of right now.\r\n\r\nThe only potential downside is that due to the alpha blending, some of the cursors may not look quite pixel perfect. Noticably the red square used to highlight tiles doesn't have quite the right perceived colour (compare it with the red build blueprint):\r\n \r\n![screenshot from 2015-02-11 02 12 00](https://cloud.githubusercontent.com/assets/438648/6140700/673b5802-b193-11e4-9501-0783eec28f10.png)\r\n\r\ncompared with the usual unzoomed:\r\n\r\n![screenshot from 2015-02-11 02 14 32](https://cloud.githubusercontent.com/assets/438648/6140721/c6906450-b193-11e4-9ba6-41d59f0aea17.png)\r\n\r\n.. but this is preferable to the graphics completely breaking :)\r\n\r\n--\r\n\r\nAfter spending too much time staring at an OpenGL API trace with [vogl](https://github.com/ValveSoftware/vogl), it's apparent that an uninitialized texture ends up being the render target. Sometimes this coincidentally contains \"okay-ish\" textures, and other times it contains unaligned junk (whatever happens to be in texture memory).\r\n\r\n[I suspect offending code is this `SDL_CreateTexture`](https://github.com/CorsixTH/CorsixTH/blob/c384754bad1fdcb1d9a258e924ebb13fcc8ab61b/CorsixTH/Src/th_gfx_sdl.cpp#L300-L307), where a texture is created and then immediately used as render target.\r\n\r\nI've been struggling to think of a decent fix, my first thought was to blank the texture with `fillBlack()`, which works fine until you zoom whilst constructing and then it breaks (everything is black except the cursor). I then tried copying various buffers around but obviously this was slow (and difficult to get correctly aligned). So I went with the alpha-blend trick."},"comment":{"url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/comments/74003648","html_url":"https://github.com/CorsixTH/CorsixTH/pull/687#issuecomment-74003648","issue_url":"https://api.github.com/repos/CorsixTH/CorsixTH/issues/687","id":74003648,"user":{"login":"TheCycoONE","id":823433,"avatar_url":"https://avatars.githubusercontent.com/u/823433?v=3","gravatar_id":"","url":"https://api.github.com/users/TheCycoONE","html_url":"https://github.com/TheCycoONE","followers_url":"https://api.github.com/users/TheCycoONE/followers","following_url":"https://api.github.com/users/TheCycoONE/following{/other_user}","gists_url":"https://api.github.com/users/TheCycoONE/gists{/gist_id}","starred_url":"https://api.github.com/users/TheCycoONE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TheCycoONE/subscriptions","organizations_url":"https://api.github.com/users/TheCycoONE/orgs","repos_url":"https://api.github.com/users/TheCycoONE/repos","events_url":"https://api.github.com/users/TheCycoONE/events{/privacy}","received_events_url":"https://api.github.com/users/TheCycoONE/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T01:53:11Z","updated_at":"2015-02-12T01:53:11Z","body":"Works great for me too.  Excellent work!"}}