Advertisement
alexFilimon

Untitled

Mar 30th, 2020
343
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1.  
  2. import javax.swing.JFrame;
  3.  
  4. import com.jogamp.opengl.GL;
  5. import com.jogamp.opengl.GL2;
  6. import com.jogamp.opengl.GLAutoDrawable;
  7. import com.jogamp.opengl.GLCapabilities;
  8. import com.jogamp.opengl.GLEventListener;
  9. import com.jogamp.opengl.GLProfile;
  10. import com.jogamp.opengl.awt.GLCanvas;
  11.  
  12. public class Chess implements GLEventListener {
  13. @Override
  14. public void init(GLAutoDrawable glAutoDrawable) {
  15.  
  16. }
  17.  
  18. @Override
  19. public void dispose(GLAutoDrawable glAutoDrawable) {
  20.  
  21. }
  22.  
  23. @Override
  24. public void display(GLAutoDrawable glAutoDrawable) {
  25. final GL2 gl = glAutoDrawable.getGL().getGL2();
  26. boolean reverse = false;
  27.  
  28. gl.glCullFace(GL.GL_FRONT);
  29.  
  30. gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2.GL_FILL);
  31.  
  32. for(float f = -1.0f; f <= 1.0f; f += 0.25){
  33. drawOneRow(gl, f, reverse);
  34. reverse = !reverse;
  35. }
  36. }
  37.  
  38. public void drawOneRow(GL2 gl, float row, boolean reverse){
  39. boolean black = reverse;
  40. for(float f = -1.0f; f <= 1.0f; f += 0.25){
  41. if(!black){
  42. gl.glDisable(GL.GL_CULL_FACE);
  43. gl.glColor3f(1.0f,1.0f,1.0f);
  44. }
  45. else{
  46. gl.glEnable(GL.GL_CULL_FACE);
  47. gl.glColor3f(0.0f,0.0f,0.0f);
  48. }
  49.  
  50. gl.glBegin(gl.GL_POLYGON);
  51. gl.glVertex3f(f, row,0.0f);
  52. gl.glVertex3f((f + 0.25f), row,0.0f);
  53. gl.glVertex3f((f + 0.25f), (row + 0.25f),0.0f);
  54. gl.glVertex3f(f, (row + 0.25f),0.0f);
  55. gl.glEnd();
  56.  
  57. black = !black;
  58. }
  59. }
  60.  
  61. @Override
  62. public void reshape(GLAutoDrawable glAutoDrawable, int i, int i1, int i2, int i3) {
  63.  
  64. }
  65.  
  66.  
  67. public static void main( String[] args ) {
  68.  
  69. //getting the capabilities object of GL2 profile
  70. final GLProfile profile = GLProfile.get( GLProfile.GL2 );
  71. GLCapabilities capabilities = new GLCapabilities(profile);
  72.  
  73. // The canvas
  74. final GLCanvas glcanvas = new GLCanvas( capabilities );
  75. Chess chess = new Chess();
  76. glcanvas.addGLEventListener( chess );
  77. glcanvas.setSize(400, 400);
  78.  
  79. //creating temalab2
  80. final JFrame frame = new JFrame( "Chess" );
  81.  
  82. //adding canvas to temalab2
  83. frame.getContentPane().add( glcanvas );
  84. frame.setSize(frame.getContentPane().getPreferredSize() );
  85. frame.setVisible( true );
  86. }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement