We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using this modified main method to run my main sketch on a second display in 3.0a5. The sketch doesnt run because my sketch path is lost, I tried exporting the sketch and it didnt work. Any suggestions?
static final void main(final String[] args) {
final String sketch = Thread.currentThread().getStackTrace()[1].getClassName();
final String[] monitor = { "--display=1", "--present" };
final String[] params = concat(append(monitor, sketch), args);
PApplet.main(params);
}
Answers
I've warned about that in your previous post:
https://forum.Processing.org/two/discussion/comment/60819/#Comment_60819
It works when run as an exported app.
Another option is not use main() and go w/ runSketch() in setup().
Besides "--display=" & "--present", pass "--sketch-path" to it.
Yes, I exported the sketch and it still didnt work. Could I pass the sketch path in the main()?
I really prefer not to use runSketch() because that way, I'd have to split my code into a main sketch and two projector sketches. One projector sketch for the live music visuals im making and one for the controlP5 buttons and knobs.
I'm having trouble sharing variables and objects between these when I use the runSketch() method. I keep getting "cant make static reference to non-static value".
Sorry this turned out to be such a lengthy discussion.
Unfortunately not! When we're using the PDE (Processing's IDE), that is the 1 responsible to pass "--sketch-path=" to our sketches.
However when we hack the
static final void main(final String[] args) {
, the PDE somehow decides not to! X(As I had mentioned before, only when we run the exported app, outside the PDE, we got sketchPath back while hacking main().
That sentence above is ambiguous and doesn't match what you had already told me before! [-(
I remember you've said you had 1 external projector. Plus 1 main monitor.
Is that still correct or it is now 1 monitor + 2 external projectors? ~:>
Recall that every sketch automatically got 1 canvas window already. And each windows can target 1 display only.
I've already told you there's no other way. Unless you know some hard hack into Processing's innards to change the chosen initial display on-the-fly. :-\"
That is, each target display demands 1 PApplet instance.
As said, we already got 1 free when we start a sketch. By default it's gonna target our main monitor.
Therefore, for every other monitor(s) &/or projector(s), we're gonna need 1 extra PApplet.
The most flexible way to ignite some PApplet instance is via runSketch().
We can even pass to them many args like "--present", "--display=", "--location=", "--sketch-path=", etc, as you already know:
Another example based on: https://forum.Processing.org/two/discussion/comment/46184/#Comment_46184
What I wanted to do before was to have a single sketch switch between monitors when a certain key was pressed. But now I think its easier to use the runSketch() method.
So just to make sure I've understood this right, I should have 1 main sketch doing all the calculations and processing all the objects (I'll keep it hidden) and 2 sketches; 1 a projector sketch on the second monitor and the other is my controlP5 sketch?
This would work perfectly but everytime the controlP5 knobs / sliders change, the objects used by my projector sketch will need to change. I'm thinking of instantiating the projector sketch each time this happens.
Is there an easier way of doing this? You mentioned using a PGraphics object but will a projector sketch be able to access this object from the main sketch?
PApplet.main() & PApplet.runSketch().
public static
nested or top classes.static
), it can access every member from its enclosing class.Awesome. What is the role of synchronized()?
Just some precaution. I don't think it would be a good idea to let the other PApplet use image() at the same time the PGraphics is being updated from the main PApplet. :-\"
I update PGraphics in multiple places. Do I just use synchronized() as above in those places?
If you don't see any problems, no need for **synchronized ()` I guess.
If used, they're just to protect the update part from the display part.
I can compile my code, but the projector sketch is not showing anything. I'm wondering if there is something I'm missing.
Oh, you've got 2 main problems there:
Your currently situation is main PApplet is using a P2D renderer canvas, which is OpenGL-based.
While the Projector is using JAVA2D renderer canvas, which isn't OpenGL-based.
Therefore the latter can't use the shared P2D PGraphics, b/c its canvas is JAVA2D.
But at the same time you can't change it from JAVA2D to some other OpenGL-based renderer.
B/c that would crash the whole sketch! :-SS
So after all, how could such circular situation be ever fixed?
My idea is share a PImage rather than a PGraphics.
We just need to use arrayCopy() from canvas' pixels[] to sharedImg's own pixels[]. *-:)
https://Processing.org/reference/arrayCopy_.html
https://Processing.org/reference/pixels.html