JOGL2.0
でNeHeのlesson05を通そうとしているのだが意外に手強い。
なんとかclasspathの通し方あたりはクリアしたと思うのだが、
JOGL2.0がJOGL1系と比べてかなり変わっている。
まず、パッケージが配置換えになっている。
かつて
import net.java.games.jogl.*;
だったものが
import com.jogamp.opengl.util.Animator; import javax.media.opengl.*;
こんなんになっているみたいだ。
JOGL2.0向けのサンプルコードを探すのが先決のようだ。。。
サンプル
net.java.games.jogl.*
をimportしてないのは2.0のソースなのだろうか?
http://blog.rickyc.org/2009/07/16/jogl-hello-world/
http://ronor.blog81.fc2.com/blog-entry-47.html
http://schabby.de/jogl-example-hello-world/
http://journal.mycom.co.jp/column/jsr/047/index.html
http://www.land-of-kain.de/docs/jogl/
http://kur.dyndns.org/java/
http://d.hatena.ne.jp/SofiyaCat/20090426
JOGLインストールメモ
まず、
http://jogamp.org/deployment/archive/jogl-latest/build/
から
jogl-2.0-pre-20100611-windows-i586.zip
をダウンロード。
C:\jogl-2.0-pre-20100611-windows-i586に解凍。
CLASSPATHに
C:\jogl-2.0-windows-i586\lib\jogl.all.jar C:\jogl-2.0-windows-i586\lib\nativewindow.all.jar C:\jogl-2.0-windows-i586\lib\gluegen-rt.jar C:\jogl-2.0-windows-i586\lib\newt.all.jar
を入れる。
実行時は次のオプションを指定して、JOGLのJNIなdll群にPathを通す。
-Djava.library.path=C:\jogl-2.0-windows-i586\lib
こんなantになった。build.xml
<?xml version="1.0" encoding="UTF-8"?> <project name="helloant" default="compile"> <property name="src" value="src"/> <property name="classes" value="classes"/> <property name="jogl" value="C:/jogl-2.0-windows-i586"/> <target name="compile"> <javac srcdir="${src}" includeAntRuntime="no" destdir="${classes}"> <!--<compilerarg line="-J-Duser.language=en"/>--> <classpath> <pathelement location="${jogl}/lib/jogl.all.jar" /> <pathelement location="${jogl}/lib/nativewindow.all.jar" /> <pathelement location="${jogl}/lib/gluegen-rt.jar" /> <pathelement location="${jogl}/lib/newt.all.jar" /> </classpath> </javac> </target> <target name="run" depends="compile"> <java classname="JOGLAPP" fork="true" classpath="${classes}" > <sysproperty key="java.library.path" value="${jogl}/lib"/> <classpath> <pathelement location="${jogl}/lib/jogl.all.jar" /> <pathelement location="${jogl}/lib/nativewindow.all.jar" /> <pathelement location="${jogl}/lib/gluegen-rt.jar" /> <pathelement location="${jogl}/lib/newt.all.jar" /> </classpath> </java> </target> </project>
ようやく動作を確認できた。
やっと中身に入っていける・・・。
JOGL+Swing
import javax.media.opengl.GL2; import javax.media.opengl.GLAutoDrawable; import javax.media.opengl.GLEventListener; import javax.swing.JFrame; import javax.media.opengl.awt.GLJPanel; import com.sun.opengl.util.Animator; class MyGLEventListener implements GLEventListener { @Override public void init(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClearColor(0.0f, 1.0f, 0.0f, 0.0f); // init opengl here System.out.println("MyGLEventListener#init"); } @Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); // draw things here gl.glFinish(); } @Override public void dispose(GLAutoDrawable drawable) { } @Override public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { } } public class JOGLAPP { public static void main(String[] args) { // SWING JFrame frame=new JFrame("SWING"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); GLJPanel glArea=new GLJPanel(); frame.setContentPane(glArea); // frame.setSize(300, 300); frame.setVisible(true); glArea.addGLEventListener(new MyGLEventListener()); Animator anim = new Animator(glArea); anim.start(); } }