Setup OpenGL with Java〜JOGLを使う準備 for Eclipse〜

イントロダクション

ゲームというより、タスク・スケジュール・ロードマップ管理アプリケーションの作成を行います。(Swingの扱い方やオブジェクト指向についてもやります)

使うのはJOGL (Java版のOpenGL)です。土台になるのはSwingです。つまり画面の外側はSwingで内側(コンポーネント)はJOGLで表示します。

Introduction

I will create a Task, Schedule and Roadmap Manager using java. (I will write Swing and Object-orientation).

And Using Swing and JOGL(OpenGL in java). I mean that Swing create Frame of view, JOGL create Content of view.

インストール(how to Install)

こちらのページを参考にやります。( see this page)

インストール方法(How to install)

https://www.tutorialspoint.com/jogl/jogl_installation.htm

ダウンロード(Download)

http://jogamp.org/deployment/jogamp-current/archive/

ダウンロードするファイル一覧(List of download)

  1. jogamp-all-platforms.7z
  2. glugen-javadoc.7z
  3. jogl-javadocs.7z

1〜3のファイルにビルドパスを通す(Set to buildpath in Eclipse)

  • gluegenrt.jar
  • jogl-all.jar
  • gluegen-rt-natives-macXXX.jar
  • jogl-all-natives-macXXX

ついでなので、LWJGLのファイルもビルドパスを通します。ファイルのダウンロードはこちら JOGLはこのフレームワークに同梱されています。

1.Eclipseの設定を開きます。

2.Java-BuildPath-UserLibralyを開きます。

3.ライブラリを作成します。(Newボタンを押下)

そして、Editを押下してライブラリにLWJGLのファイルを全部追加します。

※頭に「lwjgl-」がついているファイル全てです。

サンプルコード:ここのページからコピーしたものをちょいと修正(赤文字)

Sample Code : little bit change source from this page (red charactor is changed)

package zenryokuservice.gui.mtm;
import javax.swing.JFrame;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLCanvas;

public class MultiTaskManager implements GLEventListener {

   public void display(GLAutoDrawable arg0) {
      // method body
   }

   public void dispose(GLAutoDrawable arg0) {
      //method body
   }

   public void init(GLAutoDrawable arg0) {
      // method body
   }

   public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) {
      // method body
   }

   public static void main(String[] args) {

      //getting the capabilities object of GL2 profile
      final GLProfile profile = GLProfile.get(GLProfile.GL2);
      GLCapabilities capabilities = new GLCapabilities(profile);
      // The canvas
      final GLCanvas glcanvas = new GLCanvas(capabilities);
      MultiTaskManager b = new MultiTaskManager();
      glcanvas.addGLEventListener(b);
      glcanvas.setSize(400, 400);

      //creating frame
      final JFrame frame = new JFrame (" Basic Frame");
      //adding canvas to it
      frame.getContentPane().add(glcanvas);
      frame.setSize(frame.getContentPane().getPreferredSize());
      // It's impotant this is mwaning "window close and stop JVM"
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

   }//end of main
}//end of classimport    

実行した時のキャプチャ

次回(Next)

実際に描画をやってみます。実際には2D描画です。

I will create program for draw 2D Line.

実際は2D表示(2D drawing)


[rakuten ids="advancedselect:10000013"]


投稿者:

takunoji

音響、イベント会場設営業界からIT業界へ転身。現在はJava屋としてサラリーマンをやっている。自称ガテン系プログラマー(笑) Javaプログラミングを布教したい、ラスパイとJavaの相性が良いことに気が付く。 Spring framework, Struts, Seaser, Hibernate, Playframework, JavaEE6, JavaEE7などの現場経験あり。 SQL, VBA, PL/SQL, コマンドプロント, Shellなどもやります。

コメントを残す