Advertisement
mikaelhc

Untitled

May 21st, 2013
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. package com.clcbio.api.structure.viewer.experimental;
  2.  
  3. import java.awt.event.WindowAdapter;
  4. import java.awt.event.WindowEvent;
  5.  
  6. import javax.media.opengl.GL;
  7. import javax.media.opengl.GL2;
  8. import javax.media.opengl.GLAutoDrawable;
  9. import javax.media.opengl.GLCapabilities;
  10. import javax.media.opengl.GLEventListener;
  11. import javax.media.opengl.GLProfile;
  12. import javax.media.opengl.awt.GLJPanel;
  13. import javax.swing.JFrame;
  14.  
  15. import com.jogamp.opengl.util.FPSAnimator;
  16.  
  17. public class SimpleJoglTest implements GLEventListener {
  18.  
  19. private float theta;
  20. private float s;
  21. private float c;
  22.  
  23. public static void main(String[] args) {
  24. GLCapabilities caps = new GLCapabilities(GLProfile.getDefault());
  25. caps.setNumSamples(2);
  26. caps.setSampleBuffers(true);
  27.  
  28. SimpleJoglTest test = new SimpleJoglTest();
  29. GLJPanel canvas = new GLJPanel(caps);
  30. // GLCanvas canvas = new GLCanvas(caps); <-- this works.
  31.  
  32. JFrame frame = new JFrame("GLJPanel Window Test");
  33. frame.setSize(300, 300);
  34. frame.add(canvas);
  35. frame.setVisible(true);
  36.  
  37. frame.addWindowListener(new WindowAdapter() {
  38. @Override
  39. public void windowClosing(WindowEvent e) {
  40. System.exit(0);
  41. }
  42. });
  43.  
  44. canvas.addGLEventListener(test);
  45. FPSAnimator anim = new FPSAnimator(canvas, 1);
  46. anim.start();
  47. }
  48.  
  49. @Override
  50. public void dispose(GLAutoDrawable drawable) {
  51. System.out.println("Dispose");
  52. }
  53.  
  54. @Override
  55. public void init(GLAutoDrawable drawable) {
  56. System.out.println("Init");
  57. }
  58.  
  59. @Override
  60. public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
  61. System.out.println("Reshape");
  62. }
  63.  
  64. public void drawSomething(GL2 gl) {
  65. gl.glBegin(GL.GL_TRIANGLES);
  66. gl.glColor3f(1, 0, 0);
  67. gl.glVertex3f(-c, -c, 0);
  68. gl.glColor3f(0, 1, 0);
  69. gl.glVertex3f(0, c, 0);
  70. gl.glColor3f(0, 0, 1);
  71. gl.glVertex3f(s, -s, 0);
  72. gl.glEnd();
  73. }
  74.  
  75. @Override
  76. public void display(GLAutoDrawable drawable) {
  77. theta += 0.1;
  78. s = (float) Math.sin(theta);
  79. c = (float) Math.cos(theta);
  80.  
  81. GL2 gl = drawable.getGL().getGL2();
  82. gl.glClearColor(1.0f, 0.0f, 1.0f, 1.0f);
  83. gl.glClear(GL.GL_COLOR_BUFFER_BIT);
  84.  
  85. drawSomething(gl);
  86. }
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement