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 & HelpPrograms › Using blend() multiply on rotated images
Page Index Toggle Pages: 1
Using blend() multiply on rotated images (Read 789 times)
Using blend() multiply on rotated images
Feb 3rd, 2008, 8:14pm
 
This is my first post on this forum and sure not the last one. I hope to contribute to the forum soon.

I got a question about blend() in combination with rotated images. I wrote this script but i am yet unable to multiply different images rotated and stacked upon each other. Also i'd like to multiply these images with the background, and at a later time with other circles on top.

Is it even possible to rotate a blend ?
And is this the right way to accomplish this ?

Thanks in advance.

Code:

PImage b;

// Radius/Shape nitialization
float xCenter = 350;
float yCenter = 350;
float radius = 100;

float xOffset = -20;
float yOffset = -60;

float nrSteps = 10;
float degreeValue = 0;

float circleX;
float circleY;


void setup() {
size(700, 700);
background(255);
b = loadImage("http://www.muhneer.nl/files/preview/fff_pic.jpg");
noLoop();
}

void draw() {
println(nrSteps);
drawCircle();
}

void drawCircle() {
for (int i = 1; i <= nrSteps; i = i+1) {
degreeValue = 360/nrSteps;
circleX = round(xCenter + (cos(radians(degreeValue*i))*radius));
circleY = round(yCenter + (sin(radians(degreeValue*i))*radius));
item(circleX, circleY, degreeValue*i);
}
}

void item(float x, float y, float angle) {
pushMatrix();
translate(x, y);
rotate(radians(angle));
//b.blend(b, 0, 0, 76, 76, 10, 10, 76, 76, MULTIPLY);
image(b, xOffset, yOffset);
//rect(0, 0, 150, 120);
//blend(b, 0, 0, 150, 120, 10, 10, 150, 120, MULTIPLY);
point(0, 0);
popMatrix();
}
Re: Using blend() multiply on rotated images
Reply #1 - Feb 6th, 2008, 11:36pm
 
I found a solution in using OpenGL, this has a more advanced blend function. As far as i can see now. Dont know if this is the best method.

Code:

import processing.opengl.*;
import javax.media.opengl.*;

PGraphicsOpenGL pgl;
GL gl;

float rY;
float rZ;
float rX;

PImage a;
PImage b;

void setup() {
size(500, 500, OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
background(255);

b = loadImage("http://www.muhneer.nl/files/preview/COLIN_SMALL.gif");
a = loadImage("http://www.muhneer.nl/files/preview/fff_pic.jpg");

pgl = (PGraphicsOpenGL) g;
gl = pgl.gl;

// Begin opengl blending
pgl.beginGL();
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_DST_COLOR, GL.GL_ZERO); // Activate the multiply effect
pgl.endGL();

translate(240, 240);
image(b, 0, 0);
rotateZ(radians(20));
image(b, 0, 0);

}
Re: Using blend() multiply on rotated images
Reply #2 - Mar 8th, 2009, 9:50pm
 
i've used this, and it works well

it get's rid of the black line and it does the same thing as filter(MULTIPLY), with the images overlapping.

Code:

//--------------------------------------------------------------
//opengl
//--------------------------------------------------------------
pgl.beginGL();
gl.glEnable(GL.GL_TEXTURE_2D);

//blending function
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);

// Texture
tex.bind();
tex.enable();

//image coordinates
gl.glBegin(GL.GL_QUADS);
gl.glNormal3f(0.0f, 0.0f, 1.0f);
gl.glTexCoord2f(0, 0); gl.glVertex2f(0, bild[w].height);
gl.glTexCoord2f(1, 0); gl.glVertex2f(bild[w].width, bild[w].height);
gl.glTexCoord2f(1, 1); gl.glVertex2f(bild[w].width, 0);
gl.glTexCoord2f(0, 1); gl.glVertex2f(0, 0);
gl.glEnd();

tex.disable();
gl.glDisable( GL.GL_BLEND );

pgl.endGL();


however, i want to output graphics with an alpha channel, and it seems that PGraphics http://processing.org/reference/createGraphics_.html doesn't work with openGL "It's not possible to use createGraphics() with OPENGL..."

is there another solution to have a "multiply" effect on rotated images, that doesn't involve openGL

any help would be much appreciated.

thanks.
Ken
Page Index Toggle Pages: 1