-1

I'm a beginner in haskell and trying to make a game. Currently learning Gloss graphics. I wonder how I can import an BMP (JPG or PNG) image in haskell? (As a character or background etc). I want the image to be shown in the graphics window IO (). But can't get it to work. Should I use another module than gloss for this?

Thanks for any help

loadBMP :: FilePath -> IO Picture

-- this obviously doesn't work, I tried this and hundreds of other things...
loadBMP = ./fish.bmp
radrow
  • 6,419
  • 4
  • 26
  • 53
blobfish
  • 25
  • 3
  • Have you encountered this > https://stackoverflow.com/q/47159722/4636715 – vahdet Feb 13 '19 at 14:24
  • 4
    `loadBMP` is [an existing function](https://www.stackage.org/haddock/lts-13.7/gloss-1.13.0.1/Graphics-Gloss-Data-Bitmap.html#v:loadBMP), so why are you trying to _define_ it? You should _use_ it instead, i.e. `fishSprite <- loadBMP "fish.bmp"` somewhere in your `main` action. – leftaroundabout Feb 13 '19 at 14:25

1 Answers1

0

It sounds like you're having trouble with the basics, so maybe a simple example would help. This will display a bmp image in a Gloss window:

module Main where

import Graphics.Gloss

main :: IO ()
main = do
  picture <- loadBMP "myimage.bmp"
  display (InWindow "Pic" (200, 200) (10, 10)) white picture

On your other point, about whether Gloss is suitable for a beginner game, I would say yes. It is well documented and relatively easy to use. I did a similar thing with it for my first Haskell project.

8n8
  • 1,233
  • 1
  • 8
  • 21
  • It's better to ask question by starting a new one, rather than ask new question in a comment section. –  Feb 23 '19 at 18:42
  • I get a weird error: `test01.hs: ErrorUnhandledCompressionMode {errorCompression = CompressionBitFields} CallStack (from HasCallStack): error, called at ./Graphics/Gloss/Internals/Data/Picture.hs:208:28 in gloss-rendering-1.13.0.2-5vVjOgmniwF2ujwiGcx8nq:Graphics.Gloss.Internals.Data.Picture ` Can you help me? > – mauroc8 Mar 18 '19 at 01:15
  • It's because ["We only handle uncompressed images"](http://hackage.haskell.org/package/bmp-1.2.6.3/docs/Codec-BMP.html#t:Error). Try [this image](https://www.w3.org/People/mimasa/test/imgformat/img/w3c_home.bmp) instead - it works for me. – 8n8 Mar 18 '19 at 09:43