Gloss
A shiny JSON parsing library in Swift
Gloss - A shiny JSON Parsing Library in Swift | harlan kellaway
I have spent an evening until some ridiculous time in the morning trying to figure out how to get Haskell's GHC to work correctly and to have Cabal install the gloss library.
After reading through every bit of documentation/error reports imaginable, even with old installs of ghc, gcc binary (instead of a symlink to clang), and brewing llvm no matter what happened one fix resolved one issue, only to then present another.
So I have a simple solution that worked for me for Yosemite and I will post it below (I wish someone else had posted it here)
Source: (StackOverflow)
I want to access the pixel data of what is being displayed to the window, but I have not had any luck finding such a function in gloss, nor by attempting to call OpenGL readPixels in a keyboard event callback. It looks like gloss renders a Picture to the window without exposing the rendered bitmap.
If this is hard to do in gloss, is there an alternative which has realtime high-level bitmap manipulation (translation, rotation, transparency)?
Source: (StackOverflow)
gloss
is a nice library for graphics. The problem, is, when I run it in ghci
, it closes ghci
as soon as I exit. I tried using forkIO
, but it still closes ghci after closing the window. How do I get gloss
to not close ghci (or at least keep the history) or is it better to just use a file?
Source: (StackOverflow)
When I load the haskell / gloss examples (so far I've tried Wave and Snow), I seem to be getting an error with finding something in the GLUT shared libraries. What might cause this error and how can I fix it?
can't load .so/.DLL for: /Users/jd/sandbox/.cabal-sandbox/lib/x86_64-osx-ghc-7.10.1/GLUT_J2ZZFJOYOcH4hQYFlXhEPp/libHSGLUT-2.7.0.1-0waW9bZutCf5s5H5zSV4Oh-ghc7.10.1.dylib (dlopen(/Users/jd/sandbox/.cabal-sandbox/lib/x86_64-osx-ghc-7.10.1/GLUT_J2ZZFJOYOcH4hQYFlXhEPp/libHSGLUT-2.7.0.1-0waW9bZutCf5s5H5zSV4Oh-ghc7.10.1.dylib, 5): Symbol not found: _glutBitmap8By13
Referenced from: /Users/jd/sandbox/.cabal-sandbox/lib/x86_64-osx-ghc-7.10.1/GLUT_J2ZZFJOYOcH4hQYFlXhEPp/libHSGLUT-2.7.0.1-0waW9bZutCf5s5H5zSV4Oh-ghc7.10.1.dylib
Expected in: flat namespace
in /Users/jd/sandbox/.cabal-sandbox/lib/x86_64-osx-ghc-7.10.1/GLUT_J2ZZFJOYOcH4hQYFlXhEPp/libHSGLUT-2.7.0.1-0waW9bZutCf5s5H5zSV4Oh-ghc7.10.1.dylib)
This is on mac OSX 10.9.5 with GHC 7.10.1
Source: (StackOverflow)
I'm trying to run a simple Gloss program in Haskell on Xubuntu 14.04.
Now i've run the same program before with no issues on the same machine a while ago but it seems like its no longer working. Apparently it thinks Gloss is not installed when it is.
I've tried a lot of things with no luck.
Error when trying to compile program:
MyProg.hs:2:8:
Could not find module `Graphics.Gloss'
Use -v to see a list of the files searched for.
When using -v flag:
Glasgow Haskell Compiler, Version 7.6.3, stage 2 booted by GHC version 7.6.3
Using binary package database: /usr/lib/ghc/package.conf.d/package.cache
Using binary package database: /home/myuser/.ghc/x86_64-linux-7.6.3/package.conf.d/package.cache
package GLUT-2.4.0.0-31a913db9728fc0bba038e31af3ad274 is unusable due to missing or recursive dependencies:
OpenGL-2.8.0.0-344e8603ffa2fe942e6526830661f0ee
package OpenGL-2.8.0.0-344e8603ffa2fe942e6526830661f0ee is shadowed by package OpenGL-2.8.0.0-965a1de4ba5cd960ad85db9941a93722
package gloss-1.8.1.2-eb3652fd7115ec4d025ca235f1e1d64d is unusable due to missing or recursive dependencies:
GLUT-2.4.0.0-31a913db9728fc0bba038e31af3ad274 OpenGL-2.8.0.0-344e8603ffa2fe942e6526830661f0ee
package gloss-raster-1.8.1.2-fd045cd6d26cf5909eb1793d4659a1f3 is unusable due to missing or recursive dependencies:
gloss-1.8.1.2-eb3652fd7115ec4d025ca235f1e1d64d
hiding package HTTP-4000.2.8 to avoid conflict with later version HTTP-4000.2.19
hiding package Cabal-1.16.0 to avoid conflict with later version Cabal-1.22.4.0
hiding package binary-0.5.1.1 to avoid conflict with later version binary-0.6.4.0
hiding package network-2.4.1.2 to avoid conflict with later version network-2.6.2.0
hiding package parallel-3.2.0.3 to avoid conflict with later version parallel-3.2.0.6
hiding package GLURaw-1.3.0.0 to avoid conflict with later version GLURaw-1.4.0.2
hiding package binary-0.6.4.0 to avoid conflict with later version binary-0.7.4.0
wired-in package ghc-prim mapped to ghc-prim-0.3.0.0-d5221a8c8a269b66ab9a07bdc23317dd
wired-in package integer-gmp mapped to integer-gmp-0.5.0.0-2f15426f5b53fe4c6490832f9b20d8d7
wired-in package base mapped to base-4.6.0.1-8aa5d403c45ea59dcd2c39f123e27d57
wired-in package rts mapped to builtin_rts
wired-in package template-haskell mapped to template-haskell-2.8.0.0-a3012803fde1dc362e555b35a1a78e6d
wired-in package dph-seq not found.
wired-in package dph-par not found.
Hsc static flags: -static
*** Chasing dependencies:
Chasing modules from: *MyProg.hs
MyProg.hs:2:8:
Could not find module `Graphics.Gloss'
Locations searched:
Graphics/Gloss.hs
Graphics/Gloss.lhs
*** Deleting temp files:
Deleting:
*** Deleting temp dirs:
Deleting:
What seems to be the issue? (The machine has not changed at all since the program last worked fine, I had installed and used Gloss successfully then).
Source: (StackOverflow)
I switched from C++ to Haskell and use Gloss to make games.
I wrote this valid code in a main.hs:
import Graphics.Gloss.Interface.Pure.Game
events (EventKey (Char 'a') Down _ _) _ = RectangleWire 10 10
events _ x = x
main = play (InWindow "GameEvent" (700, 100) (10, 10))
white
100
(Circle 10.0)
id
events
(\_ world -> world)
Then the command ghc main.hs
answered:
[1 of 1] Compiling Main ( main.hs, main.o )
main.hs:3:43: Not in scope: data constructor `RectangleWire'
It seems some functions are missing from my Gloss lib even though I have the latest version installed. For example, this code, "Game Event" from the gloss-examples package, compiles and runs perfectly (so beautiful):
import Graphics.Gloss
-- | Display the last event received as text.
main
= play (InWindow "GameEvent" (700, 100) (10, 10))
white
100
""
(\str -> Translate (-340) 0 $ Scale 0.1 0.1 $ Text str)
(\event _ -> show event)
(\_ world -> world)
Source: (StackOverflow)
If you import Gloss within a Stack project and use stack ghci
, you get the following error:
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
<command line>: can't load .so/.DLL for: /Users/v/hs/.stack-work/install/x86_64-osx/lts-3.7/7.10.2/lib/x86_64-osx-ghc-7.10.2/GLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv/libHSGLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv-ghc7.10.2.dylib (dlopen(/Users/v/hs/.stack-work/install/x86_64-osx/lts-3.7/7.10.2/lib/x86_64-osx-ghc-7.10.2/GLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv/libHSGLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv-ghc7.10.2.dylib, 5): Symbol not found: _glutBitmap8By13
Referenced from: /Users/v/hs/.stack-work/install/x86_64-osx/lts-3.7/7.10.2/lib/x86_64-osx-ghc-7.10.2/GLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv/libHSGLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv-ghc7.10.2.dylib
Expected in: flat namespace
in /Users/v/hs/.stack-work/install/x86_64-osx/lts-3.7/7.10.2/lib/x86_64-osx-ghc-7.10.2/GLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv/libHSGLUT-2.7.0.3-FFXiDYE1CfiDHjNKroBerv-ghc7.10.2.dylib)
How can that be fixed?
Source: (StackOverflow)
I have a program which simulates the interaction of many agents in a community. I'm animating the interaction using the Gloss library, the pictures of the agents render correctly, just not the animation. I animate it by generating a simulation, which is a list of list of interactions, which I then take the one corresponding to the second of the animation, where I then render that interaction. The code for simulating works fine when outputting it to terminal. The code:
render :: Int -> History -> Picture -- assume window to be square
render size (History int agents) = Pictures $ map (drawAgent (step`div`2) colors step) agents
where step = size*6 `div` (length agents)
--agents = nub $ concat $ map (\(Interaction a1 a2 _ ) -> [a1,a2]) int
nubNames = nub $ map (getName . name) agents --ignore the first two letters of name
colors = Map.fromList $ zipWith (\name color-> (name, color)) nubNames (cycle colorlist)
colorlist = [red,green,blue,yellow,cyan,magenta,rose,violet,azure,aquamarine,chartreuse,orange]
drawAgent :: Int -> Map.Map String Color -> Int -> Agent -> Picture
drawAgent size colors step agent =
color aColor (Polygon [(posA,posB),(posA,negB),(negA,negB),(negA,posB)])
where aColor = fromMaybe black $ Map.lookup (getName $ name agent ) colors
a = (fst $ position agent) * step
b = (snd $ position agent) * step
posA = fromIntegral $ a+size
negA = fromIntegral $ a-size
posB = fromIntegral $ b+size
negB = fromIntegral $ b-size
simulate :: Int -> [Agent] -> [History]
simulate len agents = trace ("simulation"
(playRound agents len) :
simulate len (reproduce (playRound agents len))
main = do
a <- getStdGen
G.animate (G.InWindow "My Window" (400, 400) (0,0)) G.white
(\time ->(render 400) $ ((simulate 5 (agent a))!!(floor time)))
where agent a = generate a 9
sim a = simulate 40 (agent a)
When I execute this, it will say the simulation is running, but only render the first interaction.
$ ghc -O2 -threaded main.hs && ./main
[6 of 8] Compiling Prisoners ( Prisoners.hs, Prisoners.o )
Linking main ...
simulation
simulation
simulation
It will continue like this until I stop it, rendering the same picture each time. What am I doing wrong?
Source: (StackOverflow)
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.
Source: (StackOverflow)
I am building a simple interactive program with 2D-graphics, and I'd like to know which combination of Haskell libraries are likely to work. My requirements and ideas-so-far are below:
Fundamental requirements:
- Simple 2-D geometric drawing, of the sort provided by Gloss or Diagrams
- SVG-style interactivity: For example, playing a jigsaw puzzle or Fifteen Game, be able to click on an object and maybe drag it around the canvas.
- (Fallback: Use keyboard navigation to move around the image, activate an object, etc)
Induced Requirements:
- I'd prefer to work in FP Haskell Center, which implies that my UI should be a web app (with Yesod/Snap/Happstack).
If a web app, it could be "image-map" style, where every interaction involves a round-trip to the server, or Javascript style, as with Fay or Elm
Non-requirements:
- This is a self-contained "toy" (like Tangrams or a jigsaw puzzle), so it doesn't need any persistent state in a database
My ideas:
Can anyone suggest set of packages and architecture style that would likely work well together for this UI? My current ideas are:
Yesod with {Gloss or Diagrams} to draw static graphics in FP Haskell Center.
- Then switch to local development to add local native mouse-click interactivity.
- Or use some Ajax solution to send click events back to the server to update graphics
Elm with reactive graphics, without FP Haskell Center
Interactive Javascript experience, written in Fay, compiled to Javascript. (I have never used Fay, I don't know if it can rely on lots of Hackage packages, I know it does not support some extensions, but I don't know if it can use pre-compiled packages that depended on those extensions)
Elm and Fay seem similar, the main differences being that:
- (a) Elm is not actually Haskell
- (b) Fay doesn't enforce FRP style?
Any recommendations?
Source: (StackOverflow)
I am facing a peculiar problem. Here at high school I have got about 10 computers (all are same type, same type cpu, same type memory etc) donated which are now running Debian after reinstall. I was try to teach the pupils some Haskell, I myself learned it little. The kids are interested. A problem is our country is third world and the internet is very slow and costly. The basic ghc and ghci I installed using deb packages (found by using apt-rdepends) on all machines after once downloading all of the deb files only on one machine using some limited time free internet connection. It has taken more than 10 hours to download the all ghc deb files that are missing.
I want know if such trick is possible for cabal? I will download all required tar or other files once, on one computer, using the costly and slow internet, but then I do not want spend all my money to download from internet for all 10 computers.
I want show the kids diagrams and gloss package as it is enjoyable and funny.
I am inspired by this gentleman Smith
How should I do this ? Is there way for other packages in general other than diagrams and gloss?
Thank you and sorry for my bad English.
Source: (StackOverflow)
I'm attempting to use the Gloss library's play
function, which takes an event-handling function whose first argument is of type Event
(according to the Hackage documentation). I'm working on Windows with GHC 7.6.3 and Gloss 1.8.0.1.
Here's a sketch of what I'm trying to do:
import Graphics.Gloss
type GameState = [Int]
handleInputEvent :: Event -> GameState -> GameState
handleInputEvent _ = id -- Just stubbed in for now
The compiler error is:
Not in scope: type constructor or class `Event'
If I go into WinGHCI and import Graphics.Gloss and ask it for the type signature of play
, it looks like this:
play ::
Display
-> Color
-> Int
-> world
-> (world -> Picture)
-> (gloss-1.8.0.1:Graphics.Gloss.Internals.Interface.Event.Event
-> world -> world)
-> (Float -> world -> world)
-> IO ()
I'm guessing this has something to do with the name Event
clashing with some other module, and thus not being imported in the same way as other symbols from Gloss.
How do I talk to Haskell about Gloss' Event
?
Source: (StackOverflow)
I'm using gloss to display something, while at the same time using forkOS $ system "mpg123 foo.mp3" >> return ()
to play some audio in the background. When I close the gloss window, the program exits, but the audio keeps playing. All resources show that this thread is supposed to die, what's going on? It doesn't die even when I use killThread
to kill it explicitly.
Source: (StackOverflow)
I am trying to recreate something similar to conky. Where the graphics are displayed on the background.So I looked in to gloss and X11 libraries for documentation.
The constructors for display in gloss
InWindow String (Int, Int) (Int, Int)
FullScreen (Int, Int)
Both of them don't allow transparency and windowless settings.
I been looking through haskell wiki.
https://wiki.haskell.org/X_window_programming_in_Haskell.
Some of the examples allows you to create windowless applications.
Could set_background_pixel allow the background to be transparent?
Is there a guide for transparency and rending graphics using gloss or some other library?
Source: (StackOverflow)
I've been messing around with Gloss for a little bit, getting a feel for it, and I really like it!
I'm having one problem though, and that is that I'm not sure how to persist drawings for more than one frame. I can draw one Picture at a time, but I'm not sure how to keep them on the screen. I can always keep a list of Pictures and display those, but that seems like it could be very inefficient, so I wanted to check if there was a better way to do it. I've been going through the documentation and haven't found anything.
Any help would be great! Thanks!
Source: (StackOverflow)