Создание простого проекта opengl с использованием стека?

Я создаю простой проект haskell-opengl. Он собирается успешно с помощью команд:

cabal configure
cabal build

Когда я использую стек:

stack build

Я получаю сообщение об ошибке:

GLUT-2.7.0.1: configure
Progress
    Configuring GLUT-2.7.0.1...
    Setup.hs: Missing dependency on a foreign library:
    * Missing C library: glut32
    This problem can usually be solved by installing the system package that
    provides this library (you may need the "-dev" version). If the library is
    already installed but in a non-standard location then you can use the flags
    --extra-include-dirs= and --extra-lib-dirs= to specify where it is.

Как использовать стек Glut.dll?

module Main where

import Graphics.UI.GLUT
import Foreign.Marshal.Array
import Foreign.Ptr
import Foreign.Storable()
import Foreign.C.Types()
import qualified Data.ByteString as BS
import Control.Monad

data State = State
    {
        vertexBuffer :: BufferObject,
        gpuProgram :: Program
    }

triangleVertexes :: [GLfloat]
triangleVertexes = [
     0.0,  0.5,   0.0, 1.0,
     0.5, -0.366, 0.0, 1.0,
    -0.5, -0.366, 0.0, 1.0,
     1.0,  0.0,   0.0, 1.0,
     0.0,  1.0,   0.0, 1.0,
     0.0,  0.0,   1.0, 1.0
    ]

main :: IO ()
main = do
   (progName, _) <- getArgsAndInitialize
   initialDisplayMode $= [ DoubleBuffered, RGBAMode, WithAlphaComponent, WithDepthBuffer ]
   _ <- createWindow progName
   state <- initializeState
   displayCallback $= display state
   reshapeCallback $= Just (reshape state)
   mainLoop

fragmentShaderFilePath :: FilePath
fragmentShaderFilePath = "shader.frag"

vertexShaderFilePath :: FilePath
vertexShaderFilePath = "shader.vert"

createVertexBuffer :: [GLfloat] -> IO BufferObject
createVertexBuffer vertexes = do
    bufferObject <- genObjectName
    bindBuffer ArrayBuffer $= Just bufferObject
    withArrayLen vertexes $ \count arr ->
        bufferData ArrayBuffer $= (fromIntegral count * 4, arr, StaticDraw)
    enableAttribLocations [0, 1]
    setAttribPointers
    return bufferObject

vertexNumComponents :: NumComponents
vertexNumComponents = 4

colorNumComponents :: NumComponents
colorNumComponents = 4

initializeState :: IO State
initializeState = do
    bufferObject <- createVertexBuffer triangleVertexes
    program <- initGPUProgram
    return State
        {
            vertexBuffer = bufferObject,
            gpuProgram = program
        }

loadShader :: ShaderType -> FilePath -> IO Shader
loadShader t path = do
    shader <- createShader t
    source <- BS.readFile path
    shaderSourceBS shader $= source
    compileShader shader
    status <- get (compileStatus shader)
    unless status $ putStrLn . (("message" ++ " log: ") ++) =<< get (shaderInfoLog shader)
    return shader

initGPUProgram :: IO Program
initGPUProgram = do
    vertexShader <- loadShader VertexShader vertexShaderFilePath
    fragmentShader <- loadShader FragmentShader fragmentShaderFilePath
    let shaders = [vertexShader, fragmentShader]
    program <- createProgram
    mapM_ (attachShader program) shaders
    linkProgram program
    mapM_ (detachShader program) shaders
    return program

display :: State -> DisplayCallback
display state = do
    clearColor $= Color4 1.0 0.0 1.0 1.0
    clear [ ColorBuffer ]
    bindBuffer ArrayBuffer $= Just (vertexBuffer state)
    enableAttribLocations [0, 1]
    setAttribPointers
    currentProgram $= Just (gpuProgram state)
    drawArrays Triangles 0 3
    disableAttribLocations [0, 1]
    swapBuffers
    checkError "display"

setCapabilityForAttribLocations :: Capability -> [GLuint] -> IO ()
setCapabilityForAttribLocations capability =
    mapM_ (\location -> vertexAttribArray (AttribLocation location) $= capability)

disableAttribLocations :: [GLuint] -> IO ()
disableAttribLocations = setCapabilityForAttribLocations Disabled

enableAttribLocations :: [GLuint] -> IO ()
enableAttribLocations = setCapabilityForAttribLocations Enabled

setAttribPointers :: IO ()
setAttribPointers = do
    vertexAttribPointer (AttribLocation 0) $= (ToFloat, VertexArrayDescriptor vertexNumComponents Float 0 nullPtr)
    vertexAttribPointer (AttribLocation 1) $= (ToFloat, VertexArrayDescriptor colorNumComponents Float 0 (plusPtr nullPtr 48))

reshape :: State -> ReshapeCallback
reshape _ size =
     viewport $= (Position 0 0, size)

checkError :: String -> IO ()
checkError functionName = get errors >>= mapM_ reportError
    where reportError e = putStrLn (showError e ++ " detected in " ++ functionName)
          showError (Error category message) = "GL error " ++ show category ++ " (" ++ message ++ ")"

-- фрагментный шейдер

#version 330

smooth in vec4 theColor;

out vec4 outputColor;

void main()
{
    outputColor = theColor;
}

-- вершинный шейдер

 #version 330

layout (location = 0) in vec4 position;
layout (location = 1) in vec4 color;

smooth out vec4 theColor;

void main()
{
    gl_Position = position + vec4(0.5, 0.5, 0.0, 1.0);
    theColor = color;
}

person Bet    schedule 27.07.2015    source источник
comment
Можете ли вы предоставить дополнительную информацию, например (1) ОС/архитектуру, (2) вывод для stack --version и stack exec -- ghc --version, ghc --version и cabal --version?   -  person Michael Snoyman    schedule 15.08.2015
comment
stack --version: версия 0.1.2.0, версия Git 65246552936b7da4b64b38372feac903d96a8911   -  person Bet    schedule 16.08.2015
comment
stack exec -- ghc --version : Версия 0.1.2.0, Git ревизия 65246552936b7da4b64b38372feac903d96a8911   -  person Bet    schedule 16.08.2015
comment
ghc --version: Великолепная система компиляции Haskell в Глазго, версия 7.8.3   -  person Bet    schedule 16.08.2015
comment
cabal --version : cabal-установить версию 1.18.0.5, используя версию 1.18.1.3 библиотеки Cabal   -  person Bet    schedule 16.08.2015
comment
Это, вероятно, станет слишком сложным для отладки в вопросе SO. Пожалуйста, откройте для этого проблему Github и включите в нее воспроизводящийся случай. Кроме того, перезапустите stack exec -- ghc --version, приведенный выше вывод не содержит версии GHC.   -  person Michael Snoyman    schedule 16.08.2015
comment
Создайте задачу на Github: github.com/commercialhaskell/stack/issues/819   -  person Bet    schedule 19.08.2015
comment
Спасибо, буду следить там   -  person Michael Snoyman    schedule 19.08.2015
comment
Другим возможным решением может быть stackoverflow.com/a/41588628/562583.   -  person Turion    schedule 27.09.2018
comment
С последней версией стека это не актуально.   -  person Bet    schedule 29.09.2018