GLWindow window; FPSAnimator animator; GLRenderer renderer; public Main() { initComponents(); window = GLWindow.create(new GLCapabilities(GLProfile.getDefault())); window.setTitle("OpenGL prova - GLWindow"); window.setSize(800, 600); renderer = new GLRenderer(); window.addGLEventListener(renderer); animator = new FPSAnimator(window, 60, true); }
private void btnHideActionPerformed(java.awt.event.ActionEvent evt) { window.setVisible(false); } private void btnShowActionPerformed(java.awt.event.ActionEvent evt) { window.setVisible(true); } private void btnStartActionPerformed(java.awt.event.ActionEvent evt) { animator.start(); } private void btnStopActionPerformed(java.awt.event.ActionEvent evt) { animator.stop(); } private void btnFullscreenActionPerformed(java.awt.event.ActionEvent evt) { window.setFullscreen(btnFullscreen.isSelected()); }
double a = 0.0; @Override public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL2.GL_COLOR_BUFFER_BIT); gl.glBegin(GL2.GL_QUADS); gl.glColor3f(1, 1, 1); for (int i = -4; i < 4; i++) { for (int j = -4; j < 4; j++) { if ((i + j) % 2 != 0) { gl.glVertex2d(i / 4.0, j / 4.0); gl.glVertex2d(i / 4.0 + 0.25, j / 4.0); gl.glVertex2d(i / 4.0 + 0.25, j / 4.0 + 0.25); gl.glVertex2d(i / 4.0, j / 4.0 + 0.25); } } } gl.glEnd(); // inserire un rombo rosso che si sposta da sinistra a destra a += 0.01; }