Just to mess around with Haskell's Gloss library, I wrote:
import Graphics.Gloss
data World = World { worldBugs :: [Picture] }
bug :: Point -> Float -> Picture
bug (x, y) s =
let head = Translate x (y - s) $ Circle (s * 0.8)
body = Translate x (y + s) $ Circle (s * 1.2)
in pictures [head, body]
main = play (InWindow "Animation Test" (400, 400) (100, 100)) white 10
(World . map (\(n,b) -> Translate (n * 20) (n * 20) $ b) $ zip [0..] $ replicate 100 $ bug (0,0) 100)
(\world -> pictures $ worldBugs world)
(\event world -> world)
(\time (World bs) -> World $ map (Rotate (time * 10)) bs)
Which displays some "bugs" (two circles forming a head and torso) that rotate as time passes. The problem is, after a couple seconds of running, it crashes with:
Gloss / OpenGL Stack Overflow "after drawPicture."
This program uses the Gloss vector graphics library, which tried to
draw a picture using more nested transforms (Translate/Rotate/Scale)
than your OpenGL implementation supports. The OpenGL spec requires
all implementations to have a transform stack depth of at least 32,
and Gloss tries not to push the stack when it doesn't have to, but
that still wasn't enough.
You should complain to your harware vendor that they don't provide
a better way to handle this situation at the OpenGL API level.
To make this program work you'll need to reduce the number of nested
transforms used when defining the Picture given to Gloss. Sorry.
which, if I understand it correctly basically means that eventually, too many transformations are put onto a stack, and it overflows. It notes that this might be a hardware limitation (I'm on a Surface 2 Pro), so am I SOL? It doesn't do this when using animate
, but that's probably due to the fact that it doesn't pass a state each tick.
If I'm going to make a game, I'm going have to use play
to pass a state to the next tick; I can't base everything on time. Is there a way around this? Googling the error yields next to nothing.