1

I'm currently working on a tile-based 2d engine for Haskell. So my current task is to extract(=import) sections of a picture. I am using from Graphics.Gloss.Data.Picture

bitmapSection :: Rectangle -> BitmapData -> Picture

My Problemm is as Following: I tried multiple diferent convertion methods (see full code below) but none of them yields the result I wish to have.

the base Image is: enter image description here (size is: 32x32)

what I get is: enter image description here

Note:I tried every diferent input/conversion method I could think of and drew them side by side...

now the question is: what am I doing wrong?

full sample code:

import Graphics.Gloss.Interface.Pure.Game
    ( white, Display(InWindow), Event, Picture(Blank), pictures, bitmap, translate)
import Graphics.Gloss.Interface.IO.Game (playIO)


import Graphics.Gloss
    ( white,
      bitmapSection,
      Display(InWindow),
      Picture(Blank),
      bitmapDataOfBMP,
      bitmapDataOfByteString,
      bitmapOfByteString,
      BitmapFormat(BitmapFormat),
      PixelFormat(PxRGBA, PxABGR),
      RowOrder(TopToBottom, BottomToTop ),
      Rectangle (Rectangle),
      BitmapData (bitmapSize), bitmapOfBMP, bitmapOfForeignPtr
      )

import qualified Data.ByteString as ByteString

main :: IO ()
main = do
    state <- read'
    playIO
        window
        background 
        fps
        state
        (\state -> return state)
        (\event state -> return state)
        (\_ state -> return state)

        where
            background = white
            window = InWindow "WindowName" (500,100) (10,10)
            fps = 60


read' :: IO Picture
read' = do
    file <- ByteString.readFile "rechteck_gruen.bmp"
    let 
        bit_map1 = bitmapDataOfByteString  32 32 (BitmapFormat BottomToTop PxRGBA) file True
        bit_map2 = bitmapDataOfByteString  32 32 (BitmapFormat TopToBottom PxRGBA) file True
        bit_map3 = bitmapDataOfByteString  32 32 (BitmapFormat BottomToTop PxABGR) file True
        bit_map4 = bitmapDataOfByteString  32 32 (BitmapFormat TopToBottom PxABGR) file True

        pic1 = bitmapOfByteString 32 32 (BitmapFormat BottomToTop PxRGBA) file True 
        pic2 = bitmapOfByteString 32 32 (BitmapFormat TopToBottom PxRGBA) file True
        pic3 = bitmapOfByteString 32 32 (BitmapFormat BottomToTop PxABGR) file True
        pic4 = bitmapOfByteString 32 32 (BitmapFormat TopToBottom PxABGR) file True

        {--
        Important: bitmapSection with size 32x32 is only for testing purpose... 
        therefore picFromSection should be equal to picFromByteString ? 
        --}
        picFromSection = map (\bitMap -> bitmapSection (Rectangle (0,0) (32,32)) bitMap) 
            [bit_map1, bit_map2, bit_map3, bit_map4]

        picFromByteString = [pic1, pic2, pic3, pic4]

        picFromBitMap = map (\bitMap -> bitmap bitMap) 
            [bit_map1, bit_map2, bit_map3, bit_map4]

        scene = picFromSection ++ picFromByteString ++ picFromBitMap

        performTranslate _ [] = []
        performTranslate n (x:xs) = translate (n*40-230) 0 x  : performTranslate (n+1)  xs

   
    
    return $ pictures $ performTranslate 0 scene
Thomas Meyer
  • 384
  • 1
  • 11

0 Answers0