您使用该texImage2D
功能。你会像这样调用它:
import Data.Vector.Storable (unsafeWith)
import Graphics.Rendering.OpenGL.GL.Texturing.Specification (texImage2D, Level, Border, TextureSize2D(..))
import Graphics.Rendering.OpenGL.GL.PixelRectangles.ColorTable (Proxy(..), PixelInternalFormat(..))
import Graphics.Rendering.OpenGL.GL.PixelRectangles.Rasterization (PixelData(..))
-- ...
(ImageRGBA8 (Image width height dat)) ->
-- Access the data vector pointer
unsafeWith dat $ \ptr ->
-- Generate the texture
texImage2D
-- No cube map
Nothing
-- No proxy
NoProxy
-- No mipmaps
0
-- Internal storage format: use R8G8B8A8 as internal storage
RGBA8
-- Size of the image
(TextureSize2D width height)
-- No borders
0
-- The pixel data: the vector contains Bytes, in RGBA order
(PixelData RGBA UnsignedByte ptr)
请注意,Juicy 并不总是返回 RGBA 图像。您必须处理每个不同的图像变体:
ImageY8, ImageYA8, ImageRGB8, ImageRGBA8, ImageYCrCb8
另外,在这个命令之前,你必须绑定一个纹理对象来存储纹理数据。
import Data.ObjectName (genObjectNames)
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (textureBinding)
import Graphics.Rendering.OpenGL.GL.Texturing.Specification (TextureTarget(..))
-- ...
-- Generate 1 texture object
[texObject] <- genObjectNames 1
-- Make it the "currently bound 2D texture"
textureBinding Texture2D $= Just texObject
顺便说一句,其中许多导入是在您导入时自动添加的Graphics.Rendering.OpenGL
;如果您不想要,您不必单独导入每个东西。