Codea 4.x Mesh color bug

-- Modern
function setup()
    testMesh = mesh()
    testMesh:addRect(0,0,300,300)
    c1,c2= color(0, 255, 0), color(255)
    testMesh.colors = {c1,c1,c2,c2}
end

function draw() 
    background(0)
    matrix.translate(WIDTH/2,HEIGHT/2)
    testMesh:draw()
end

Bug: it seems like some of the color channels for mesh are mixed up or inverted? This rect should be green on the top but it’s magenta instead.

1 Like

Here’s a triangle version showing the problem. The colors should be red, green, and blue.

viewer.mode=FULLSCREEN

function setup()
    w,h=WIDTH,HEIGHT
    m=mesh()
    m.vertices={vec2(100,h/2-50),vec2(w-100,h/2-50),vec2(w/2,h/2+300)}
    m.colors={color(255,0,0),color(0,255,0),color(0,0,255)}
end

function draw()
    background(0)
    m:draw()  
end


With above code this is my triangle.


thought I’d check primarily and secondary colors, here’s the results…

Thanks for the test examples. I probably messed up the byte interpretation of the colours array somehow (like the vertices actually expect 4 bytes per colour, but instead get 16 or so, which messes them up)

I think I’ve got it. The colour bits were in reversed order!

1 Like

@John Glad that’s fixed. I guess that’s why white (255,255,255,255) was correct and (255,0,0,255) was red and (255,0,0,0) was black.

@John @sim - sent in a report about bubbles demo. Think it may be down to trying to print out touch variables. Tried to print out touch type using print(type(touch)) and it crashed after that.

Attached two error images with printing out touch variables and touch type.