We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › blend coordinates
Page Index Toggle Pages: 1
blend coordinates (Read 243 times)
blend coordinates
Jan 25th, 2009, 12:31am
 
Hey folks.  I'm trying to use blend() to display images with additive color, but am having trouble grok'ing the coordinate system.  I'm sure I'm doing something silly.

For example:

Code:
import processing.opengl.*;
import javax.media.opengl.*;
PImage img;

void setup() {
size(600,600, OPENGL);

img = createImage(10, 10, RGB);

float md = 0.5*sqrt(sq(img.width/2)+sq(img.height/2));
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++) {
float d = sqrt(sq(x-img.width/2)+sq(y-img.height/2));
img.set(x ,y , color(0, 128-128*d/md, 0));
}
}

}

void draw()
{
background(0);
// image "A" -- smaller
blend(img,
0, 0,
img.width, img.height,
0, 0, //x & y of new image
50, 50, //width & height of new image
BLEND);

// image "B" - larger
blend(img,
0, 0,
img.width, img.height,
0, 0, //x & y of new image
100, 100, //width & height of new image
BLEND);
}


Image "A" appears about where I expect -- upper left corner at (0, 0) with bottom right at (50, 50).

Image "B" however, appears with the y coordinate flipped:  the upper left corner is at (0, 500) (i.e., height-100) with the bottom at (100, 600).

If I use Image(), the image is placed where I expect, but if multiple images appear on top of one another, there's no visual indication.  

Forgive the ignorance, and thanks for the help!

jjguy
Re: blend coordinates
Reply #1 - Jan 25th, 2009, 10:47am
 
I see two problems...

First, the set of chosen colors and/or of blend mode makes the blend ineffective: the bigger picture masks the smaller. You can see it if you invert the two images' drawing order.

Second, you can see it only in mode JAVA2D or P2D, which display the sketch as expected.
In the mode you chose, OPENGL, indeed the second image appears at the bottom! Which is quite unexpected.
Either it is a strange property of the OPENGL mode (which I don't really know, never use), but I doubt it, or it is a bug.

I suggest you go to Contribute page and fill in a bug in the bugs database.
I didn't saw that in previous bugs on OpenGL, only the bug 942 seems vaguely related (but questions performance, not result).

I can reproduce the issue with Processing 1.0.1 on WinXP Pro SP3 and old graphics card. Also with Processing 0154 and 0135 (the later shows a very pixillated image!).
Re: blend coordinates
Reply #2 - Jan 25th, 2009, 3:37pm
 
PhiLho, thanks so much!   I am always reluctant to consider unusual behaviors I discover a "bug" -- it is almost always imperfect understanding of the framework or API.

A few comments:

First, apologies on the blending mode.  It went to BLEND from ADD in my own troubleshooting and apparently didn't make it back when I simplified for the post.  It seems irrelevant.

Second, I changed my sketch to P3D and everything works as expected.

Third, I'm on OS X -10.5.6 with Processing 0154 -- so the behavior, if indeed a bug, is not limited to Windows.

I'll submit a bug so it's recorded and let someone on the dev team investigate.  Thanks again!

jjguy

Page Index Toggle Pages: 1