OSX平台Gloss无法以原生分辨率渲染该如何解决?
Let's work through how to fix this frustrating scaling issue you're hitting with Gloss on your Retina-display Mac.
The Issue You're Facing
As you outlined:
在OSX系统(原生分辨率2560×1600)中,Gloss会将所有内容以2倍缩放因子显示:调用display函数设置300×300窗口时,实际生成600×600的窗口,无论是Gloss绘制的内容还是通过Juicy加载的精灵,各维度尺寸均放大一倍。将内容缩小无法达到原生分辨率下的清晰效果。
Here's your original code for context:
module Main where import Graphics.Gloss import Graphics.Gloss.Juicy import Codec.Picture main :: IO () main = loadJuicy "someimg.png" >>= maybe ( print "Nope" ) displayImg displayImg :: Picture -> IO () displayImg p = display ( InWindow "Image" ( 300, 300 ) ( 100, 100 ) ) white ( pictures [ p, translate 32 32 $ circleSolid 4 ] )
Why This Happens
At first glance, it seems like a dead end because Gloss doesn't expose low-level OpenGL access—but the real issue is tied to Gloss's default backend. The GLUT backend that Gloss uses out of the box doesn't handle macOS's Retina display pixel scaling correctly, forcing that 2x magnification regardless of your window settings.
The Fix
You can resolve this by rebuilding Gloss with the GLFW backend enabled and GLUT disabled. GLFW has proper Retina display support on macOS, which will let Gloss render at your native 2560×1600 resolution without forced scaling.
Here's how to do it:
- If you're using Cabal, install Gloss with these flags:
cabal install gloss --flags="glfw -glut" - If you use Stack, update your
stack.yamlto include the same flags for the Gloss package, then rebuild your project.
Once you switch to the GLFW backend, your existing code will render at the exact window dimensions you specify, giving you crisp, native-resolution output.
内容的提问来源于stack exchange,提问作者Merzhase

