Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902301
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:27:20+00:00 2026-06-03T09:27:20+00:00

How do I load a texture using Haskell, OpenGL and the JuicyPixels library? I

  • 0

How do I load a texture using Haskell, OpenGL and the JuicyPixels library?

I can get as far as this:

loadImage :: IO ()
loadImage = do image <- readPng "data/Picture.png"
               case image of 
                 (Left s) -> do print s
                                exitWith (ExitFailure 1)
                 (Right d) -> do case (ImageRGBA i) -> do etc...

How do I convert this to a TextureObject? I think I need to do a conversion between a Vector Word8 and PixelData (for OpenGL to recognize)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:27:21+00:00Added an answer on June 3, 2026 at 9:27 am

    You use the texImage2D function. You’d invoke it like this:

    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)
    

    Note that Juicy doesn’t always give back an RGBA image. You have to handle each of the different image variations:

    ImageY8, ImageYA8, ImageRGB8, ImageRGBA8, ImageYCrCb8
    

    Also, before this command, you have to have bound a texture object to store the texture data in.

    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, many of those imports are added automatically when you import Graphics.Rendering.OpenGL; you don’t have to import each thing individually if you don’t want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to load an image as a texture for openGL using the
I am trying to load and draw a 2d texture using OpenGL with GLFW
I'm trying to draw grayscale image in color as texture in OpenGL using two
Im using this code to load a texture: HRESULT hr = D3DXCreateTextureFromFile(d3ddev, test.bmp, &g_texture);
I'm using libpng in my OpenGL project to load texture of png file with
Basically I am trying to load the image as a texture using QPixmap: texture[T_WALL]
I'm having issues trying to get a texture loaded into VRAM. I'm using OpenGL
At this moment I use this scenario to load OpenGL texture from PNG: load
Here's the code I use to load a texture. image is a CGImageRef. After
I load my animated character with a huge texture this way: [[CCSpriteFrameCache sharedSpriteFrameCache]addSpriteFramesWithFile:@MyFile.plist]; And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.