I have only worked with Processing's standard renderer until now. I got a java project where i am working with processing included via maven.
Since other renderers might be faster, i wanted to try using another for my current project, but any other renderer fails for me (P2D, P3D, FX2D). Only the default, Java2D works.
Seemed weird to me, so i started another project with nothing in it, just creating an empty frame. I first tried running it in the Processing.exe as a sketch, and it worked:
The Sketch code:
void setup()
{
size(500, 200, P3D);
}
void draw()
{
}
I then rewrote it into plain java:
import processing.core.PApplet;
public class Test extends PApplet
{
public void setup() {
}
public void draw() {
}
public void settings() {
this.size(500, 200, P3D);
}
public static void main(final String[] passedArgs) {
final String[] appletArgs = { "Test" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
}
else {
PApplet.main(appletArgs);
}
}
}
No matter what i tried so far, i keep running into the following exeption:
java.lang.NoClassDefFoundError: com/jogamp/opengl/GLException
at processing.opengl.PGraphicsOpenGL.createPGL(PGraphicsOpenGL.java:712)
at processing.opengl.PGraphicsOpenGL.<init>(PGraphicsOpenGL.java:569)
at processing.opengl.PGraphics3D.<init>(PGraphics3D.java:35)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at processing.core.PApplet.makeGraphics(PApplet.java:2235)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2314)
at processing.core.PApplet.initSurface(PApplet.java:10828)
at processing.core.PApplet.runSketch(PApplet.java:10767)
at processing.core.PApplet.main(PApplet.java:10467)
at Test.main(Test.java:19)
Caused by: java.lang.ClassNotFoundException: com.jogamp.opengl.GLException
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 14 more
java.lang.RuntimeException: com/jogamp/opengl/GLException
at processing.core.PApplet.makeGraphics(PApplet.java:2268)
at processing.core.PApplet.createPrimaryGraphics(PApplet.java:2314)
at processing.core.PApplet.initSurface(PApplet.java:10828)
at processing.core.PApplet.runSketch(PApplet.java:10767)
at processing.core.PApplet.main(PApplet.java:10467)
at Test.main(Test.java:19)
I am working with Java 17, and already tried to run with Java 8 as i read this might work, but.. it didnt.
Is it not possible to run those P2D, P3D, FX2D sketches outside of the processing.exe?
An even better solution to this problem would be to just use the newer processing4.
Micycle1 made the processing4-core usable with maven via JitPack: https://github.com/micycle1/processing-core-4
Adding following dependencies to the pom.xml solved it:
<dependency>
<groupId>org.jogamp.jogl</groupId>
<artifactId>jogl-all</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.jogamp.gluegen</groupId>
<artifactId>gluegen-rt-main</artifactId>
<version>2.3.2</version>
</dependency>
Related
Background/Prerequisites
I am trying to follow a game tutorial(to create flappy bird). In the
Episode - 2 it creates an empty window and I get an error.
I tried following this tutorial series to create a game using java - eclipse - lwjgl.
https://www.youtube.com/watch?v=1pUYjxeDNEs&list=PLlrATfBNZ98e5KBKGcL7ARy3DjstzI2TV&index=1&ab_channel=TheCherno
Flappy Bird - Episode 1
I have installed java jdk 17.0.6 (in the tutorial it installs an older version which I thought it won't be a problem, let me know if this could be the cause), eclipse 2022 and lwjgl - 2.9.1.
I have copied the code from Episode 2 (seen below):
https://www.youtube.com/watch?v=PlMqfsOOD3U&list=PLlrATfBNZ98e5KBKGcL7ARy3DjstzI2TV&index=2&ab_channel=TheCherno
Flappy Bird - Episode 2
which tries to create an empty window.
package com.chris.flappy;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
public class Main implements Runnable{
private int width = 1280;
private int height = 720;
private String title = "Flappy";
private boolean running = false;
private Thread thread;
public void start(){
running = true;
thread = new Thread(this,"Display");
thread.start();
}
public void run() {
try {
Display.setDisplayMode(new DisplayMode(width,height));
Display.setTitle(title);
Display.create();
} catch (LWJGLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while(running) {
if(Display.isCloseRequested()) running = false;
}
Display.destroy();
}
public static void main(String args[]) {
new Main().start();
}
}
I have included in the module path the lwjgl.jar file and changed the native library location as shown in the video to the corresponding folder with the dlls, but with the difference that in the video (probably because it was an older version) it didn't have the separation of module path and class path.
Screenshot_1
I have the following workspace folders set.
Screenshot_2
Screenshot_3
Error
I am gettting the following error.
Error: Unable to initialize main class com.chris.flappy.Main
Caused by: java.lang.NoClassDefFoundError: org/lwjgl/LWJGLException
Screenshot_4
What have I tried from the mentioned solutions?
I have tried using an older version of java (1.8) and still it doesn't work
In this article solution they mentioned about moving jars to classpath, I tried drag and dropping them from module path as well as placing them but it seems to not work.
Does anyone know how can I fix this?
Thank you.
Comment section
comment_screenshot1
comment_screenshot2
My goal: Running Processing.org (version 3.5.4) from Max (cycling74) version 8 on Windows 10 64 through writing an MXJ external (Max Java support). I want to open a processing test sketch within window from MAX by sending a bang message to the MXJ external. For this I have
class MaxJavaTest3 extends MaxObject which calls
class TestProcessing extends PApplet.
public class MaxJavaTest3 extends MaxObject {
public void bang() {
String[] args = {};
TestProcessing.main(args);
}
}
public class TestProcessing extends PApplet {
public static void main(String args[] ) {
PApplet.main("TestProcessing", args);
}
public void settings() {
size(920, 780);
}
public void setup() {
background(0);
fill(255, 0, 0);
circle(width/2, height/2, 80);
}
}
In IntelliJ, I set the dependencies for Max and Java. The bang message is received in Java e.g. triggering some text messages to the console. If I execute PApplet.main via the entry point TestProcessing.main, the processing window opens. So far so good, but trying to invoke PApplet.main via MaxJavaTest3.bang() method I get the error:
java.lang.RuntimeException: java.lang.ClassNotFoundException: TestProcessing
at processing.core.PApplet.runSketch(PApplet.java:10852)
at processing.core.PApplet.main(PApplet.java:10657)
at TestProcessing.main(TestProcessing.java:11)
at MaxJavaTest3.bang(MaxJavaTest3.java:19)
Caused by: java.lang.ClassNotFoundException: TestProcessing
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at processing.core.PApplet.runSketch(PApplet.java:10845)
... 3 more
```JAVA
I found a post which suggests that there is a problem with Max using Processing´s OpenGL related capacities: "since OpenGL uses also native libraries (*.dll files) and not only *.jar files. I don't know if its possible in MaxMSP - that depends on how they set up their JVM."
https://forum.processing.org/one/topic/use-processing-from-within-max-msp-or-from-matlab.html
I am getting an error when running java program using processing core v 3.3.7.
I tried other versions, but it didn't help.
The error I get is the following:
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: java.lang.StringIndexOutOfBoundsException: begin 0, end -1, length 2
at java.base/java.lang.String.checkBoundsBeginEnd(String.java:3319)
at java.base/java.lang.String.substring(String.java:1874)
at processing.core.PApplet.<clinit>(PApplet.java:120)
The code is provided below:
import processing.core.PApplet;
public class ProcessingTest extends PApplet {
#Override
public void settings() {
size(200, 200);
}
#Override
public void draw() {
background(0);
fill(255, 0, 0);
ellipse(100, 100, 100, 100);
}
public static void main (String... args) {
ProcessingTest pt = new ProcessingTest();
PApplet.runSketch(new String[]{"ProcessingTest"}, pt);
}
}
I can't see what the problem is.
Strangely enough I couldn't replicate your issue.
Is your class in a package ? If so, might be worth passing the full class path including the package. e.g:
PApplet.runSketch(new String[]{ProcessingTest.class.getCanonicalName()}, pt);
you can also try:
PApplet.main(ProcessingTest.class.getCanonicalName());
Additionally, it's worth mentioning what OSX you're on and what JDK you used to compile, and what your machine outputs when calling System.getProperty("java.version");.
Having a quick skim through Processing source code I spotted this line:
javaPlatform = parseInt(version.substring(0, version.indexOf('.')));
Depending on your OS this might a basic bug parsing an unexpected string.
This is the screenshot of my Eclipse project files.
I get the error below when I try to initiated a new Sound("Res/MouseClick.ogg") object in my class AudioPlayer at line 15.
package com.game;
import java.util.HashMap;
import java.util.Map;
import org.newdawn.slick.Music;
import org.newdawn.slick.Sound;
public class AudioPlayer {
public static Map<String, Sound> soundMap = new HashMap<String, Sound>();
public static Map<String, Music> musicMap = new HashMap<String, Music>();
public static void load() {
try {
soundMap.put("menu_sound", new Sound("Res/MouseClick.ogg")); // <- throws error
musicMap.put("music", new Music("Res/Background.ogg"));
} catch (Exception e) {
e.printStackTrace();
}
}
public static Music getMusic(String key) {
return musicMap.get(key);
}
public static Sound getSound(String key) {
return soundMap.get(key);
}
}
Exception in thread "main" java.lang.NoClassDefFoundError: sun/misc/Unsafe
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.getUnsafeInstance(MemoryUtilSun.java:74)
at lwjgl/org.lwjgl.MemoryUtilSun$AccessorUnsafe.<init>(MemoryUtilSun.java:62)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:500)
at java.base/java.lang.reflect.ReflectAccess.newInstance(ReflectAccess.java:166)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(ReflectionFactory.java:404)
at java.base/java.lang.Class.newInstance(Class.java:590)
at lwjgl/org.lwjgl.MemoryUtil.loadAccessor(MemoryUtil.java:324)
at lwjgl/org.lwjgl.MemoryUtil.<clinit>(MemoryUtil.java:66)
at lwjgl/org.lwjgl.openal.ALC10.alcOpenDevice(ALC10.java:202)
at lwjgl/org.lwjgl.openal.AL.init(AL.java:160)
at lwjgl/org.lwjgl.openal.AL.create(AL.java:138)
at lwjgl/org.lwjgl.openal.AL.create(AL.java:102)
at lwjgl/org.lwjgl.openal.AL.create(AL.java:201)
at slick/org.newdawn.slick.openal.SoundStore$1.run(SoundStore.java:295)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:310)
at slick/org.newdawn.slick.openal.SoundStore.init(SoundStore.java:292)
at slick/org.newdawn.slick.Sound.<init>(Sound.java:54)
at Wave/com.game.AudioPlayer.load(AudioPlayer.java:15)
at Wave/com.game.Game.<init>(Game.java:37)
at Wave/com.game.Game.main(Game.java:157)
Caused by: java.lang.ClassNotFoundException: sun.misc.Unsafe
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 23 more
From your posted IDE screenshot I can see that you are using
Java 12, and
the Java Module System (module-info.java)
Note that sun/misc/Unsafe is a (legacy) Java internal API which for that reason and by default is encapsulated (hidden) away when using the Java Module System.
In order for your application (and your used library) to access it, you need to explicitly include it in your module-info.java by adding requires jdk.unsupported;
Alternatively, you may also not use the Java Module System – in which case it should simply work. However, I recommend to continue using the module system.
I wrote this simple code:
public class Test {
public static void main(String args[]) {
OculusRift oculusRift = new OculusRift();
oculusRift.init();
HMDInfo hdmInfo = oculusRift.getHMDInfo();
System.out.println(hdmInfo);
// while(oculusRift.isInitialized()){
//
// }
oculusRift.destroy();
}
}
But I get this error
Exception in thread "main" java.lang.UnsatisfiedLinkError: de.fruitfly.ovr.OculusRift._initSubsystem()Z
at de.fruitfly.ovr.OculusRift._initSubsystem(Native Method)
at de.fruitfly.ovr.OculusRift.init(OculusRift.java:82)
at ec.test.test3.Test.main(Test.java:21)
Java Result: 1
I created and included a Library based on:
JRift-0.2.5.1.jar
JRiftLibrary-0.2.5.1.jar
JRiftLibrary-0.2.5.1-natives-windows.jar
From here
What is missing?
Edit:
Forced by extracting JRiftLibrary64.dll and adding its path explicitly to the java path
System.loadLibrary("JRiftLibrary64");
It works.. why does not work on the other way?
Have you tried JOVR? https://github.com/jherico/jovr
Here a complete example: https://github.com/jherico/jocular-examples
This library is simple, very solid and compatible with the current Oculus Runtime 1.8
Regards