イントロダクション(Introduction)
前回、JOGLのインストールをして開発の準備を行いました。
Last time, I wrote setting up JOGL. and prepare develop OpenGL in java.
ドキュメントを読み進める(Read Doc)
日本語:PDFはこちら → 申し訳ないが参考になりませんでした。。。
English : this PDF.→ こちらを参考にします。
メインイベント( Let's enjoy JOGL)
JOGLを使用して実装を行います。Swingなど初めてですって方も問題ありません。自分も初めての実装です(笑)。
Let's implement using JOGL!. do not mind if you have not know swing and more. I have implemented first JOGL(笑).
実装したコード(Implementation)
package zenryokuservice.gui.mtm; import javax.swing.JFrame; import com.jogamp.opengl.GL2; 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 init(GLAutoDrawable drawable) { // 画面を初期化する GL2 gl = drawable.getGL().getGL2(); // black background(黒で初期化) gl.glClearColor(0, 0, 0, 0); } /** * Draw 2D graphics "H" * 2次元描画で"H”を描く */ public void display(GLAutoDrawable drawable) { // 表示 start GL(GL2 or GL2) GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); // draw in red gl.glColor3d(1, 0, 0); // draw "H" gl.glBegin(GL2.GL_LINES); // raw line gl.glVertex2d(-0.8, 0.8); gl.glVertex2d(-0.8, -0.8); gl.glVertex2d(-0.8, 0.0); gl.glVertex2d(-0.4, 0.0); gl.glVertex2d(-0.4, 0.8); gl.glVertex2d(-0.4, -0.8); // stop draw gl.glEnd(); } public void dispose(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()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }//end of main }//end of classimport
実行結果
参考にしたPDFには問題が載っています。
This PDF have a Question as bellow.
<Question: 問題>
"H"は描いたけれどもう1つ"W"を描きたいのですがどの用に描いたら良いでしょうか?描いてください。
- This was code for drawing an “H”.
- How to draw an “W” besides it?
- Which coordinate system is used?
次回(Next)
作成したコードを解析します。(Analyze this code)