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

Re : Processing 2 and OpenGL Frame Buffer Objects (FBO)

$
0
0
Hello Ivicks,

the first part of your question is about the pair of calls at the beginning of draw:

  1. PGL pgl = ((PGraphicsOpenGL) g).beginPGL();
  2. gl = pgl.gl.getGL().getGL2();
I can't give you the most detailed answer about why they are necessary, for that you should turn to someone more involved in OpenGL and Processing or some good books on OpenGL, but their purpose is roughly to prepare OpenGl for drawing. If you look at the source code for the PGraphicsOpenGL class, line 1640 to 1645, you'll see that the function beginPGL() "flushes" out any previous graphics and geometric transformations that hasn't been processed or drawn and in turns calls the beginGL() (line 1217)  of the PGL class - a Processing-OpenGL abstraction layer according to the header comments - which sets up the default Processing projection matrix.

After the function called on line 1 returns, the variable pgl points to an instance of the PGL class, the OpenGl-Processing abstraction layer.

The second line is more important, and probably causes the crash when omitted. Through the PGL instance, you can access the javax.media.opengl.GL object which for all practical purposes can be though of as the point of entry into the OpenGL API in Java when using JOGL. This also where things get confusing and I must admit that I don't really know what happens behind this interface. In any case, the chained function calls pgl.gl.getGL().getGL2() should return an OpenGL context that is suppose to look and behave like described in the OpenGL 2 specifications. You can think of OpenGL as machine which you operate by setting levers into different positions or states. You feed this machine geometry data and colours and by setting certain states it will perform specific operations and output the rendered frame like you want them (if you know what you are doing, otherwise you often get a mess of pixels or nothing at all).

I believe these getGL functions from line 2 also put the machine in a kind of ready state which is needed to start working with it.

This concept of state machine is important to understand the pushing popping and to try and answer the second part of you question.

The purpose of the code I posted was to show how to modify PGraphicsOpenGL so that one could push and pop framebuffers from outside the class. This was to solve a problem which caused the attachment of a texture to the FBO to fail because of conflicts with the FBO used by Processing internally (see andres answer). The solution was to push the current (that is the Processing internal buffer) FBO on the stack, perform my own offscreen rendering in my FBO, pop back the Processing FBO to return to a 'normal' state and finally show what has been rendered offscreen by texturing a quad using the texture attached to my FBO.

In my example, I'm not doing anything fancy in the offscreen rendering, I'm only filling the frame buffer with a colour that changes every frame using the noise function, thus setting the viewport to match the dimensions of the FBO (10 times smaller than the sketch in my example) could be omitted in that particular case. However, if you are going to do something a bit more complex, like re-rendering a complete scene at a much higher resolution, you will need to set the viewport to the dimension of you FBO so that the your geometries are actually drawn where you intend them to be. Also notice the pair of ((GL2)gl).glPushAttrib and ((GL2)gl).glPopAttrib. What I'm doing there is pushing the viewport matrix along with the information about what is enabled (like lighting) before I render offscreen, and pop them back afterwards. This is to save the state of the machine as set by Processing and to restore it after I'm done working on the custom FBO. Note that the operation of switching between states can be expensive in terms of processing time which could cause your animation to seriously slow down, so handle with care!

Judging from the code in your post, it seems that you are not binding your FBO, and actually not rendering anything in the FBO. You are only filling the window with black, getting the OpenGL context and binding the default frame buffer with glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); and then showing the texture attached to your FBO (which is empty because you haven't drawn anything in it).

As for why my example do not work on your machine, I don't really know, but hopefully I gave you enough information for you to figure out how to make your own code work.

Good article about FBOs in OpenGL :http://www.songho.ca/opengl/gl_fbo.html

Regards.



Re : Minim- "Unexpected token: \"

$
0
0
Try to put P3D to your size.
 
like this
 
size(100, 100 , P3D);
 
and run it.

minim recording problem

$
0
0
Hi, i've been recently making some tries with minim but I got stuck while testing the example code. The problematical one is in particular the one from here:


the code gives no errors but when i record all i get is something like this


audio is kinda corrupted: it seems like something goes wrong with buffers. Otherwise in all the other applications audio/recording goes ok with the same input/configuration.

I use latest processing, latest java, tried both (included in processing and latest from site) minim version with the same result. Mac with Mountain Lion.

The java audio recording applets I've tried on the web work fine.

I've been browsing quite all the posts about minim recording and it seems I'm the only one with this kind of problem but I'm new to minim so I don't have a clue. Can anyone give me a hand?

Thank you!
purpleandblue

minim using twice?

$
0
0

hi
i am using minim to generate a pip from value 1000 to 1100 - so far so good - it works
but it says in the console below:
=== Minim Error ===
=== Likely buffer underrun in AudioOutput.

i have no idea what that means but it works

but

if i want to do another pip at value 2000 to 2100 it does not work anymore. it seems as if it would only work once?
can anyone help?

here is part of the code concerning the pip

  1. import ddf.minim.*;
    import ddf.minim.signals.*;

    Minim minim;
    AudioOutput out;
    SineWave sine;


    void setup() {
       
         size(842,566);
         background(255);
         smooth();

        
         //pip
         minim = new Minim(this);
          // get a line out from Minim, default sample rate is 44100, default bit depth is 16
         out = minim.getLineOut(Minim.STEREO, 2048);
          // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate 44100 to match the line out
         sine = new SineWave(440, 0.5, out.sampleRate());
    }

    void draw() {
         background(255);
         stroke(0);
       
           //pip again
         if ((value > 1000) && (value < 1100))
         {
           out.addSignal(sine);
       
         }
         if (value > 1100) {
             out.close();
             minim.stop();   
         }
        
          if ((value > 2000) && (value < 2100))  {
            out.addSignal(sine);
          }  
            if (value > 2100) {
             out.close();
             minim.stop();   
         }
        }



Re : minim using twice?

$
0
0
Same warning here:

=== Minim Error ===
=== Likely buffer underrun in AudioOutput.

I get those all the time!

where processing.video?

$
0
0
Hi all,

I try to record film. But I can't import package processing.video: library core.jar(processiing2.0b3) has no package processing.video. Where is processing.video?

Re : where processing.video?

$
0
0
Oh sorry.. here is said that "video" is removed. Does anyone know tool to record movie? Not in PDE. In NetBeans. May be some library.. 

Re : where processing.video?


how to draw a design with a touch screen?

$
0
0
hello,
i'm from belgium and i have a projet with processing .
for my project i want tu draw a picture with a touch screen ( i taked that from nintendo ds and i used that with arduino).
this is my code:
 
// programme de tracage depuis processing
// avec saisie par ecran tactile (nitendo
// ds reconditioner).
// Pirrera C. Delrot A. et Mercier D.
import processing.serial.*;//on introduit la librairie serial qui permet
// de prendre les donnes envoyer par le port com
Serial EcranDs; // on donne un nom au port

void setup()
{
  size( 800, 800 );//taille fenetre
  background( 255 );// couleur du fond
  EcranDs = new Serial(this, Serial.list()[0], 9600); //[port] de l entree et
  EcranDs.bufferUntil(' ');
}
 
void draw() { 
 
}

void serialEvent( Serial EcranDs ){
  frameRate(60);//images par seconde
 
 
  String Lecture = EcranDs.readStringUntil( '\n' );//on lit ce que le port com nous envoi
 //ligne par ligne
  if( Lecture != null ){
    Lecture = trim( Lecture );
    int[] coords = int( split( Lecture, ',' ) );// on separe les cordonnes x et y
    //car on resoit x , y
    background(255);//couleur du fond (blanck)
    stroke(100);// couleur du tour du cercle
    fill(100);// couleur de l interieu du cercle
    int x = coords[0];
    int y =  coords[1];
    // on va limiter les contours du dessin
    if (x<700 & y<700){
      if (x>0 & y>0){
        ellipse(y, x, 10, 10); // permet de tracer un cercle qui suit notre point

      }
    }
  }
 
}
how to draw a design ( a draw , a picture )with a touch screen?
the  point follows my position but i don t know how to draw a design with a touch screen.
 
if you can corect my code it's nice . thanks.
sorry for my english (i speak fench and italian).
 

Re : where processing.video?

Processing 2.0b7 Serial.bufferUntil() not working?

$
0
0
Hi,
I am experimenting with serial communication between Processing and an AVR microcontroller (ATMEGA328).  I am on Windows XP and have successfully used Processing 1.5 and 1.5.1 to send and receive serial data to/from the microcontroller. 

Now I have downloaded the 32  bit Processing 2.0b7 code.  I specifically wanted the 2.0 Processing code because I am interested in exporting my application via the command line (actually from a Tcl script), and command line export is not available until version 2.0 and later.

On 2.0b7, I do the exact same thing as I was doing in 1.5.1and the bufferUntil() never triggers a serialEvent.  To track it down, I went with the simplest example script from Tom Igoe as detailed here http://processing.org/reference/libraries/serial/Serial.html.  The program never seems to receive the line feed from the microcontroller.  I do see evidence of the serial link sending the data because I have a USB-Serial converter with a RX/TX LED and I see it flash.

Again, I ran the exact same code in Processing 1.5.1, and it works fine.

Does anyone have any suggestions for getting this to  work in 2.0b7? 

Thanks for any ideas.

Rob

Re : how to draw a design with a touch screen?

$
0
0
Inside serialEvent(), you are calling "background(255);//couleur du fond (blanck)", which clears the entire drawing every a serialEvent happens.

Simply removing this line might fix your problem. There is a better solution, but it is much more complicated.

smooth() method different levels

$
0
0
Hi All,

I have been checking some code for a project of mine and saw something interesting in PApplet and PGraphics classes related with smooth() methods

Below is the piece of code from PAppplet.java

 public void smooth() {
    if (recorder != null) recorder.smooth();
    g.smooth();
  }

  public void smooth(int level) {
    if (recorder != null) recorder.smooth(level);
    g.smooth(level);
  }

Here both g and recorder objects are instances of PGraphics.java class and in that class, here are the smooth methods:

  public void smooth() {
    smooth = true;
  }
  /**
   *
   * @param level either 2, 4, or 8
   */
  public void smooth(int level) {
    smooth = true;
  }

Basically, setting different levels of smooth does not seem to be working. I have tried to put different numbers like 32 64 8 and so on but result didnt change at all. and as you can check the api page on http://processing.org/reference/smooth_.html it says smoothing levels should be working, but simply it is does not.

can anyone explain why the pieces of code above dont do anything with the levels although it is written in the API?

Re : minim using twice?

$
0
0
it don't mind the warning - as long as it works...

my real problem is, that it does not work the second time and i don't understand why?
do you?

Re : minim using twice?

$
0
0
Same!!! Just the 1st "play" works! Mute on any following attempts!

Re : Processing 2 and OpenGL Frame Buffer Objects (FBO)

$
0
0
Thanks for your input.  I really appreciate the detailed response.

The beginPGL makes sense now, as does popping of the viewport.  I was thinking of beginPGL as more of a constructor rather than an OpenGL call.  I've also added to my code some endPGL calls since I see beginPGL followed by endPGL in the internal code, and also logically this makes sense to me.

The best I can tell from some tests the processing internal FBO is no longer interfering with your FBO code, since I am able to get things to work without using the pushFramebuffer and popFramebuffer.  What is confusing me is that I am unable to get my own changes to affect the FBO, but calls to native processing routines such as background do affect the FBO.  When I don't use the background() routine the FBO comes out uninitialized.

The code can be found here.  Pastebin is numbered so it's just easier to talk about.

The idea is that I create an FBO in setup(), make it green, and then use it in draw() when a boolean is toggled.  A key press will toggle the boolean, and the background should alter between black (no FBO) and green (FBO).

What is killing me is that line 45 correctly changes the FBO to green, but lines 48-55 do not, even though 48-55 is a copy of the code for background()....  I even tried some Z translations to see if there was some depth test I was missing.

If anyone has any insight, I'd appreciate it.  The full code is below just so the link is never lost.

  1. import processing.core.*;
  2. import processing.opengl.*;
  3. import javax.media.opengl.GL;
  4. import javax.media.opengl.GL2;

  5. public class FBOTest extends PApplet {

  6. GL gl;

  7. int myFBO;
  8. int fboTexture;
  9. boolean drawFBO = true;

  10. public void setup() {
  11.  frameRate(30);
  12.  size(800, 600, P3D);
  13.  background(0, 0, 0);
  14.  colorMode(RGB, 100);
  15.  
  16.  // Start the opengl context so we can do some initialisation
  17.  PGL pgl = g.beginPGL();
  18.  gl = pgl.gl.getGL().getGL2();
  19.  
  20.  // Check what version of OpenGL we're using
  21.  println("This system uses OpenGL:"
  22.      + pgl.gl.getGL().glGetString(GL.GL_VERSION));
  23.  
  24.  int[] fboAndTex = new int[2];
  25.  
  26.  // create a FBO ten times smaller than the sketch
  27.  try {
  28.    fboAndTex = initializeFBO(gl, width, height);
  29.  } catch (Exception e) {
  30.    exit();
  31.  }
  32.  
  33.  myFBO = fboAndTex[0];
  34.  fboTexture = fboAndTex[1];
  35.  println("FBO created, ID: " + myFBO + ", with texture ID: " + fboTexture);

  36.  gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, myFBO); // Bind our frame buffer
  37.  
  38.  
  39.  // THIS WORKS
  40.  //background(0, 100, 0, 100);
  41.  
  42.  // THIS DOES NOT WORK
  43.  pushStyle();
  44.  pushMatrix();
  45.  resetMatrix();
  46.  //translate(0, 0, 5); // just a double check for depth test
  47.  fill(0, 100, 0, 100);
  48.  rect(0, 0, width, height);
  49.  popMatrix();
  50.  popStyle();
  51.  
  52.  /*
  53.  // TODO why won't this work??
  54.  fill(50, 50, 50);
  55.  rect(0, 0, width, height);
  56.  
  57.  fill(0, 0, 100);
  58.  textSize(32);
  59.  text("word", 50, 50, 0); 
  60.  */
  61.  gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0); // Bind draw buffer
  62.  
  63.  g.endPGL();
  64. }

  65. boolean checkBufferCompletness(GL gl) {
  66.  int fBStatus = gl.glCheckFramebufferStatus(GL.GL_FRAMEBUFFER);
  67.  if (fBStatus != GL.GL_FRAMEBUFFER_COMPLETE) {
  68.    switch (fBStatus) {
  69.    case GL.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
  70.      println("Not all framebuffer attachment points are framebuffer attachment complete.");
  71.      break;
  72.    case GL.GL_FRAMEBUFFER_UNSUPPORTED:
  73.      println("The combination of internal formats of the attached images violates an implementation-dependent set of restrictions.");
  74.      break;
  75.    case GL.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
  76.      println("No images are attached to the framebuffer.");
  77.      break;
  78.    default:
  79.      println("Framebuffer not ready for another reason.");
  80.    }
  81.    return false;
  82.  }
  83.  return true;
  84. }

  85. /*
  86. * Creates a Frame Buffer Object (FBO) take can be used to render color and
  87. * depth offscreen. There is a texture attached to the FBO which can be used
  88. * like a regular texture (texturing a quad for instance). gl : the OpenGL
  89. * context w : the width of the FBO h: the height Returns the ids of the FBO
  90. * and the associated texture in an array in that order. Throws an exception
  91. * if the FBO could not be created
  92. */
  93. int[] initializeFBO(GL gl, int w, int h) throws Exception {
  94.  // let's first create a texture to attach to the FBO
  95.  int[] array = new int[1];
  96.  gl.glGenTextures(1, array, 0); // ask OpenGL for a texture id
  97.  int tex = array[0];

  98.  // tell OpenGL we're going to work on this new texture
  99.  gl.glEnable(GL.GL_TEXTURE_2D);
  100.  gl.glBindTexture(GL.GL_TEXTURE_2D, tex);

  101.  // Setup some properties, mipmap etc...
  102.  
  103.  gl.glTexParameteri(GL.GL_TEXTURE_2D, 
  104.             GL.GL_TEXTURE_MIN_FILTER,
  105.             GL.GL_NEAREST);
  106.  
  107.  gl.glTexParameteri(GL.GL_TEXTURE_2D, 
  108.               GL.GL_TEXTURE_MAG_FILTER,
  109.               GL.GL_NEAREST);
  110.  
  111.  gl.glTexParameteri(GL.GL_TEXTURE_2D, 
  112.             GL.GL_TEXTURE_WRAP_S,
  113.             GL.GL_CLAMP_TO_EDGE);
  114.  
  115.  gl.glTexParameteri(GL.GL_TEXTURE_2D, 
  116.             GL.GL_TEXTURE_WRAP_T,
  117.             GL.GL_CLAMP_TO_EDGE);
  118.  
  119.  // set what the format of the pixels we're using
  120.  gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, 
  121.            GL.GL_RGBA, w, h, 0, 
  122.            GL.GL_RGBA,
  123.            GL.GL_UNSIGNED_BYTE, null);

  124.  // Done with the texture
  125.  gl.glBindTexture(GL.GL_TEXTURE_2D, 0);

  126.  // Create a Frame Buffer Object
  127.  gl.glGenFramebuffers(1, array, 0); // Ask OpenGL for a framebuffer id
  128.  int fbo = array[0];
  129.  // Tells OpenGL we're going to work on the fbo
  130.  gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, fbo);

  131.  // attach the texture to the FBO
  132.  gl.glFramebufferTexture2D(GL.GL_FRAMEBUFFER, 
  133.                GL.GL_COLOR_ATTACHMENT0,
  134.                GL.GL_TEXTURE_2D, tex, 0);
  135.  // then create a render buffer
  136.  gl.glGenRenderbuffers(1, array, 0); // Ask OpenGL for a renderbuffer id
  137.  int rb = array[0];
  138.  // attach the render buffer to the FBO
  139.  gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, rb);

  140.  // this tells OpenGL that the render buffer is used for depth data and
  141.  // that we need a buffer of dimension w by h
  142.  gl.glRenderbufferStorage(GL.GL_RENDERBUFFER, 
  143.               GL2.GL_DEPTH_COMPONENT24,
  144.               w, h);
  145.  // attach it to the frame buffer
  146.  gl.glFramebufferRenderbuffer(GL2.GL_DRAW_FRAMEBUFFER,
  147.                 GL.GL_DEPTH_ATTACHMENT, 
  148.                 GL.GL_RENDERBUFFER, rb);
  149.  // done working on the render buffer
  150.  gl.glBindRenderbuffer(GL.GL_RENDERBUFFER, 0);

  151.  // At this point everything is set and all that remains to do is to
  152.  // check for completness of the FBO
  153.  if (!checkBufferCompletness(gl)) {
  154.    throw new Exception("Could not create the FBO.");
  155.  }

  156.  // done working on the frame buffer
  157.  gl.glBindFramebuffer(GL.GL_FRAMEBUFFER, 0);

  158.  return new int[] { fbo, tex };

  159. }

  160. public void draw() {

  161.  // Start the opengl context so we can do some initialisation
  162.  PGL pgl = g.beginPGL();
  163.  gl = pgl.gl.getGL().getGL2();
  164.  
  165.  background(0);
  166.  
  167.  if(drawFBO) {
  168.    ((PGraphicsOpenGL) g).drawTexture(GL.GL_TEXTURE_2D, fboTexture,
  169.                            width, height, 0, 0, width, height);
  170.  }
  171.  
  172.  fill(100, 0, 0);
  173.  rect(0, 0, 50, 50);
  174.  
  175.  g.endPGL();
  176. }

  177. public void keyPressed() {
  178.  drawFBO = !drawFBO;
  179.  println("FBO is " + drawFBO);
  180. }

  181. }

Re : minim using twice?

$
0
0
and what are we now going to do? any idea?

Re : smooth() method different levels

$
0
0
Don't forget that PGraphics has various sub-classes, overriding this smooth() method: PGraphicsJava2D, PGraphics2D, PGraphics3D, PGraphicsOpengGL, PGraphicsPDF and so on...

Re : smooth() method different levels

$
0
0
yea, you are right, I have debugged the code and it was using J2D... thank you so much

Re : how to draw a design with a touch screen?

$
0
0
thanks it works .
but somme point have bugs ( the position is not good when i draw it fastre )
 
 
electric shema :
                                                                                       ____________________y1 touch screen
                             ________ 10k homs ____________|__  A0 arduino
gnd arduino  ------|                                                          ____________________y2 touch screen
                            |________ 10k homs ____________|__   A1 arduino
                            |                                                          ____________________x1 touch screen
                            |________ 10k homs ____________|__  A2 arduino
                            |                                                          ____________________x2 touch screen
                            |________ 10k homs ____________|__  A3 arduino
 
how  can i  ameliorate the sensibility and the presision ?
Viewing all 1768 articles
Browse latest View live