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 4531594
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T13:55:27+00:00 2026-05-21T13:55:27+00:00

I’m stuck trying to get multiple textures working in OpenGL using Haskell. I’ve been

  • 0

I’m stuck trying to get multiple textures working in OpenGL using Haskell. I’ve been following the NeHe tuts and some various other OpenGL resources online, but the combination of slightly different calls and my newbness has caused a roadblock.

To be specific I want to render two cubes, each with a different texture (same texture for all 6 faces for the time being). Rendering one cube, with a texture is fine. Rendering multiple cubes of the same texture works fine as well. But I’ve not been able to figure out how to change textures for the two cubes

If I’m not mistaken the call to change textures is:

textureBinding $ Texture2D $= Just *mytexture*

where mytexture is supposed to be some form of textureID (a TextureObject). What the heck goes into the mytexture spot? This should be really easy but I’ve spent the better part of 2 days trying to figure this out to no avail. Any help is appreciated.

Main:

    -- imports --
import Graphics.Rendering.OpenGL
import Graphics.UI.GLUT
import Data.IORef
import Display
import Bindings
import Control.Monad
import Textures

-- main --
main = do
    (program, _) <- getArgsAndInitialize         -- convenience, return program name and non-GLUT commands
    initialDisplayMode $= [DoubleBuffered, WithDepthBuffer] -- inital display mode
    initialWindowSize $= Size 600 600
    createWindow "OpenGL Basics"
    reshapeCallback $= Just reshape
    angle <- newIORef (0.1::GLfloat) -- linked to angle of rotation (speed?)
    delta <- newIORef (0.1::GLfloat)
    position <- newIORef (0.0::GLfloat, 0.0) -- position, pass to display
    texture Texture2D $= Enabled
    tex <- getAndCreateTextures ["goldblock","pumpkintop"]
    keyboardMouseCallback $= Just (keyboardMouse delta position) --require keys, delta, and position
    idleCallback $= Just (idle angle delta) --ref idle angle and delta
    displayCallback $= (display angle position tex) --ref display angle and delta
    cullFace $= Just Front 
    mainLoop    -- runs forever until a hard exit is called

In Main I call getAndCreateTextures (borrowed from the net), which returns a list of texture objects.

Display (for rendering):

    -- display (main) --
display angle position tex = do
    clear [ColorBuffer, DepthBuffer]
    loadIdentity --modelview
    shadeModel $= Smooth
    (x,z) <- get position --get current position from init or keys
    translate $ Vector3 x 0 z -- move to the position before drawing stuff
--    DO STUFF HERE
--    texture $ Texture2D $= Just wtfgoeshere
    preservingMatrix $ do
        a <- get angle
        rotate a $ Vector3 (1::GLfloat) 0 0
--        rotate a $ Vector3 0 0 (1::GLfloat)
        rotate a $ Vector3 0 (1::GLfloat) 0
--        scale 0.7 0.7 (0.7::GLfloat)
--        color $ Color3 (0.5::GLfloat) (0.1::GLfloat) (0.1::GLfloat)
        cubeTexture (0.1::GLfloat)
    swapBuffers

--idle (main)
idle angle delta = do
    a <- get angle      -- get existing angle
    d <- get delta      -- get delta
    angle $= a + d      -- new angle is old angle plus plus delta
    postRedisplay Nothing
  • 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-05-21T13:55:27+00:00Added an answer on May 21, 2026 at 1:55 pm

    getAndCreateTextures is almost certainly doing what you need. The function of that name I found on the web has type IO [Maybe TextureObject], those are the TextureObject values you need. So you could do,

    [gtex, ptex] <- getAndCreateTextures ["goldblock","pumpkintop"]
    textureBinding Texture2D $= gtex
    

    for example.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I want to count how many characters a certain string has in PHP, but

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.