Problem with loaded images vs. images made within my program

So here’s the deal–I’m working on a pseudo-3D ray caster (in the spirit of games like Wolfenstein 3D) and I’ve run into a problem with texturing. My texturing process currently involves splitting a single (usually 16 x 16) texture image into individual columns of pixels, i.e. if my texture is 16 x 16 I create 16 images from it, each one representing a single column of the original texture image. I originally did this using image.copy() in a process that looks roughly like this:

for x = 1, width do column[x] = texture:copy(x, 1, 1, texture.height) end

But this didn’t work–not with textures loaded from sprite packs, nor with textures made within Codea. The result looked like:

I’m not sure why. I probably should’ve posted about my issue here at this point–if you see a really silly mistake that will make the rest of post pointless please point it out–but instead I made a manual workaround that looks like this:

for x = 1, width do column[x] = getColumn(texture, x) end function getColumn(img, x) columnImg = image(1, img.height) for y = 1, img.height do columnImg:set(1, y, img:get(x, y)) end return columnImg end

This solution works, but only with images that are made within my program, such as images that I make in the Spritely example and then copy into my program. Here is my ray caster running with a red brick wall that I made in Spritely:

and here is my ray caster running with a gray brick wall that I made in Sprite Something (however, the same problem occurs if the texture is from the sprite packs, downloaded from the internet, etc.):

Interestingly, the bottom fourth of the texture in the picture kind of resembles the actual texture, while the rest of it is random and actually changes each time I run the program.

Some things to note: the texture images themselves always look normal if I simply draw them using sprite(). However, only images that have been made within my program look normal after splitting them. I’ve tried various texture sizes and I’ve tried textures from several different places with no luck.

So…any ideas?


I’ve investigated some more and found that image.copy() works with certain images (such as “Planet Cute:Character Boy”) but not others (such as “Small World:Bunny Skull”). Images that image.copy() works with also work with my workaround, i.e. “Planet Cute:Character Boy” works as a texture but “Small World:Bunny Skull” does not.


Ok, I’ve figured it out. The problem is with retina display graphics (I have a 3rd-gen iPad, if that matters). Images that are imported with the “Retina Display” setting enabled (and for me it’s enabled by default) do not–at least the way I was doing it–work with image.copy() (nor do they work with my workaround because it probably uses a method similar to image.copy()). I suspect it has to do with the adjustments that were made to accommodate the retina display detailed here:

There is probably a way to use image.copy() that takes into account the retina display–and please tell me if there is–but I don’t need it for this and I’ve got everything working the way I want.

It sounds like there is a bug in image.copy — I’ll look into it shortly. Could you put an issue on the issue tracker?

Ok, thanks, I’ve done so.

For now you might want to try the image.rawCopy function. I’m looking into the .copy bug, however.