daily pastebin goal
35%
SHARE
TWEET

Untitled

a guest Feb 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.awt.Dimension;
  2. import java.awt.EventQueue;
  3. import java.awt.Toolkit;
  4.  
  5. import javax.swing.JFrame;
  6.  
  7. import com.jogamp.opengl.GL2;
  8. import com.jogamp.opengl.GLAutoDrawable;
  9. import com.jogamp.opengl.GLCapabilities;
  10. import com.jogamp.opengl.GLEventListener;
  11. import com.jogamp.opengl.GLProfile;
  12. import com.jogamp.opengl.awt.GLCanvas;
  13. import com.jogamp.opengl.glu.GLU;
  14. import com.jogamp.opengl.util.FPSAnimator;
  15. import com.jogamp.opengl.util.gl2.GLUT;
  16.  
  17. public class a01 extends JFrame implements GLEventListener {
  18.  
  19.     private GL2 gl;
  20.     private GLU glu;
  21.     private GLUT glut;
  22.     private FPSAnimator animator;
  23.    
  24.     public a01(String string) {
  25.         super(string);
  26.         GLProfile profile=GLProfile.get(GLProfile.GL2);
  27.         GLCapabilities capabilities=new GLCapabilities(profile);
  28.         GLCanvas canvas=new GLCanvas(capabilities);
  29.         canvas.addGLEventListener(this);
  30.         add(canvas);
  31.         Toolkit kit=Toolkit.getDefaultToolkit();
  32.         Dimension d=kit.getScreenSize();
  33.         setBounds(d.width/4, d.height/4, d.width/2, d.height/2);
  34.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  35.         setVisible(true);
  36.         animator=new FPSAnimator(canvas,60);
  37.         animator.start();
  38.     }
  39.  
  40.     @Override
  41.     public void display(GLAutoDrawable drawable) {
  42.         gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
  43.         float a=2.0f;
  44.         int n=11;
  45.         gl.glRotatef(1.0f,0.0f,1.0f,0.0f);
  46.         gl.glBegin(GL2.GL_POINTS);
  47.                 for(int i=0;i<n;i++)
  48.                     for(int j=0;j<n;j++)
  49.                         for(int k=0;k<n;k++)
  50.                             gl.glVertex3f(-a/2+a*i/(n-1),-a/2+a*j/(n-1),-a/2+a*k/(n-1));
  51.         gl.glEnd();
  52.         gl.glFlush();
  53.        
  54.     }
  55.  
  56.     @Override
  57.     public void dispose(GLAutoDrawable drawable) {
  58.  
  59.     }
  60.  
  61.     @Override
  62.     public void init(GLAutoDrawable drawable) {
  63.         gl=drawable.getGL().getGL2();
  64.         glu=GLU.createGLU(gl);
  65.         glut=new GLUT();
  66.         gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
  67.     }
  68.  
  69.     @Override
  70.     public void reshape(GLAutoDrawable drawable, int x, int y, int width,
  71.             int height) {
  72.         gl.glViewport(0, 0, width, height);
  73.         if(height==0)
  74.             height=1;
  75.         float aspect=(float)width/height;
  76.         gl.glMatrixMode(GL2.GL_PROJECTION);
  77.         gl.glLoadIdentity();
  78.         glu.gluPerspective(45.0f,aspect,1.0f,10.0f);
  79.         glu.gluLookAt(0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
  80.         gl.glMatrixMode(GL2.GL_MODELVIEW);
  81.     }
  82.  
  83.     public static void main(String[] args) {
  84.         EventQueue.invokeLater(new Runnable() {
  85.            
  86.             @Override
  87.             public void run() {
  88.                 new a01("a01");
  89.             }
  90.         });
  91.     }
  92.  
  93. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top