unfolding icon indicating copy to clipboard operation
unfolding copied to clipboard

Cannot draw atop maps in JAVA2D since Processing 3 beta 6

Open tillnagel opened this issue 8 years ago • 4 comments

Java2DMapDisplay uses papplet.g as canvas directly, and thus beginDraw() in mapDisplay.draw() messes up things.

Solution: Either add new method preDraw() and only call beginDraw for OpenGLMapDisplay (and keep it empty in Java2DMapDisplay), or use an offscreen buffer in Java2D too (which might fix #117, too).

tillnagel avatar Sep 24 '15 10:09 tillnagel

Work-around: Switch to P2D, e.g. use

size(800,800, P2D);

tillnagel avatar Dec 20 '16 08:12 tillnagel

I Updated the Java2DMapDisplay.java, and now the examples work in my environment.(JDK1.8, JAVA2D, unfolding0.9.9beta )

I did have to change the examples a bit;

  • create a settings() method, and do size() there.
  • make size() use JAVA2D.
  • create a static main() calling runSketch with the examples' class name.

Next the patch difference (used WinMerge):

--- de\fhpotsdam\unfolding\mapdisplay\Java2DMapDisplay.java	Fri Sep 27 09:47:43 2019
+++ unfolding/releases/0.9.9beta/fixes/Java2DMapDisplay.java	Fri Sep 27 09:45:17 2019
@@ -33,6 +33,9 @@
 	// Used for loadImage and float maths
 	public PApplet papplet;
 
+	// Double buffer created from papplet's PGraphics
+	private PGraphics innerPg;
+
 	/** The inner transformation matrix. Scales and rotates the map. */
 	protected PMatrix3D innerMatrix = new PMatrix3D();
 
@@ -61,6 +64,8 @@
 		super(provider, width, height);
 		this.papplet = papplet;
 
+		this.innerPg = papplet.createGraphics((int)width, (int)height, JAVA2D);
+
 		this.offsetX = offsetX;
 		this.offsetY = offsetY;
 
@@ -323,12 +328,12 @@
 	// DRAWING --------------------------------------------------
 
 	public PGraphics getInnerPG() {
-		// NB Always inner graphics, this one not used. Implemented in sub classes.
-		return papplet.g;
+		// Return the PGraphics object which is used during draw() to image() onto the main PGraphics
+		return innerPg;
 	}
 
 	public PGraphics getOuterPG() {
-		return papplet.g;
+		return innerPg;
 	}
 
 	/**
@@ -401,11 +406,16 @@
 		}
 
 		pg.popMatrix();
-		pg.endDraw();
 
+		// Ensure Markers are drawn before endDraw
 		postDraw();
 
+		pg.endDraw();
+
+		papplet.image( getInnerPG(), offsetX, offsetY);
+
 		cleanupImageBuffer();
+
 	}
 
 	/**

r-hmn avatar Sep 27 '19 07:09 r-hmn

Thanks for the suggestion @r-hmn. Alas, with that change and using P2D/P3D renderer, markers are not visible, and non-markers (i.e. objects drawn atop the map directly) are not at their correct positions when using an offset.

tillnagel avatar Dec 10 '19 12:12 tillnagel

Thanks @tillnagel interesting.. i must have missed the non-markers examples failing.

Since September i've changed to using jxmapviewer2 as the basis for my development because the "processing" paint-loop was too massive to incorporate. But it was nice to experience unfolding & processing! Cheers

r-hmn avatar Dec 10 '19 12:12 r-hmn