Bạn sử dụng chức năng texImage2D
. Bạn sẽ gọi nó như thế này:
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)
Lưu ý rằng Juicy không luôn trả lại hình ảnh RGBA. Bạn phải xử lý mỗi sự biến đổi hình ảnh khác nhau:
ImageY8, ImageYA8, ImageRGB8, ImageRGBA8, ImageYCrCb8
Ngoài ra, trước khi lệnh này, bạn phải có ràng buộc một đối tượng kết cấu để lưu trữ các dữ liệu kết cấu trong
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
BTW, nhiều. các mục nhập đó được thêm tự động khi bạn nhập Graphics.Rendering.OpenGL
; bạn không phải nhập từng điều riêng lẻ nếu bạn không muốn.
Lưu ý rằng đây là một phần những gì JuicyPixels-Repa hữu ích, nhưng cần cập nhật cho Repa-3.0 (GHC 7.4 trở lên). –
Rất tiếc. Tôi quên tôi đã làm một số công việc để cập nhật JP-repa cho repa mới. Yay. –