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)
| 1878 | * @param path A path (or null if none), can be absolute or relative ({@link PApplet#savePath} will be called) |
| 1879 | */ |
| 1880 | protected PGraphics makeGraphics(int w, int h, |
| 1881 | String renderer, String path, |
| 1882 | boolean primary) { |
| 1883 | if (!primary && !g.isGL()) { |
| 1884 | if (renderer.equals(P2D)) { |
| 1885 | throw new RuntimeException("createGraphics() with P2D requires size() to use P2D or P3D"); |
| 1886 | } else if (renderer.equals(P3D)) { |
| 1887 | throw new RuntimeException("createGraphics() with P3D or OPENGL requires size() to use P2D or P3D"); |
| 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | try { |
| 1892 | Class<?> rendererClass = |
| 1893 | Thread.currentThread().getContextClassLoader().loadClass(renderer); |
| 1894 | |
| 1895 | Constructor<?> constructor = rendererClass.getConstructor(); |
| 1896 | PGraphics pg = (PGraphics) constructor.newInstance(); |
| 1897 | |
| 1898 | pg.setParent(this); |
| 1899 | pg.setPrimary(primary); |
| 1900 | if (path != null) { |
| 1901 | pg.setPath(savePath(path)); |
| 1902 | } |
| 1903 | // pg.setQuality(sketchQuality()); |
| 1904 | // if (!primary) { |
| 1905 | // surface.initImage(pg, w, h); |
| 1906 | // } |
| 1907 | pg.setSize(w, h); |
| 1908 | |
| 1909 | // everything worked, return it |
| 1910 | return pg; |
| 1911 | |
| 1912 | } catch (InvocationTargetException ite) { |
| 1913 | String msg = ite.getTargetException().getMessage(); |
| 1914 | if ((msg != null) && |
| 1915 | (msg.contains("no jogl in java.library.path"))) { |
| 1916 | // Is this true anymore, since the JARs contain the native libs? |
| 1917 | throw new RuntimeException("The jogl library folder needs to be " + |
| 1918 | "specified with -Djava.library.path=/path/to/jogl"); |
| 1919 | |
| 1920 | } else { |
| 1921 | printStackTrace(ite.getTargetException()); |
| 1922 | Throwable target = ite.getTargetException(); |
| 1923 | /* |
| 1924 | // removing for 3.2, we'll see |
| 1925 | if (platform == MACOSX) { |
| 1926 | target.printStackTrace(System.out); // OS X bug (still true?) |
| 1927 | } |
| 1928 | */ |
| 1929 | throw new RuntimeException(target.getMessage()); |
| 1930 | } |
| 1931 | |
| 1932 | } catch (ClassNotFoundException cnfe) { |
| 1933 | // Clarify the error message for less confusion on 4.x |
| 1934 | if (renderer.equals(FX2D)) { |
| 1935 | renderer = "JavaFX"; |
| 1936 | } |
| 1937 | if (external) { |
no test coverage detected