-1

I am trying to run this example: https://raw.githubusercontent.com/elisehuard/game-in-haskell/master/src/Shapes.hs

But I get the error "freeglut ERROR: Function called without first calling 'glutInit'."

I managed to isolate the problem to line 39 : "Color (bright magenta) $ translate 0 (-100) $ scale 0.2 0.2 $ text "Boo!""

when I change it to : "Color (bright magenta) $ translate 0 (-100) $ scale 0.2 0.2 $ blank

It's working fine.

I am working on linux mint 19; Gloss version 1.13.0.1; gloss-rendering 1.13.0.2.


After Cloning gloss, building, and adding the new cloned lib to my stack

malki@Hood:~/Projects/TstP$ stack build
TstP-0.1.0.0: build (lib + exe)
gloss-1.13.0.1: build (lib)
Completed 2 action(s).
Log files have been written to: /home/malki/Projects/TstP/.stack-work/logs/

--  While building package TstP-0.1.0.0 using:
      /home/malki/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 build lib:TstP exe:TstP-exe --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/malki/Projects/TstP/.stack-work/logs/TstP-0.1.0.0.log

    Preprocessing library for TstP-0.1.0.0..
    Building library for TstP-0.1.0.0..
    Preprocessing executable 'TstP-exe' for TstP-0.1.0.0..
    Building executable 'TstP-exe' for TstP-0.1.0.0..
    [1 of 2] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/TstP-exe/TstP-exe-tmp/Main.o )
    
    /home/malki/Projects/TstP/app/Main.hs:5:1: error:
        Could not find module ‘Graphics.UI.GLFW’
        It is not a module in the current program, or in any known package.
      |
    5 | import "GLFW-b" Graphics.UI.GLFW as GLFW
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:6:1: error:
        Could not find module ‘Graphics.Gloss’
        Use -v to see a list of the files searched for.
      |
    6 | import Graphics.Gloss
      | ^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:7:1: error:
        Could not find module ‘Graphics.Gloss.Rendering’
        Use -v to see a list of the files searched for.
      |
    7 | import Graphics.Gloss.Rendering
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:8:1: error:
        Could not find module ‘Graphics.Gloss.Data.Color’
        Use -v to see a list of the files searched for.
      |
    8 | import Graphics.Gloss.Data.Color
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    
    /home/malki/Projects/TstP/app/Main.hs:9:1: error:
        Could not find module ‘Graphics.Gloss.Data.Picture’
        Use -v to see a list of the files searched for.
      |
    9 | import Graphics.Gloss.Data.Picture
      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^


--  While building package gloss-1.13.0.1 using:
      /home/malki/.stack/setup-exe-cache/x86_64-linux/Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 --builddir=.stack-work/dist/x86_64-linux/Cabal-2.2.0.1 build lib:gloss --ghc-options " -ddump-hi -ddump-to-file"
    Process exited with code: ExitFailure 1
    Logs have been written to: /home/malki/Projects/TstP/.stack-work/logs/gloss-1.13.0.1.log

    Preprocessing library for gloss-1.13.0.1..
    Building library for gloss-1.13.0.1..
    [ 1 of 44] Compiling Graphics.Gloss.Data.Bitmap ( Graphics/Gloss/Data/Bitmap.hs, .stack-work/dist/x86_64-linux/Cabal-2.2.0.1/build/Graphics/Gloss/Data/Bitmap.o ) [Graphics.Gloss.Rendering changed]
    
    /home/malki/Projects/TstP/gloss/gloss/Graphics/Gloss/Data/Bitmap.hs:15:1: error:
        Could not find module ‘Graphics.Gloss.Rendering’
        There are files missing in the ‘gloss-rendering-1.13.0.2’ package,
        try running 'ghc-pkg check'.
        Use -v to see a list of the files searched for.
       |
    15 | import Graphics.Gloss.Rendering
       | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
malki@Hood:~/Projects/TstP$ 

These modules exists as global modules (things compile outside this stack dir). They are not present in the gloss-clone though.

malki@Hood:~/Projects/TstP/gloss/gloss$ find ./Graphics
./Graphics
./Graphics/Gloss
./Graphics/Gloss/Geometry
./Graphics/Gloss/Geometry/Angle.hs
./Graphics/Gloss/Geometry/Line.hs
./Graphics/Gloss/Geometry.hs
./Graphics/Gloss/Interface
./Graphics/Gloss/Interface/Pure
./Graphics/Gloss/Interface/Pure/Simulate.hs
./Graphics/Gloss/Interface/Pure/Animate.hs
./Graphics/Gloss/Interface/Pure/Game.hs
./Graphics/Gloss/Interface/Pure/Display.hs
./Graphics/Gloss/Interface/IO
./Graphics/Gloss/Interface/IO/Simulate.hs
./Graphics/Gloss/Interface/IO/Animate.hs
./Graphics/Gloss/Interface/IO/Interact.hs
./Graphics/Gloss/Interface/IO/Game.hs
./Graphics/Gloss/Interface/IO/Display.hs
./Graphics/Gloss/Interface/Environment.hs
./Graphics/Gloss/Data
./Graphics/Gloss/Data/Vector.hs
./Graphics/Gloss/Data/Point.hs
./Graphics/Gloss/Data/ViewState.hs
./Graphics/Gloss/Data/ViewPort.hs
./Graphics/Gloss/Data/Color.hs
./Graphics/Gloss/Data/Point
./Graphics/Gloss/Data/Point/Arithmetic.hs
./Graphics/Gloss/Data/Bitmap.hs
./Graphics/Gloss/Data/Controller.hs
./Graphics/Gloss/Data/Picture.hs
./Graphics/Gloss/Data/Display.hs
./Graphics/Gloss/Internals
./Graphics/Gloss/Internals/Color.hs
./Graphics/Gloss/Internals/Interface
./Graphics/Gloss/Internals/Interface/Common
./Graphics/Gloss/Internals/Interface/Common/Exit.hs
./Graphics/Gloss/Internals/Interface/Event.hs
./Graphics/Gloss/Internals/Interface/ViewState
./Graphics/Gloss/Internals/Interface/ViewState/KeyMouse.hs
./Graphics/Gloss/Internals/Interface/ViewState/Motion.hs
./Graphics/Gloss/Internals/Interface/ViewState/Reshape.hs
./Graphics/Gloss/Internals/Interface/Simulate
./Graphics/Gloss/Internals/Interface/Simulate/Idle.hs
./Graphics/Gloss/Internals/Interface/Simulate/State.hs
./Graphics/Gloss/Internals/Interface/Simulate.hs
./Graphics/Gloss/Internals/Interface/Backend
./Graphics/Gloss/Internals/Interface/Backend/GLFW.hs
./Graphics/Gloss/Internals/Interface/Backend/GLUT.hs
./Graphics/Gloss/Internals/Interface/Backend/Types.hs
./Graphics/Gloss/Internals/Interface/Backend.hs
./Graphics/Gloss/Internals/Interface/Animate.hs
./Graphics/Gloss/Internals/Interface/Callback.hs
./Graphics/Gloss/Internals/Interface/Interact.hs
./Graphics/Gloss/Internals/Interface/Animate
./Graphics/Gloss/Internals/Interface/Animate/Timing.hs
./Graphics/Gloss/Internals/Interface/Animate/State.hs
./Graphics/Gloss/Internals/Interface/Debug.hs
./Graphics/Gloss/Internals/Interface/Game.hs
./Graphics/Gloss/Internals/Interface/Window.hs
./Graphics/Gloss/Internals/Interface/Display.hs
./Graphics/Gloss.hs
malki@Hood:~/Projects/TstP/gloss/gloss$ 

Isn't the local Graphic branch supposed to shadow the existing one? It seems that it tries to replace it in full.


Please advise!

Cheers!

finuux
  • 1
  • 2

1 Answers1

1

Gloss is compiled to run either with GLFW or GLUT - see Backend.hs:

#ifdef WITHGLUT
defaultBackendState :: GLUTState
#elif  WITHGLFW
defaultBackendState :: GLFWState
#else
#error No default backend defined
#endif

WITHGLUT and WITHGLFW are compile-time flags specified when building the package. The code you're trying to run manually sets up a GLFW window, then uses gloss to render things: it looks like the gloss you're using is compiled to use GLUT instead of GLFW, so the setup that's been done manually isn't sufficient.


You'll need to recompile gloss to use GLFW instead:

git clone https://github.com/benl23x5/gloss
cd gloss
stack build --flag gloss:glfw --flag gloss:-glut

You may need to tweak the build files to fix errors during the build: stack's pretty good at explaining what you need to fix. I had to:

  • Add GLFW-b-1.4.8.4@sha256:2d10594c5cfa9d5178596eb6a18106a1318409e47a4108bfe91b89d80684638e to the extra-deps of stack.yaml
  • Add Graphics.Gloss.Internals.Interface.Backend.GLUT to Other-modules in gloss.cabal.

You can then modify the build files for the example you're trying to run to make stack use your local version of the package as described here.

hnefatl
  • 5,860
  • 2
  • 27
  • 49
  • After cloning gloss & building, I get a bunch of errors about missing modules: Could not find module ‘Graphics.Gloss.Rendering’ I have gloss-rendering installed globally. I don't see it in the gloss clone though... – finuux Dec 09 '18 at 01:20
  • @finuux If it's not in the top directory of the cloned repo then it's a git issue - you should be running those commands from the same directory as the stack-x.y.yaml files. It would help if you edited your answer to quote the exact errors you get. – hnefatl Dec 09 '18 at 09:17
  • Thanks for the advice, I am new to stack-overflow. I edited with errors... – finuux Dec 09 '18 at 22:36