Texture mapping: What on earth am I doing wrong?!

I have been trying to make a program based off of the 3D lab sample project, but with just a single rotating cube. But no matter what I try, I cannot seem to get the texture to show up on the cube. It just renders as a solid color.

The relevant code:

self.cube = mesh()
    
    self.cube.texture = readImage("Planet Cute:Dirt Block")
    self.cube.vertices = cubeverts
    self.cube.texCoord = cubetexCoords
    
    
    self.cube:setColors(255,255,255,255)

I can’t for the life of me figure out what I am doing wrong here. It seems to match the sample code…

Here is the code for the entire program:

Block = class()

function Block:init()
    -- you can accept and set parameters here
    local vertices = {
      vec3(-0.5, -0.5,  0.5), -- Left  bottom front
      vec3( 0.5, -0.5,  0.5), -- Right bottom front
      vec3( 0.5,  0.5,  0.5), -- Right top    front
      vec3(-0.5,  0.5,  0.5), -- Left  top    front
      vec3(-0.5, -0.5, -0.5), -- Left  bottom back
      vec3( 0.5, -0.5, -0.5), -- Right bottom back
      vec3( 0.5,  0.5, -0.5), -- Right top    back
      vec3(-0.5,  0.5, -0.5), -- Left  top    back
    }
    
    local cubeverts = {
      -- Front
      vertices[1], vertices[2], vertices[3],
      vertices[1], vertices[3], vertices[4],
      -- Right
      vertices[2], vertices[6], vertices[7],
      vertices[2], vertices[7], vertices[3],
      -- Back
      vertices[6], vertices[5], vertices[8],
      vertices[6], vertices[8], vertices[7],
      -- Left
      vertices[5], vertices[1], vertices[4],
      vertices[5], vertices[4], vertices[8],
      -- Top
      vertices[4], vertices[3], vertices[7],
      vertices[4], vertices[7], vertices[8],
      -- Bottom
      vertices[5], vertices[6], vertices[2],
      vertices[5], vertices[2], vertices[1],
    }
        -- all the unique texture positions needed
    local texvertices = { vec2(0.03,0.24),
                          vec2(0.97,0.24),
                          vec2(0.03,0.69),
                          vec2(0.97,0.69) }
                
    -- apply the texture coordinates to each triangle
    local cubetexCoords = {
      -- Front
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
      -- Right
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
      -- Back
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
      -- Left
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
      -- Top
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
      -- Bottom
      texvertices[1], texvertices[2], texvertices[4],
      texvertices[1], texvertices[4], texvertices[3],
    }
    

    self.cube = mesh()
    
    self.cube.texture = "Planet Cute:Dirt Block"
    self.cube.vertices = cubeverts
    self.cube.texCoord = cubetexCoords
    
    
    self.cube:setColors(255,255,255,255)
    self.scale={100,100,100}

end

function Block:draw()
    -- Codea does not automatically call this method
    pushMatrix()
    pushStyle()
    scale(self.scale[1],
            self.scale[2],
            self.scale[3])
    self.cube:draw()
    popStyle()
    popMatrix()
    
end

function Block:touched(touch)
    -- Codea does not automatically call this method
end

function setup()
    
    b = Block()
    t=0
    
    
    
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)
    perspective()
    camera(0,300,150, 0,0,0, 0,1,0)
    
    rotate(50*t)
    b:draw()
    
    --sprite("Planet Cute:Dirt Block",50,50,200,200)
    

    t = t + DeltaTime
    
end


@mooglinux - are you ready to kick yourself?

self.cube.texCoords = cubetexCoords -- texCoords is plural

Uuuuuggggghhhhhhhhh go figure…

kicks self profusely

Ouch! That’s why I like programming with static type checking better :stuck_out_tongue_winking_eye:

moodlinux you are pretty supple!