texFromImage img = do
    (t:_) <- genObjectNames 1
    textureBinding Texture2D $= Just t
    textureWrapMode Texture2D S $= (Repeated, Repeat)
    textureWrapMode Texture2D T $= (Repeated, Repeat)
    textureFilter Texture2D $= ((Nearest, Nothing), Nearest)
    let (p, _, _) = toForeignPtr img
        s@(Size w h) = size $ (extent . imgData) img    
    texImage w h p
    return (t, s)
    where
        size (_ :. h :. w :. _) = Size (fromIntegral w) (fromIntegral h)
        texImage width height ptr = withForeignPtr ptr $ \p -> texImage2D Nothing NoProxy 0 RGBA8 (TextureSize2D width height) 0 $ PixelData ABGR UnsignedByte p
texFromImage img = do
    (t:_) <- genObjectNames 1
    textureBinding Texture2D $= Just t
    textureWrapMode Texture2D S $= (Repeated, Repeat)
    textureWrapMode Texture2D T $= (Repeated, Repeat)
    textureFilter Texture2D $= ((Nearest, Nothing), Nearest)
    let (p, _, _) = toForeignPtr img
        s@(Size w h) = size $ (extent . imgData) img    
    texImage w h p
    return (t, s)
    where
        size (_ :. h :. w :. _) = Size (fromIntegral w) (fromIntegral h)
        texImage width height ptr = withForeignPtr ptr $ \p -> texImage2D Nothing NoProxy 0 RGBA8 (TextureSize2D width height) 0 $ PixelData ABGR UnsignedByte p
texFromImage img = do
    (t:_) <- genObjectNames 1
    textureBinding Texture2D $= Just t
    textureWrapMode Texture2D S $= (Repeated, Repeat)
    textureWrapMode Texture2D T $= (Repeated, Repeat)
    textureFilter Texture2D $= ((Nearest, Nothing), Nearest)
    let (p, _, _) = toForeignPtr img
        s@(Size w h) = size $ (extent . imgData) img    
    texImage w h p
    return (t, s)
    where
        size (_ :. h :. w :. _) = Size (fromIntegral w) (fromIntegral h)
        texImage width height ptr = withForeignPtr ptr $ \p -> texImage2D Nothing NoProxy 0 RGBA8 (TextureSize2D width height) 0 $ PixelData ABGR UnsignedByte p