Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Re : Movie Maker Tool

$
0
0
Does anyone know how to call the moviemaker tool function through code? I want to make a program that will automatically make .mov from an image array without having to use a GUI.

thanks!

Background shines through text?

$
0
0
Hi everyone,

I need a little help in Processing color theory and/or overlaying graphics!

In my sketch I have a half transparent text on a separat PGraphics. When I overlay this text onto an other
PGraphics with an opaque rectangle and finally overlay this PGraphics onto the main canvas, the background of the canvas shines through the text.

What I expected was that the half transparent text will be merged with the rectangle color and will get opaque and not that the opaque rectangle gets transparent with the overlayed text. It's as the text works like an alpha mask, but I don't want that.

What do I miss here? Or whats the right way to archive my expected result?

Thank you for your time!

My specs: Windows7 64bit, NVIDIA GeForce 560M, Processing 2.0b6



  1. package spheretest;
  2. import processing.core.PApplet;
  3. import processing.core.PGraphics;
  4. public class Main extends PApplet {
  5.     /**
  6.      *
  7.      */
  8.     private static final long serialVersionUID = 3655653701051264925L;
  9.     private PGraphics pg = null;
  10.     private PGraphics java2d = null;
  11.     public void setup() {
  12.         size(500, 500, P3D);
  13.         pg = createGraphics(width, height, P3D);
  14.         java2d = createGraphics(width, height, JAVA2D);
  15.        
  16.         java2d.beginDraw();
  17.         java2d.background(0, 0, 0, 0);
  18.         java2d.fill(0,0,0,150);
  19.         java2d.textSize(36);
  20.         java2d.text("Transparent Text", 50, 50);
  21.        
  22.         java2d.fill(0,0,0,100);
  23.         java2d.textSize(36);
  24.         java2d.text("Transparent Text", 50, 86);
  25.        
  26.         java2d.fill(0,0,0,50);
  27.         java2d.textSize(36);
  28.         java2d.text("Transparent Text", 50, 122);
  29.         java2d.endDraw();
  30.     }
  31.     public void draw() {
  32.        
  33.         background(255, 0, 0);
  34.         noStroke();
  35.         fill(0,255,0);
  36.         rect(50, 50, 400, 25);

  37.         pg.beginDraw();
  38.         pg.background(0, 0, 0, 0);
  39.         pg.noStroke();       
  40.         pg.fill(255);
  41.         pg.rect(0, 0, 200, 200);       
  42.         pg.image(java2d,0,0);
  43.         pg.endDraw();

  44.         image(pg, 0, 0);
  45.     }
  46.     public static void main(String args[]) {
  47.         PApplet.main(new String[] { spheretest.Main.class.getName() });
  48.     }
  49. }

Re : Processing 2.0b7 Serial.bufferUntil() not working?

$
0
0
Hi akseidel,
Thanks for the response.

I would agree with you, but I run the exact same code on Processing version 1.5.1 and it runs fine.  From this I infer that the '\n' is in fact being sent from my microcontroller.  In fact, there is a lot of handshaking communication taking place on the serial connection between Processing and the microcontroller that is all working perfectly on version 1.5.1, and not at all on 2.0b7.  You say you have been developing in OS X and Win 7, I don't suppose you have tried with a Win XP machine?

Has anyone else successfully used Serial.bufferUntil() on a Win XP machine in version 2.0b7?  Or any 2.0+ version?

Re : Wait for Arduino Before Sending Data Over Serial

$
0
0
They're stored in the serial buffer, which can store up to 64 bytes. To be on the safe side, I only send 32 bytes at a time (waiting==32). As soon as the arduino has processed those 32 bytes (which can be any of A through H, each corresponding to a direction of travel), it sends the command to resume to processing, which sends the next 32 bytes. In practice, there's no noticeable delay - the motors are in constant movement. 

COM port setup error

$
0
0
Hello All,
My Arduino is on COM4.  In Processing "println (Serial.list()[1])" prints COM4 as expected.
But  "port = new Serial(this, Serial.list()[1], 9600);" I get a ton of errors, around "error inside Serial.<init>()".  This happens if the Serial.list index is anything other than 0.  (port is defined as an instance of Serial above )
Can you help me?  I am stuck at the starting line!

Re : Processing 2.0b7 Serial.bufferUntil() not working?

$
0
0
You are right. I have not tried my current project on Win XP. I think my previous project did not look for \n. I think I was using a scheme that bracketed all of the data from the Arduino with some character. In the current project the stuff from the Adrunio is explicitly starting with \n as in Serial.print("\nMessage")  Serial.print("rest of message"). It naturally happened that way because the Ardrunio side was built first using the serial monitor to debug the Arduino side of the scheme before starting the Processing side.

attempting to compare live video to a saved picture

$
0
0
Hey guys, new to the processing world and have come to a big brick wall.  

As the titles says, I am trying to compare a live video stream to a saved picture in a data file, then display a letter character on screen.  Something like a sign language translator.  My current code outlines an object or body part. 

I know this is possible using matlab and other signal processing software but is this even possible with processing. I have searched the forum but can not find any advice.. 

I will take any advice or suggestions. Thanks in advance.


Help with Serial read

$
0
0
I'm using Arduino with Processing. So I wan't to do stuff with the Arduino on the processing program, like when it serial read such as "1" it do stuff like play a mp3 file.

Here is the code I started with, so I will when it serial read 1 it play the mp3 file:

  1. import ddf.minim.*;
  2. import processing.serial.*;

  3. Serial port;

  4. AudioPlayer PVY;
  5. Minim minim;//audio context

  6. void setup()
  7. {
  8.   size(400, 400);
  9.   minim = new Minim(this);
  10.   PVY = minim.loadFile("PVY.mp3", 2048);
  11.   PVY.play();
  12.   
  13.   port = new Serial(this, "COM3", 9600);
  14.   port.bufferUntil('\n');
  15. }

  16. void draw()
  17. {
  18.   background(255, 0, 0);
  19.   
  20. }

  21. void stop()
  22. {
  23.   PVY.close();
  24.   minim.stop();
  25.   super.stop();
  26. }

Could you grant me the access?

$
0
0
There will be a couple of Champion League and English Championship matches played tomorrow. A bunch of good ones, not to be missed! See them below: Porto vs Malaga Live Stream Arsenal vs Bayern Munchen Live Stream Barnsley vs Wolverhampton Wanderers Live Stream Birmingham City vs Sheffield Wednesday Live Stream Burnley vs Middlesbrough Live Stream Derby County vs Bolton Live Stream Hull City vs Blackburn Rovers Live Stream Ipswich Town vs Watford Live Stream Leicester City vs Charlton Athletic Live Stream Millwall vs Peterborough United Live Stream Nottingham Forest vs Huddersfield Town Live Stream Crystal Palace vs Bristol City Live Stream Porto vs Malaga Live Stream Arsenal vs Bayern Munchen Live Stream Barnsley vs Wolverhampton Wanderers Live Stream Birmingham City vs Sheffield Wednesday Live Stream Burnley vs Middlesbrough Live Stream Derby County vs Bolton Live Stream Hull City vs Blackburn Rovers Live Stream Ipswich Town vs Watford Live Stream Leicester City vs Charlton Athletic Live Stream Millwall vs Peterborough United Live Stream Nottingham Forest vs Huddersfield Town Live Stream Crystal Palace vs Bristol City Live Stream Porto vs Malaga Live Stream Arsenal vs Bayern Munchen Live Stream Barnsley vs Wolverhampton Wanderers Live Stream Birmingham City vs Sheffield Wednesday Live Stream Burnley vs Middlesbrough Live Stream Derby County vs Bolton Live Stream Hull City vs Blackburn Rovers Live Stream Ipswich Town vs Watford Live Stream Leicester City vs Charlton Athletic Live Stream Millwall vs Peterborough United Live Stream Nottingham Forest vs Huddersfield Town Live Stream Crystal Palace vs Bristol City Live Stream

How to solve the java.lang.NullPointerException?

$
0
0
When I run a program with serialEvent, the java.lang.NullPointerException occurs, but not everytime.

The messages processing given are as follows:

Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version   = RXTX-2.1-7
java.lang.NullPointerException
at processing.mode.java.runner.Runner.findException(Runner.java:682)
at processing.mode.java.runner.Runner.reportException(Runner.java:627)
at processing.mode.java.runner.Runner.exception(Runner.java:570)
at processing.mode.java.runner.EventThread.exceptionEvent(EventThread.java:367)
at processing.mode.java.runner.EventThread.handleEvent(EventThread.java:255)
at processing.mode.java.runner.EventThread.run(EventThread.java:89)
Exception in thread "Thread-6" java.lang.NullPointerException
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)


Any help is greatly thanks!

error, disabling serialEvent() for //./COM3

$
0
0
Hi...
I want to do the transition of images with respect to the intensity of light strike on LDR.
I manipulate the output of LDR from 1 to 10 in arduino and there is 10 images in processing, i want those images in processing to change with respect to the LDR output. 
But i am getting this error......

error, disabling serialEvent() for //./COM3
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at processing.serial.Serial.serialEvent(Unknown Source)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Caused by: java.lang.NullPointerException
at processing.core.PGraphics.image(PGraphics.java:3541)
at processing.core.PApplet.image(PApplet.java:11912)
at transition_of_images.serialEvent(transition_of_images.java:65)
... 8 more

Here is my code 

  1. import processing.serial.*;
  2. Serial myPort;

  3. PImage[] imgs;

  4. int nbr_of_images;
  5. float transitionFrames = 30;
  6. int displayFrames = 50;
  7. float fadeValue = 0;

  8. float img_Actual;
  9. float img_Next;


  10. void setup() {
  11.   size(1440, 900);

  12.   nbr_of_images = 10;  
  13.   imgs = new PImage[nbr_of_images];  
  14.  println(Serial.list());
  15. // print a list of all available ports
  16. myPort = new Serial(this, Serial.list()[1], 9600);
  17. myPort.bufferUntil('\n');
  18. for (int i = 0; i < nbr_of_images; i++)
  19. {
  20.   imgs[i] = loadImage(nf(i, 2) + ".JPG");
  21. }
  22. }


  23. void draw () {
  24.  // everything happens in the serialEvent()
  25.  }
  26.  
  27.  void serialEvent (Serial myPort) {
  28.  // get the ASCII string:
  29.  String inString = myPort.readStringUntil('\n');
  30.  

  31.  // convert to an int and map to the screen height:
  32.  float inByte = float(inString); 
  33.  println(inByte);
  34.   
  35.       // full opacity for image in background
  36.       tint(255);
  37.       image(imgs[int(img_Actual)], 0, 0, width, height);
  38.       
  39.       // fade foreground-image using tint()
  40.       tint(255, lerp(0, 255, fadeValue));
  41.       image(imgs[int(img_Next)], 0, 0, width, height);
  42.             
  43.             // change image and reset fadeValue
  44.   if (frameCount % (displayFrames) == 0)
  45.   {
  46.     fadeValue = 0;
  47.     img_Actual = img_Next;
  48.     img_Next = inByte;
  49.   }
  50.    // increase opacity of second image
  51.       fadeValue = fadeValue+1/transitionFrames;
    }

Need your valuable suggestions...
Thanking you in anticipation

Question - Changing color values for webcam stream

$
0
0
Hi everyone,

As a part of one of our university modules we have a video manipulation processing assignment. As my assignment I have chosen to create a simple RGB color corrector for a webcam stream. I have created most of my code, but I'm struggling with connecting the mapped sliders I have created to the loop that changes the colors (Excuse my primitive language but I'm quite a novice when it comes to Processing). Basically, I have been following the same procedure as if I was dealing with an image, and not surprisingly, this doesn't work with a video. I've looked in the libraries and got some pieces of code here and there but it doesn't seem to be working. Below this I'll post the specific part of the code which seems to be wrong, as well as the code in it's entirety.

I'm pretty sure I'm quite far away from where I want to be with this code, so any help would be greatly appreciated!


--------------------------------------------------------------------------------------------
The "bugged" part of the code:

 if (cam.available() == true)  {
    cam.read();
    loadPixels();
    cam.loadPixels();
     int x = int(random(cam.width));
     int y = int(random(cam.height));
     
     for (int i = 0; i < width*height; i++) {
       cam.pixels[i] = color (red(cam.pixels[i])*rCC*lCC, green (cam.pixels[i])*gCC*lCC, blue (cam.pixels[i])*bCC*lCC);
     }

 
     updatePixels ();

  }

Error message:
ArrayIndexOutOfBoundsException: 921600
-----------------------------------------------------------------------------------------------------
The current code in it's entirety:

import processing.video.*;
PImage img;

//Starting Slider positions
float lX = 1530;                    
float rX = 1530;
float gX = 1530;
float bX = 1530;


Capture cam;

//Load webcam and Background img
void setup() {
   size(1800, 720, P2D);
   img = loadImage ("Background.jpg");
   String [] cameras = Capture.list();
   
   if (cameras.length == 0) {
     println("There are no cameras available for capture.");
     exit();
   } else {
     println("Available cameras:");
     for (int i = 0; i < cameras.length; i++) {
       println(cameras[i]);
     }
     
     //Start cam
     cam = new Capture (this, cameras [0]);
     cam.start();
   }
}

void draw() {
  
  //Mapping the sliders
      
    float lCC = map(lX, 1330, 1730, 2, 0);                           
    float rCC = map(rX, 1330, 1730, 2, 0);
    float gCC = map(gX, 1330, 1730, 2, 0);
    float bCC = map(bX, 1330, 1730, 2, 0);
    
    
              
  if (cam.available() == true)  {
    cam.read();
    loadPixels();
    cam.loadPixels();
     int x = int(random(cam.width));
     int y = int(random(cam.height));
     
     for (int i = 0; i < width*height; i++) {
       cam.pixels[i] = color (red(cam.pixels[i])*rCC*lCC, green (cam.pixels[i])*gCC*lCC, blue (cam.pixels[i])*bCC*lCC);
     }

 
     updatePixels ();

  }

  image (img, 170, 0);
  image(cam, 0, 0);
  

   //Slider 1
   stroke(0);
  line(1330, 330, 1730, 330);                                                    
  fill(150);
  rectMode(CENTER);
  rect(lX, 330, 20, 12);

  if (mouseX > 1330 && mouseX < 1730 && mouseY > 325 && mouseY < 335) {

    if (mousePressed==true) {
      lX=mouseX;
    }

    if (lX <=1330) {
      lX=1330;
    }  

    if (lX >= 1730) {
      lX=1730;

    }
  }
      
      //Slider 2
       stroke(0);
  line(1330, 450, 1730, 450);                                                    
  fill(150);
  rectMode(CENTER);
  rect(rX, 450, 20, 12);

  if (mouseX > 1330 && mouseX < 1730 && mouseY > 445 && mouseY < 455) {

    if (mousePressed==true) {
      rX=mouseX;
    }

    if (rX <=1330) {
      rX=1330;
    }  

    if (rX >= 1730) {
      rX=1730;
    }
  }
  
  // Slider 3
  stroke(0);
  line(1330, 550, 1730, 550);                                                    
  fill(150);
  rectMode(CENTER);
  rect(bX, 550, 20, 12);

  if (mouseX > 1330 && mouseX < 1730 && mouseY > 545 && mouseY < 555) {

    if (mousePressed==true) {
      bX=mouseX;
    }

    if (bX <=1330) {
      bX=1330;
    }  

    if (bX >= 1730) {
      bX=1730;
    }
  }
  
  // Slider 4
    stroke(0);
  line(1330, 650, 1730, 650);                                                    
  fill(150);
  rectMode(CENTER);
  rect(gX, 650, 20, 12);

  if (mouseX > 1330 && mouseX < 1730 && mouseY > 645 && mouseY < 655) {

    if (mousePressed==true) {
      gX=mouseX;
    }

    if (gX <=1330) {
      gX=1330;
    }  

    if (gX >= 1730) {
      gX=1730;
    }
  }
}


pixels[] array works in 2D but not 3D?

$
0
0
I've been pulling out my hair all day trying to understand why the pixels[] array for a PImage was not being updated correctly.

It seems that the PImage pixels[] array is updated correctly when my sketch is 2D, but not 3D (not P3D nor OPENGL; both renders fail).

What I'm trying to do is to divide each frame of a movie into a grid of squares, and then arbitrarily move the squares in a 3D space.

When my sketch is 3D, it seems like only the lower right corner of the movie frame is replicated on all of the squares in the grid.  But if the sketch is 2D, then each square is a corresponding portion of the movie frame, as expected, and the entire movie frame is reproduced in the grid of squares.

I've tried this on 2.0b5 and 2.0b7 (Note that PeasyCam will make the sketch crash in 2.0b7 if you move the mouse).  I'm running Processing on a Mac, 10.7.5

Thoughts?  

  1. import processing.video.*;
  2. import peasy.*;

  3. PeasyCam cam;

  4. Movie myMovie;

  5. int stepsW ;
  6. int stepsH ;
  7. int stepSize = 80;
  8. PImage textureImage = new PImage();

  9. void setup()
  10. {  
  11.   size(1280, 720, OPENGL);
  12.   smooth();

  13.   perspective(radians(12), float(width)/float(height), 1, 500000);

  14.   cam = new PeasyCam(this, 5500);
  15.   cam.setMinimumDistance(1);
  16.   cam.setMaximumDistance(50000000);

  17.   textureImage = createImage(stepSize, stepSize, RGB);
  18.   stepsW = width/stepSize;
  19.   stepsH = height/stepSize;
  20.   println("stepSize: " + stepSize + " | stepsW: " + stepsW + " | stepsH: " + stepsH);

  21.   myMovie = new Movie(this, "test4.mov");
  22.   myMovie.loop();
  23. }

  24. void draw() {  
  25.   background(0);
  26.   myMovie.read();
  27.   myMovie.loadPixels();
  28.   meshUpdate();
  29. }

  30. void meshUpdate() {
  31.   pushStyle();
  32.   pushMatrix();
  33.   stroke(255);
  34.   int movieImagePixelIndex = 0;
  35.   for (int y=0; y<stepsH; y++) {
  36.     for (int x=0; x<stepsW; x++) {
  37.       int pixelIndex = 0;
  38.       for (int j=0; j < stepSize; j++) {
  39.         for (int i=0; i < stepSize; i++) {
  40.           movieImagePixelIndex = (y*stepSize*width) + (x*stepSize) + j*width + i;
  41.           textureImage.pixels[pixelIndex] = myMovie.pixels[movieImagePixelIndex];
  42.           pixelIndex++;
  43.         }
  44.       }
  45.       textureImage.updatePixels();
  46.       image(textureImage, x*stepSize-width/2, y*stepSize-height/2);
  47.     }
  48.   }
  49.   popStyle();
  50.   popMatrix();
  51. }

sketch in 2D (line 16 changed to "size(1280,720)"), movie frame correctly reproduced in the grid of squares:



sketch in 3D (the image is offset by width/2, height/2).  each square is a replication of the lower right corner of the movie frame:

Re : attempting to compare live video to a saved picture

Re : Different shaders for geometry, lines and text?

$
0
0
I see your point, the problem is that the rendering of unlit/untextured, textured, and stroke geometry is handled by separate shader programs since they involve different calculations at both the vertex and fragment levels. Another "architectural" option could have been to write a single massive shader that encompasses all possible combinations, but it would have been filled with if branches, which are not good to have for performance reasons. This is why I decided early on in the development of the new opengl renderer to handle each geometry class with a separate shader type...

However, you have the possibility to set only the fragment shader for any shader type, in that case Processing will complete your shader program using the default shader for that type. So, in the case of your fog example, you would need write three fragment shaders:

Main sketch:
  1. PShader fogColor; 
  2. PShader fogLines; 
  3. PShader fogTex; 

  4. void setup() { 
  5.   size(640, 360, P3D); 
  6.   
  7.   fogColor = loadShader("fogColor.glsl");
  8.   fogColor.set("fogNear", 0.0); 
  9.   fogColor.set("fogFar", 500.0);

  10.   fogLines = loadShader("fogLines.glsl");
  11.   fogLines.set("fogNear", 0.0); 
  12.   fogLines.set("fogFar", 500.0);

  13.   fogTex = loadShader("fogTex.glsl");
  14.   fogTex.set("fogNear", 0.0); 
  15.   fogTex.set("fogFar", 500.0);
  16.   
  17.   hint(DISABLE_DEPTH_TEST); 

  18. void draw() { 
  19.   shader(fogColor); 
  20.   background(0); 
  21.   noStroke(); 
  22.   translate(mouseX, mouseY, -100); 
  23.   box(200); 
  24.   fill(255,0,0); 
  25.   box(100); 

  26.   shader(fogLines);
  27.   stroke(255); 
  28.   strokeWeight(10); 
  29.   line(0,0,0, width/2, height/2, 100); 
  30.   line(0,0,0, -width/2, height/2, 100);

  31.   shader(fogTex);
  32.   text("shader", 100,0,100); 
  33. }

fogColor.glsl:
  1. varying vec4 vertColor;

  2. uniform float fogNear;
  3. uniform float fogFar;

  4. void main(){
  5.     gl_FragColor = vertColor;
  6.     
  7.     vec3 fogColor = vec3(1.0,1.0,1.0);
  8.     float depth = gl_FragCoord.z / gl_FragCoord.w;
  9.     float fogFactor = smoothstep(fogNear, fogFar, depth);
  10.     gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);
  11. }

fogLines.glsl:
  1. varying vec4 vertColor;

  2. uniform float fogNear;
  3. uniform float fogFar;

  4. void main(){
  5.     gl_FragColor = vertColor;
  6.     
  7.     vec3 fogColor = vec3(1.0,1.0,1.0);
  8.     float depth = gl_FragCoord.z / gl_FragCoord.w;
  9.     float fogFactor = smoothstep(fogNear, fogFar, depth);
  10.     gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);
  11. }

fogTex.glsl:
  1. uniform sampler2D textureSampler;
  2. varying vec4 vertColor;
  3. varying vec4 vertTexcoord;

  4. uniform float fogNear;
  5. uniform float fogFar;

  6. void main() {
  7.   gl_FragColor = texture2D(textureSampler, vertTexcoord.st) * vertColor;
  8.   
  9.   vec3 fogColor = vec3(1.0,1.0,1.0);
  10.   float depth = gl_FragCoord.z / gl_FragCoord.w;
  11.   float fogFactor = smoothstep(fogNear, fogFar, depth);
  12.   gl_FragColor = mix(gl_FragColor, vec4(fogColor, gl_FragColor.w), fogFactor);
  13. }

For this to work properly though, you have to make sure that you are using the correct varying names, as defined in the default vertex shaders. In this case, vertColor and vertTexcoord. All of this will be properly documented in the Processing reference of course, so people can exactly know the naming conventions adopted in the default Processing shaders. 

Now, a couple of observations:

1. fogColor.glsl and fogLines.glsl are actually identical, and even though this seems like an advantage (only two shaders to be written instead of three), this doesn't work properly in 2.0b7 because Processing will try to guess the type of the shader by inspecting the code you are providing to loadShader(). But because fogLines.glsl doesn't contain any information that unambiguously clear that it should work in combination with the vertex stage of line rendering, then Processing will build another color shader out of it, which is not what you want. This has been solved recently with some changes in the github repo, by removing the shader type autodetection and replacing it by a #define based approach that allows you to explicitly set the type of your shader: #13.

2. The fog effect is computed by the same snippet of code across all these shaders. I understand that it would be great to be able to specify just that snippet of code as some sort of "include" file that then could be referenced by shaders of any type. First thing to point out here is that GLSL doesn't natively support include files, so for this to work some substantial amount of additional logic/API needs to be incorporated to the opengl renderer. Something along the lines:
  1. loadShaderFunction("fogCalc.glsl");
  2. ...
  3. fog = loadShader("fog.glsl");
with fogCalc.glsl as you would expect:
  1. vec4 calcFog(vec4 fragCoord, vec4 fragColor, float near, float far) {  
  2.   vec3 fogColor = vec3(1.0,1.0,1.0);
  3.   float depth = fragCoord.z / fragCoord.w;
  4.   float fogFactor = smoothstep(near, far, depth);
  5.   return mix(fragColor, vec4(fogColor, fragColor.w), fogFactor);
  6. }
so you could do in the actual shader:
  1. varying vec4 vertColor;

  2. uniform float fogNear;
  3. uniform float fogFar;

  4. void main(){
  5.     gl_FragColor = calcFog(gl_FragCoord , vertColor, fogNear, fogFar);
  6. }
The renderer should be able to add the implementation of calcFog() automatically, but before the shader object is actually compiled... so things can get complicated easily at this point. This would be a really cool functionality, but needs more thinking and won't probably make it into the 2.0 release as the shader API is pretty much "done" at this point (with the recent changes I mentioned earlier).

Re : error, disabling serialEvent() for //./COM3

$
0
0
I do not know what is causing the error but your code is structured in a way to make troubleshooting difficult. Since you are the one to figure this out yourself I think you ought to partition your code into distinct elements that allow you to separate what you know works, and may be complete, from what is added or not working. For example the serialEvent function should take care of receiving the incoming signal and do nothing else. In your case it appears that you have 10 images in an array and you want the serialEvent to make an indexing variable correspond to the latest valid incoming number from the Arduino. Incidentally, the index will vary from 1 to 10 and so it need not be a float. A simple byte would do. I am guessing your serialEvent function should read the latest incoming value, compare it to the current index value, and then change the current index value to that new value if it is different. You would put diagnostic printlns in there to follow the progress and pinpoint exactly where an error occurs.  All that other code for changing and fading the image belongs in its own function that you call in the draw loop. I am wondering where in the program you are getting the error message. Does the code ever reach the println(inByte)? Does the code ever reach the println(Serial.list())? I think there may also be the possibility you are shorting or drawing too much current at the Arduino thereby causing the computer's serial port power manager to shut down the port. That might result in such an odd error message. A test for that would be to run the program on a plain Arduino that does not have any circuits added to it. 

Re : Help with Serial read

$
0
0
I believe all Processing programs have two parts, being the setup and draw functions. The setup function runs first once and then the draw function loops endlessly until something commands the program to stop. Your setup function sets up the screen and the audio player, appears to start playing an mp3 file (which I assume operates in the background) and then sets up the serial port. The draw function loops endlessly making a blank screen. The stop function is never called. The Arduino will be filling up the serial port with data that the Processing program never knows about because the Processing program is missing a "serialEvent" function to receive the serial data and decide what to do with it.  You need to add the serialEvent function with the right code in it to understand the number from the Arduino and do the right thing on the Processing side with that number for the rest of the Processing program, which you have yet to create, to do want you want it to do. You'll probably have a use for the stop function at some point in your project.    

Re : How to solve the java.lang.NullPointerException?

$
0
0
Have you placed printlns in your code to narrow down exactly where this occurs? It almost looks like the error occurs sometime after a serialEvent where you might have some condition your code caused that results in a bogus value. I currently have a similar error message that happens because I cannot figure out how to recover from the USB being temporarily unplugged while the program is running.

EEPROM library

$
0
0
Hi all¡

I've two question. I want save some variable values in my Arduino board but i find not the EEPROM library.Someone know where i can find the EEPROM library for Processing?

And I'm using Firmata library too, can i use both libraries?

Thank's

Re : Different shaders for geometry, lines and text?

$
0
0
Thanks for the detailed answer Andres.

Yes, the last example would be a great functionality, hope to see it sometime ;) The explicit set of the type of shader simplifies the process, nice!


Viewing all 1768 articles
Browse latest View live