Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot draw atop maps in JAVA2D since Processing 3 beta 6 #118

Open
tillnagel opened this issue Sep 24, 2015 · 4 comments
Open

Cannot draw atop maps in JAVA2D since Processing 3 beta 6 #118

tillnagel opened this issue Sep 24, 2015 · 4 comments

Comments

@tillnagel
Copy link
Owner

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
Copy link
Owner Author

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

size(800,800, P2D);

@r-hmn
Copy link

r-hmn commented Sep 27, 2019

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();
+
 	}
 
 	/**

@tillnagel
Copy link
Owner Author

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.

@r-hmn
Copy link

r-hmn commented Dec 10, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants