问题描述
未找到com.jogamp.common.type.WriteCloneable的类文件
我还附上了错误的屏幕截图:
代码如下:
package com.jogamp.opengl;
import com.jogamp.opengl.*;
import com.jogamp.opengl.awt.GLCanvas;
import javax.swing.JFrame;
public class HelloWorld implements GLEventListener {
@Override
public void init(GLAutoDrawable arg0)
{
}
@Override
public void display(GLAutoDrawable drawable) {
final GL2 gl = drawable.getGL().getGL2();
//Draw H
gl.glBegin(GL2.GL_LInes);
gl.glVertex2d(-0.8,0.6);
gl.glVertex2d(-0.8,-0.6);
gl.glVertex2d(-0.8,0.0);
gl.glVertex2d(-0.4,0.6);
gl.glVertex2d(-0.4,-0.6);
gl.glEnd();
//Draw W
gl.glBegin(GL2.GL_LInes);
gl.glVertex2d(0.4,0.6);
gl.glVertex2d(0.4,-0.6);
gl.glVertex2d(0.4,-0.6);
gl.glVertex2d(0.6,0);
gl.glVertex2d(0.6,0);
gl.glVertex2d(0.8,-0.6);
gl.glVertex2d(0.8,0.6);
gl.glEnd();
}
@Override
public void reshape(GLAutoDrawable arg0,int arg1,int arg2,int arg3,int arg4)
{
}
@Override
public void dispose(GLAutoDrawable arg0)
{
}
public static void main(String[] args) {
final GLProfile gp = GLProfile.get(GLProfile.GL2);
GLCapabilities cap = new GLCapabilities(gp);
final GLCanvas gc = new GLCanvas(cap);
HelloWorld sq = new HelloWorld();
gc.addGLEventListener(sq);
gc.setSize(400,400);
final JFrame frame = new JFrame("Hello World");
frame.add(gc);
frame.setSize(500,400);
frame.setVisible(true);
}
}
请帮助我解决此问题。
注意:我下载了jogl-all.jar文件。然后我解压缩了。然后编写上面的代码。
解决方法
您需要包含gluegen-rt lib才能编译您的类。
此外,您无需解压缩jar文件。
使用-cp
变量将jar库添加到您的classpath:
javac -cp .:gluegen-rt.jar:jogl-all.jar HelloWorld.java
要运行您的示例,您还需要本机扩展。您可以找到它们here
注意:使用最新的JOGL库,尤其是在使用最新的Mac OS版本的情况下。
java -cp .:gluegen-rt.jar:jogl-all-natives-macosx-universal.jar:jogl-all.jar:gluegen-rt-natives-macosx-universal.jar HelloWorld
以下是输出:
,下载jogamp-fat.jar here(这是2020年10月的最新候选版本,否则,请在更新this one时使用),通常是在JOGL 2.4.0或任何更高版本发布时使用)。
编译为:
javac -cp .:jogamp-fat.jar HelloWorld.java
运行方式:
java -cp .:jogamp-fat.jar HelloWorld
您可以在我们的官方维基here中找到更多信息。 Windows用户必须将:
替换为;
。使用胖JAR更容易且更不容易出错,特别是对于新手而言,它同时包含Java库和所有JogAmp API(JOGL,JOCL,JOAL和GlueGen)的本机库。