• 課題リンク
  • ソース:

    pre> import java.applet.Applet; import java.awt.Graphics; import java.awt.event.ComponentEvent; import java.awt.event.ComponentListener;

import jgl.GL; import jgl.GLU; import jgl.GLAUX;

public class testjgl extends Applet

     implements ComponentListener {
     // must use GL to use jGL.....
     // and use GLU to use the glu functions....
     // remember to give GL to initialize GLU
     // and use GLAUX to use the aux functions.....
     // remember to give GL to initialize GLAUX
     GL myGL = new GL ();
     GLU myGLU = new GLU (myGL);
     GLAUX myAUX = new GLAUX (myGL);
     private void myinit () {
         myGL.glShadeModel (GL.GL_SMOOTH); /* GL_SMOOTH is the default */
     }
     private void triangle () {
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (2.0f, 22.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 22.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (2.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (12.0f, 12.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 22.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (2.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (12.0f, 12.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 22.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (22.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (22.0f, 22.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 22.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (22.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (2.0f, 2.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 2.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (2.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (12.0f, 12.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 2.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (2.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (12.0f, 12.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 2.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (22.0f, 12.0f);
         myGL.glEnd ();
         myGL.glBegin (GL.GL_TRIANGLES);
         myGL.glColor3f (1.0f, 0.0f, 0.0f);
         myGL.glVertex2f (22.0f, 2.0f);
         myGL.glColor3f (0.0f, 1.0f, 0.0f);
         myGL.glVertex2f (12.0f, 2.0f);
         myGL.glColor3f (0.0f, 0.0f, 1.0f);
         myGL.glVertex2f (22.0f, 12.0f);
         myGL.glEnd ();
     }
     private void display () {
         myGL.glClear (GL.GL_COLOR_BUFFER_BIT);
         triangle ();
         myGL.glFlush ();
     }
     public void componentMoved (ComponentEvent e) {}
     public void componentShown (ComponentEvent e) {}
     public void componentHidden (ComponentEvent e) {}
     public void componentResized (ComponentEvent e) {
         // get window width and height by myself
         myReshape (getSize ().width, getSize ().height);
         display ();
         repaint ();
     }
     private void myReshape (int w, int h) {
         myGL.glViewport (0, 0, w, h);
         myGL.glMatrixMode (GL.GL_PROJECTION);
         myGL.glLoadIdentity ();
         if (w <= h) {
             myGLU.gluOrtho2D (0.0, 30.0, 0.0, 30.0 * (float)h/(float)w);
         } else {
             myGLU.gluOrtho2D (0.0, 30.0 * (float)w/(float)h,  0.0, 30.0);
         }
         myGL.glMatrixMode (GL.GL_MODELVIEW);
     }
     public void update (Graphics g) {
         // skip the clear screen command....
         paint (g);
     }
     public void paint (Graphics g) {
         myGL.glXSwapBuffers (g, this);
     }
     public void init () {
         myAUX.auxInitPosition (0, 0, 500, 500);
         myAUX.auxInitWindow (this);
         myinit ();
         // as call auxReshapeFunc()
         addComponentListener (this);
         myReshape (getSize ().width, getSize ().height);
         // call display as call auxIdleFunc(display)
         display ();
     }

}

/pre>


ソフトウェア基礎演習2/03/最終レポート


トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2013-06-20 (木) 14:45:27 (2280d)