2010-12-28 6 views
3

私はいくつかのことを作成するためにJOGLを使用していますが、私が見つけることができるドキュメンテーションを見てきました。NEWTを使用してJOGLウィンドウを作成する - 例?

簡単なチュートリアルJOGL版のキャンバスを使用するとパフォーマンス上の問題が発生する可能性がありますが、代わりにNEWTを使用する必要があります。しかし、それぞれのチュートリアル/ FAQはキャンバスの使用に続きます!あるいは、NEWTを使ってウィンドウを作成する方法をいくつかご紹介しますが、少なくとも私のマシンでは正しく実行することができません。

NEWTメソッドを使用してJOGLでウィンドウの作成とレンダリングを正しく実装する方法の良い例がありますか?私はCanvasと比べてどのように機能するのかも分からないので、2つの違いと、ウィンドウを作成/管理/レンダリングするための典型的なレイアウトのレイアウトの説明が理想的です。

ちょっと迷って便利なものが見つかりません。誰かが前に何かを見いだすことを願って!

答えて

0

は、JOGLのjunitテストを見て、NEWT APIの大部分をカバーしています。

0

このチュートリアルは私を助けました。詳しくは、3.9 - Yet Another Tutorial on JOGLを参照してください。 documentationも便利です。添付の例を見てください。

JOGL2NewtDemo.java

import javax.media.opengl.GLCapabilities; 
import javax.media.opengl.GLProfile; 
import com.jogamp.newt.event.WindowAdapter; 
import com.jogamp.newt.event.WindowEvent; 
import com.jogamp.newt.opengl.GLWindow; 
import com.jogamp.opengl.util.FPSAnimator; 

/** 
* A program that draws with JOGL in a NEWT GLWindow. 
* 
*/ 
public class JOGL2NewtDemo { 
    private static String TITLE = "JOGL 2 with NEWT"; // window's title 
    private static final int WINDOW_WIDTH = 640; // width of the drawable 
    private static final int WINDOW_HEIGHT = 480; // height of the drawable 
    private static final int FPS = 60; // animator's target frames per second 

    static { 
     GLProfile.initSingleton(); // The method allows JOGL to prepare some Linux-specific locking optimizations 
    } 

    /** 
    * The entry main() method. 
    */ 
    public static void main(String[] args) { 
     // Get the default OpenGL profile, reflecting the best for your running platform 
     GLProfile glp = GLProfile.getDefault(); 
     // Specifies a set of OpenGL capabilities, based on your profile. 
     GLCapabilities caps = new GLCapabilities(glp); 
     // Create the OpenGL rendering canvas 
     GLWindow window = GLWindow.create(caps); 

     // Create a animator that drives canvas' display() at the specified FPS. 
     final FPSAnimator animator = new FPSAnimator(window, FPS, true); 

     window.addWindowListener(new WindowAdapter() { 
      @Override 
      public void windowDestroyNotify(WindowEvent arg0) { 
       // Use a dedicate thread to run the stop() to ensure that the 
       // animator stops before program exits. 
       new Thread() { 
        @Override 
        public void run() { 
         if (animator.isStarted()) 
          animator.stop(); // stop the animator loop 
         System.exit(0); 
        } 
       }.start(); 
      } 
     }); 

     window.addGLEventListener(new JOGL2Renderer()); 
     window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT); 
     window.setTitle(TITLE); 
     window.setVisible(true); 
     animator.start(); // start the animator loop 
    } 
} 

JOGL2Renderer.java

import javax.media.opengl.GL; 
import javax.media.opengl.GL2; 
import javax.media.opengl.GLAutoDrawable; 
import javax.media.opengl.GLEventListener; 

/** 
* Class handles the OpenGL events to render graphics. 
* 
*/ 
public class JOGL2Renderer implements GLEventListener { 
    private double theta = 0.0f; // rotational angle 

    /** 
    * Called back by the drawable to render OpenGL graphics 
    */ 
    @Override 
    public void display(GLAutoDrawable drawable) { 
     GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context 

     gl.glClear(GL.GL_COLOR_BUFFER_BIT); // clear background 
     gl.glLoadIdentity();     // reset the model-view matrix  

      // Rendering code - draw a triangle 
     float sine = (float)Math.sin(theta); 
     float cosine = (float)Math.cos(theta); 
     gl.glBegin(GL.GL_TRIANGLES); 
     gl.glColor3f(1, 0, 0); 
     gl.glVertex2d(-cosine, -cosine); 
     gl.glColor3f(0, 1, 0); 
     gl.glVertex2d(0, cosine); 
     gl.glColor3f(0, 0, 1); 
     gl.glVertex2d(sine, -sine); 
     gl.glEnd(); 

     update(); 
    } 

    /** 
    * Update the rotation angle after each frame refresh 
    */ 
    private void update() { 
     theta += 0.01; 
    } 

    /*... Other methods leave blank ...*/ 
} 
関連する問題