We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im trying to mix images on a texture using tint (as i would sending it directly to image) but it doesnt seem to be working. Can anyone explain to me why? Do i need to render the mix before applying them to the texture? if so how?
What i currently have
PImage img1, img2;
int alpha = 0;
boolean up = true;
void setup() {
size(640, 360, P2D);
img1 = loadImage("layer1.jpg");
img2 = loadImage("layer2.jpg");
}
void draw() {
background(0);
if (up == true && alpha < 255)
{
alpha++;
} else up = false;
if (up == false && alpha > 0)
{
alpha--;
} else up = true;
beginShape();
tint(255, 255);
texture(img1);
tint(255, alpha);
texture(img2);
vertex(10, 10, 0, 0);
vertex(width-10, 10, img1.width, 0);
vertex(width-10, height-10, img1.width, img1.height);
vertex(10, height-10, 0, img1.height);
endShape();
}
Answers
In terms of performance it would make a lot more sense to pre-render the combined image once in setup ;)
Edit: sorry I see that you're adjusting the opacity of the second image dynamically; so the above doesn't apply.
Looking at the reference for texture it makes no mention that textures can be combined, so I suspect you need to combine the images before applying the texture...
Thanks for the response blindfish. Thats the problem im struggling with. I can easily render the blend to image functions. But how do i get that composition onto a texture instead of the main raster?
this is like calling fill() twice before drawing a rectangle, only the last is going to make a difference.
you probably need to set the first texture, apply to the shape, set the second texture, apply to the shape again, something like
(not tested, and would obviously benefit from a method.)
Ok, so that seemed to work, am still pretty stuck trying to get them onto the same
primative though. had another go with trying to iterate thought the pixles of each and individually procesing them. Although i seem to have got stuck. Any idea why this isnt working?
Silly mistake, forgot to update the second rgb floats to img2 (copy paste error) Also needed to pass the combined images to another pi image for output.
Heres the working code for others refernce