initialize :: IO Descriptor
initialize = do

    -- meshes
    let vertices =
            -- vertex attribute format : x, y, z, r, g, b, a
            [
              (-0.90), (-0.90), 0.0, 1.0, 0.0, 0.0, 1.0
            ,    0.90, (-0.90), 0.0, 0.0, 1.0, 0.0, 1.0
            ,    0.90,    0.90, 0.0, 1.0, 1.0, 1.0, 1.0
            , (-0.90),    0.90, 0.0, 0.0, 0.0, 1.0, 1.0
            ] :: [GLfloat]
        numPositionElements = 3
        numColorElements = 4
        offsetPosition = 0
        offsetColor = offsetPosition + numPositionElements
        sizeElement = sizeOf (head vertices)
        sizeVertex = fromIntegral (sizeElement * (numPositionElements + numColorElements))

    let indices =
            [
              0, 1, 2
            , 2, 3, 0
            ] :: [GLushort]


    vertexBuffer <- initializeBuffer ArrayBuffer vertices


    attributes <- genObjectName
    bindVertexArrayObject $= Just attributes
    bindBuffer ArrayBuffer $= Just vertexBuffer

    let vPosition = AttribLocation 0
        vColor = AttribLocation 1

    vertexAttribPointer vPosition $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numPositionElements) Float sizeVertex (bufferOffset (offsetPosition * sizeElement)))
    vertexAttribPointer vColor $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numColorElements) Float sizeVertex (bufferOffset (offsetColor * sizeElement)))

    vertexAttribArray vPosition $= Enabled
    vertexAttribArray vColor $= Enabled

    bindBuffer ArrayBuffer $= Nothing
    bindVertexArrayObject $= Nothing


    indexBuffer <- initializeBuffer ElementArrayBuffer indices


    program <- LS.loadShaders
        [ LS.ShaderInfo VertexShader (LS.FileSource "rectangle.vert")
        , LS.ShaderInfo FragmentShader (LS.FileSource "rectangle.frag")
        ]
    currentProgram $= Just program


    checkError "initialize"

    return $ Descriptor vertexBuffer attributes indexBuffer program 0 (fromIntegral $ length indices)


-- | Terminates OpenGL objects.
initialize :: IO Descriptor
initialize = do

    -- meshes
    let vertices =
            -- vertex attribute format : x, y, z, r, g, b, a
            [
              (-0.90), (-0.90), 0.0, 1.0, 0.0, 0.0, 1.0
            ,    0.90, (-0.90), 0.0, 0.0, 1.0, 0.0, 1.0
            ,    0.90,    0.90, 0.0, 1.0, 1.0, 1.0, 1.0
            , (-0.90),    0.90, 0.0, 0.0, 0.0, 1.0, 1.0
            ] :: [GLfloat]
        numPositionElements = 3
        numColorElements = 4
        offsetPosition = 0
        offsetColor = offsetPosition + numPositionElements
        sizeElement = sizeOf (head vertices)
        sizeVertex = fromIntegral (sizeElement * (numPositionElements + numColorElements))

    let indices =
            [
              0, 1, 2
            , 2, 3, 0
            ] :: [GLushort]


    vertexBuffer <- initializeBuffer ArrayBuffer vertices


    attributes <- genObjectName
    bindVertexArrayObject $= Just attributes
    bindBuffer ArrayBuffer $= Just vertexBuffer

    let vPosition = AttribLocation 0
        vColor = AttribLocation 1

    vertexAttribPointer vPosition $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numPositionElements) Float sizeVertex (bufferOffset (offsetPosition * sizeElement)))
    vertexAttribPointer vColor $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numColorElements) Float sizeVertex (bufferOffset (offsetColor * sizeElement)))

    vertexAttribArray vPosition $= Enabled
    vertexAttribArray vColor $= Enabled

    bindBuffer ArrayBuffer $= Nothing
    bindVertexArrayObject $= Nothing


    indexBuffer <- initializeBuffer ElementArrayBuffer indices


    program <- LS.loadShaders
        [ LS.ShaderInfo VertexShader (LS.FileSource "rectangle.vert")
        , LS.ShaderInfo FragmentShader (LS.FileSource "rectangle.frag")
        ]
    currentProgram $= Just program


    checkError "initialize"

    return $ Descriptor vertexBuffer attributes indexBuffer program 0 (fromIntegral $ length indices)


-- | Terminates OpenGL objects.
initialize = do

    -- meshes
    let vertices =
            -- vertex attribute format : x, y, z, r, g, b, a
            [
              (-0.90), (-0.90), 0.0, 1.0, 0.0, 0.0, 1.0
            ,    0.90, (-0.90), 0.0, 0.0, 1.0, 0.0, 1.0
            ,    0.90,    0.90, 0.0, 1.0, 1.0, 1.0, 1.0
            , (-0.90),    0.90, 0.0, 0.0, 0.0, 1.0, 1.0
            ] :: [GLfloat]
        numPositionElements = 3
        numColorElements = 4
        offsetPosition = 0
        offsetColor = offsetPosition + numPositionElements
        sizeElement = sizeOf (head vertices)
        sizeVertex = fromIntegral (sizeElement * (numPositionElements + numColorElements))

    let indices =
            [
              0, 1, 2
            , 2, 3, 0
            ] :: [GLushort]


    vertexBuffer <- initializeBuffer ArrayBuffer vertices


    attributes <- genObjectName
    bindVertexArrayObject $= Just attributes
    bindBuffer ArrayBuffer $= Just vertexBuffer

    let vPosition = AttribLocation 0
        vColor = AttribLocation 1

    vertexAttribPointer vPosition $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numPositionElements) Float sizeVertex (bufferOffset (offsetPosition * sizeElement)))
    vertexAttribPointer vColor $=
        (ToFloat, VertexArrayDescriptor (fromIntegral numColorElements) Float sizeVertex (bufferOffset (offsetColor * sizeElement)))

    vertexAttribArray vPosition $= Enabled
    vertexAttribArray vColor $= Enabled

    bindBuffer ArrayBuffer $= Nothing
    bindVertexArrayObject $= Nothing


    indexBuffer <- initializeBuffer ElementArrayBuffer indices


    program <- LS.loadShaders
        [ LS.ShaderInfo VertexShader (LS.FileSource "rectangle.vert")
        , LS.ShaderInfo FragmentShader (LS.FileSource "rectangle.frag")
        ]
    currentProgram $= Just program


    checkError "initialize"

    return $ Descriptor vertexBuffer attributes indexBuffer program 0 (fromIntegral $ length indices)


-- | Terminates OpenGL objects.