java left logo
java middle logo
java right logo
 

Home arrow Other API Tips
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4096
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
How to create a display list in JOGL E-mail
User Rating: / 8
PoorBest 

This program demonstrates the creation of a display list. The example is ported from C examples in the OpenGL Programming Guide (known as the "red book").


Image

-> Copyright and Permission Notice

package glredbook11;

import javax.swing.*;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import java.awt.event.*;

/**
 * This program demonstrates the creation of a display list.
 
 @author Kiet Le (java port)
 */
public class torus
  extends JFrame
    implements GLEventListener, KeyListener
{
  private GLCanvas canvas;
  private GLCapabilities caps;
  private int theTorus;
  private KeyEvent key; 
  private float angleX = 30f;
  private float angleY = 30f;

  public torus()
  {
    super("torus");
    
    caps = new GLCapabilities();
    canvas = new GLCanvas(caps);
    canvas.addGLEventListener(this);
    canvas.addKeyListener(this);
    
    getContentPane().add(canvas);
  }

  public void run()
  {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(512512);
    setLocationRelativeTo(null);
    setVisible(true);
  }

  public static void main(String[] args)
  {
    new torus().run();
  }

  private void drawTorus(GL gl, int numc, int numt)
  {
    double s, t, x, y, z, twopi = * Math.PI;
    for (int i = 0; i < numc; i++)
    {
      gl.glBegin(GL.GL_QUAD_STRIP);
      for (int j = 0; j <= numt; j++)
      {
        for (int k = 1; k >= 0; k--)
        {
          s = (i + k% numc + 0.5;
          t = j % numt;
          x = (0.1 * Math.cos(s * twopi / numc))
              * Math.cos(t * twopi / numt);
          y = (0.1 * Math.cos(s * twopi / numc))
              * Math.sin(t * twopi / numt);
          z = 0.1 * Math.sin(s * twopi / numc);
          gl.glVertex3d(x, y, z);
        }// k
      }// j
      gl.glEnd();
    }// i
  }

  public void init(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    
    theTorus = gl.glGenLists(1);
    gl.glNewList(theTorus, GL.GL_COMPILE);
    drawTorus(gl, 825);
    gl.glEndList();
    
    gl.glShadeModel(GL.GL_FLAT);
    gl.glClearColor(0.0f0.0f0.0f0.0f);
  }

  public void display(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    GLU glu = new GLU();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    //
    if (key != null)
    {
      switch (key.getKeyCode()) {
        case KeyEvent.VK_X:
          gl.glRotated(angleX, 1f0f0f);  
          break;
        case KeyEvent.VK_Y:
          gl.glRotated(angleY, 0f1f0f);  
          break;
        case KeyEvent.VK_I:
          gl.glLoadIdentity();
          glu.gluLookAt(0010000010);
          break;
        default:
          break;
      }
    }

    gl.glColor3f(1.0f1.0f1.0f);
    gl.glCallList(theTorus);
    gl.glPopMatrix();
    gl.glFlush();
  }

  public void reshape(GLAutoDrawable drawable, int x, int y, int width,
      int height)
  {
    GL gl = drawable.getGL();
    GLU glu = new GLU();
    //
    gl.glViewport(00, width, height);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(30(floatwidth / (floatheight, 1.0100.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(0010000010);
  }

  public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
      boolean deviceChanged)
  {
  }

  public void keyTyped(KeyEvent key)
  {
  }

  public void keyPressed(KeyEvent key)
  {
    this.key = key;
    switch (key.getKeyCode()) {
      case KeyEvent.VK_ESCAPE:
        System.exit(0);
        break;

      default:
        break;
    }
    canvas.display();
  }

  public void keyReleased(KeyEvent key)
  {
  }
}

Source: Kiet Le's The Red Book Examples using JOGL


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.