We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi there, I am having trouble combining two codes I have. The first one I want to have as a background while the second one (the text) should be on top of it.
I have tried combining them but of course it's not easy at it seem for a beginner like me, they either won't work at all or they don't work like the should.
This is not the only code that I am having trouble doing this with so I feel like I might be missing something. Any help with the code or just pointing me to the right direction would be greatly appreciated!
Code I want to stay in the back but still be interactive:
PShader sh;
String uid;
void setup() {
PImage img = loadImage("test.jpg");
size(img.width,img.height,P2D);
background(0);
// load and compile shader
sh = loadShader("lens.glsl");
// upload texture to graphics card
sh.set("texture",img);
}
void draw() {
// normalize mouse position
float inpx = mouseX/(float)width;
float inpy = mouseY/(float)height;
// set shader variable
sh.set("inp",inpx,inpy);
// run shader
shader(sh);
// fill whole window
rect(0,0,width,height);
}
And the text code:
import geomerative.*;
import ddf.minim.*;
Minim mySound; //CREATE A NEW SOUND OBJECT
AudioInput in;
RFont font;
String myText = "TEST";
void setup() {
size(1500, 400);
background(255);
smooth();
RG.init(this);
font = new RFont("FreeSans.ttf", 100, CENTER);
mySound = new Minim(this);
in = mySound.getLineIn(Minim.STEREO,512);
}
void draw() {
background(255);
strokeWeight(2);
stroke(255, 0, 0);
noFill();
translate(width/2, height/1.5);
float soundLevel = in.mix.level(); //GET OUR AUDIO IN LEVEL
RCommand.setSegmentLength(soundLevel*9000);
RCommand.setSegmentator(RCommand.UNIFORMLENGTH);
RGroup myGoup = font.toGroup(myText);
RPoint[] myPoints = myGoup.getPoints();
beginShape(QUAD_STRIP);
for (int i=0; i<myPoints.length; i++) {
vertex(myPoints[i].x, myPoints[i].y);
}
endShape();
}
Answers
(Please post the shader code also. It may be possible to code a high performance solution directly into the shader.)
Potentially important - https://forum.processing.org/two/discussion/21439/offering-money-for-help-with-glsl-fragment-shader#latest
Oh yeah of course!
Here it is:
Setting size as "img.width" and "img.height" rather than hardcoded constants gave me an error, just change size(1024,768, to the reolution of your picture.
Naming the sampler 'texture' gave me black screen so just changed it to 'u_texture' "did nothing else to the shader just add u_ in your shader at line 2,14, and 17
leave texture2D as is..
Thank you! Works great