Version of createGraphics() used internally. @param path A path (or null if none), can be absolute or relative (PApplet#savePath will be called)
(int w, int h,
String renderer, String path,
boolean primary)
| 2240 | * @param path A path (or null if none), can be absolute or relative ({@link PApplet#savePath} will be called) |
| 2241 | */ |
| 2242 | protected PGraphics makeGraphics(int w, int h, |
| 2243 | String renderer, String path, |
| 2244 | boolean primary) { |
| 2245 | // String openglError = external ? |
| 2246 | // // This first one should no longer be possible |
| 2247 | // "Before using OpenGL, first select " + |
| 2248 | // "Import Library > OpenGL from the Sketch menu." : |
| 2249 | // // Welcome to Java programming! The training wheels are off. |
| 2250 | // "The Java classpath and native library path is not " + |
| 2251 | // "properly set for using the OpenGL library."; |
| 2252 | |
| 2253 | if (!primary && !g.isGL()) { |
| 2254 | if (renderer.equals(P2D)) { |
| 2255 | throw new RuntimeException("createGraphics() with P2D requires size() to use P2D or P3D"); |
| 2256 | } else if (renderer.equals(P3D)) { |
| 2257 | throw new RuntimeException("createGraphics() with P3D or OPENGL requires size() to use P2D or P3D"); |
| 2258 | } |
| 2259 | } |
| 2260 | |
| 2261 | try { |
| 2262 | Class<?> rendererClass = |
| 2263 | Thread.currentThread().getContextClassLoader().loadClass(renderer); |
| 2264 | |
| 2265 | Constructor<?> constructor = rendererClass.getConstructor(new Class[] { }); |
| 2266 | PGraphics pg = (PGraphics) constructor.newInstance(); |
| 2267 | |
| 2268 | pg.setParent(this); |
| 2269 | pg.setPrimary(primary); |
| 2270 | if (path != null) { |
| 2271 | pg.setPath(savePath(path)); |
| 2272 | } |
| 2273 | // pg.setQuality(sketchQuality()); |
| 2274 | // if (!primary) { |
| 2275 | // surface.initImage(pg, w, h); |
| 2276 | // } |
| 2277 | pg.setSize(w, h); |
| 2278 | |
| 2279 | // everything worked, return it |
| 2280 | return pg; |
| 2281 | |
| 2282 | } catch (InvocationTargetException ite) { |
| 2283 | String msg = ite.getTargetException().getMessage(); |
| 2284 | if ((msg != null) && |
| 2285 | (msg.indexOf("no jogl in java.library.path") != -1)) { |
| 2286 | // Is this true anymore, since the JARs contain the native libs? |
| 2287 | throw new RuntimeException("The jogl library folder needs to be " + |
| 2288 | "specified with -Djava.library.path=/path/to/jogl"); |
| 2289 | |
| 2290 | } else { |
| 2291 | printStackTrace(ite.getTargetException()); |
| 2292 | Throwable target = ite.getTargetException(); |
| 2293 | /* |
| 2294 | // removing for 3.2, we'll see |
| 2295 | if (platform == MACOSX) { |
| 2296 | target.printStackTrace(System.out); // OS X bug (still true?) |
| 2297 | } |
| 2298 | */ |
| 2299 | throw new RuntimeException(target.getMessage()); |
no test coverage detected