Codea 1.5 Beta

.@Fred is that in the code editor? I’m a bit confused as to how you trigger that behaviour.

.@Simeon, yes, in the code editor. I had selected text, and was halfway through pressing copy, but my finger slipped off the copy button.

That’s odd — I can’t recreate that. Maybe I’m not doing it right?

  • Select text
  • Press “Copy”
  • Drag my finger off the “Copy” button and then release it

.@Fred: awesome! I was planning on looking into doing the same thing, but you beat me to it! Have you considered starting your own GitHub repo and adding this to it? If not, would you mind if I add it to my CodeaMisc repo?

.@Simeon: Thanks for the quick turnaround on that fix!

.@Simeon, hmmm, that’s odd. It doesn’t happen in the new beta you just pushed out… Call it fixed or I need some sleep.

@toadkick, hehe I was sure you had all done it already… :slight_smile: yes good point - I’ll put it up on gitHub, then we can use your bootstrap trick to get it easily… :slight_smile: feel free to fork and improve my kludge code.

Code hosted at: https://github.com/fredbogg/getGit

.@Simeon: With the latest build, whenever I run, and exit back to the code editor, it’s always starting the code editor in the Main tab, instead of the tab I was in before I ran the program. I think this is new, because I don’t remember being annoyed by this before. I suspect perhaps that the tab reloading upon ending program execution logic is the culprit.

Nice that you added the pause button to the shader. Seems like the bug with using two textures in a shader is still there though.

when I in lua writes

    m = mesh()
    m.texture = CAMERA
    m.texture2 = i -- which is an image
    m.shader = shader("Documents:FG")

with a shader that should mix the textures

...
void main()
{
    lowp vec4 col2 = texture2D( texture2, vTexCoord)*.5;
    col2 = col2 + texture2D( texture, vTexCoord )*.5;
    //Set the output color to the texture color
    gl_FragColor = col2;
}

it seems to just assign texture but ignore texture2. have seen some weird results. anyone tried something similar?

@Simeon - no joy. No error, but no sprite In the spritepack either. Does it work for you?

(your code was the combo I tried first, before going to the setContext dance - tried it again, just to be sure…)

So, if I do “c = image(CAMERA)”, when I print c it’s nil - even if/while I am using sprite to display CAMERA (ie. I’ve waited for the camera to initialize and it’s returning data).

Bortels, I tried here and it seems to work fine if I use the camera in the draw loop. Might be more logical with an api with a callback when the picture is taken?

I used this code

-- Cam

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness
    strokeWidth(5)

    -- Do your drawing here
    sprite(CAMERA)

end

function touched(touch)
    if touch.state == BEGAN then
        i = image(CAMERA)
        print(i)
        saveImage("Documents:aaa",i)
    end
end

ps. have you checked that you have a camera on your device :wink: .ds

@tnlogy What happens if you put the m.texture2 = i line after the assignment of the shader? Maybe the mesh has to know what shader it’ll use in order to assign its stuff.

(I’m planning on trying some experiments along these lines later.)

@Bortels. Hmm, I’ve gotten the camera to save to an image. I’ll have a look in a bit (iPad has just decided to update to 6.0.1 and I don’t want to interrupt it while it’s busy).

Andrew, I’ve tried that also, but to no success. Tell me if you get it working :slight_smile:

@Bortels I’ve just checked my code. All I have is img = image(CAMERA) in my code.

Okey-dokey. I’m getting very strange behaviour with images. I tried putting an image in my shader. So it’s the basic shader with an extra image:

uniform lowp sampler2D mask;

Wasn’t sure which one to put it in so I put it in both the Vertex and Fragment shaders. To test it, I had the Fragment shader render its colour from the mask, not the main texture.

Now comes with weird bit. I managed to assign an image to this texture. But when I tried varying the image, the data that the shader got varied in an unexpected way. Basically, what happened was that once I’d managed to get an image into that segment of memory then the shader always pointed to that bit of memory and I couldn’t change it. If I changed the image in the code (I was writing to it via setContext in the setup function) then the mask image changed even if the code was assigning a different image to the mask! So m.mask = anothermask had absolutely no effect.

.@tnlogy you are setting the texture2 variable on your mesh, it needs to be set on your shader object. So try the following:

m = mesh()
m.texture = myTexture1
m.shader = shader("Documents:ImageBlend")
m.shader.texture2 = myTexture2

```


Using your fragment shader code then produces the desired result, for me.

Edit: This is a bit confusing, but there are special variables in shaders that are automatically propagated from a mesh object: texture, texCoord, color, position, and so on. A shader will pick these up automatically from any mesh it's connected to. 

You don't have to use these auto-connections, because you can assign directly to the shader's uniform to overwrite them, e.g:

m.shader.texture = aTexture

```


This will actually stop mesh.texture from being used in your shader texture.

.@tnlogy thanks for reporting the reloading tab issue, I’ve fixed it.

@Simeon Brilliant - thanks for the explanation there on shader variables.

Wow! Just came back from vacations with no wifi… and find 75 posts and 2 version 1.5…! It’s the first time i go in this beta process, so please excuse my basic question: do i have to backup my current codea version and projects before i install the beta? Or will it come like a second app that does not mess with my current project?

It will replace your current Codea, but projects should be preserved.

Having said that - it’s a beta. Backing up your codea projects is never a bad idea.