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: 4084
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:
 
 
 
Use of some of the gluQuadric* routines E-mail
User Rating: / 7
PoorBest 

This program demonstrates the use of some of the gluQuadric* routines. Quadric objects are created with some quadric properties and the callback routine to handle errors. Note that the cylinder has no top or bottom and the circle has a hole in it.

The example is ported from C examples in the OpenGL Programming Guide (known as the "red book").


Image

-> Copyright and Permission Notice

package glredbook12x;

import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.swing.JFrame;

import com.sun.opengl.util.GLUT;

/**
 * This program demonstrates the use of some of the gluQuadric* routines.
 * Quadric objects are created with some quadric properties and the callback
 * routine to handle errors. Note that the cylinder has no top or bottom and the
 * circle has a hole in it.
 
 @author Kiet Le (java port)
 */

public class quadric
  extends JFrame
    implements GLEventListener
    , KeyListener 
{
  private GLCapabilities caps;
  private GLCanvas canvas;
  private GLU glu;
  private GLUT glut;

  private int startList;


  public quadric()
  {
    super("quadric");

    caps = new GLCapabilities();
    canvas = new GLCanvas(caps);
    canvas.addGLEventListener(this);
    canvas.addKeyListener(this);

    add(canvas);
  }

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

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

  public void init(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    glu = new GLU();
    glut = new GLUT();

    GLUquadric qobj;
    float mat_ambient[] =
    0.5f0.5f0.5f1.0f };
    float mat_specular[] =
    1.0f1.0f1.0f1.0f };
    float mat_shininess[] =
    50.0f };
    float light_position[] =
    1.0f1.0f1.0f0.0f };
    float model_ambient[] =
    0.5f0.5f0.5f1.0f };

    gl.glClearColor(0.0f0.0f0.0f0.0f);

    gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, mat_ambient, 0);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, mat_specular, 0);
    gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, mat_shininess, 0);
    gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, light_position, 0);
    gl.glLightModelfv(GL.GL_LIGHT_MODEL_AMBIENT, model_ambient, 0);

    gl.glEnable(GL.GL_LIGHTING);
    gl.glEnable(GL.GL_LIGHT0);
    gl.glEnable(GL.GL_DEPTH_TEST);

    /*
     * Create 4 display lists, each with a different quadric object. Different
     * drawing styles and surface normal specifications are demonstrated.
     */
    startList = gl.glGenLists(4);
    qobj = glu.gluNewQuadric();

    /*
     * glu.gluQuadricCallback(qobj, GLU.GLU_ERROR, errorCallback); <br>
     * Quadric call backs have yet been implemented in JOGL.
     * But this program still work.
     */
    glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL)/* smooth shaded */
    glu.gluQuadricNormals(qobj, GLU.GLU_SMOOTH);
    gl.glNewList(startList, GL.GL_COMPILE);
    glu.gluSphere(qobj, 0.751510);
    gl.glEndList();

    glu.gluQuadricDrawStyle(qobj, GLU.GLU_FILL)/* flat shaded */
    glu.gluQuadricNormals(qobj, GLU.GLU_FLAT);
    gl.glNewList(startList + 1, GL.GL_COMPILE);
    glu.gluCylinder(qobj, 0.50.31.0155);
    gl.glEndList();

    glu.gluQuadricDrawStyle(qobj, GLU.GLU_LINE)/* all polygons wireframe */
    glu.gluQuadricNormals(qobj, GLU.GLU_NONE);
    gl.glNewList(startList + 2, GL.GL_COMPILE);
    glu.gluDisk(qobj, 0.251.0204);
    gl.glEndList();

    glu.gluQuadricDrawStyle(qobj, GLU.GLU_SILHOUETTE)/* boundary only */
    glu.gluQuadricNormals(qobj, GLU.GLU_NONE);
    gl.glNewList(startList + 3, GL.GL_COMPILE);
    glu.gluPartialDisk(qobj, 0.01.02040.0225.0);
    gl.glEndList();

  }

  public void display(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();

    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    gl.glPushMatrix();

    gl.glEnable(GL.GL_LIGHTING);
    gl.glShadeModel(GL.GL_SMOOTH);
    gl.glTranslatef(-1.0f, -1.0f0.0f);
    gl.glCallList(startList);

    gl.glShadeModel(GL.GL_FLAT);
    gl.glTranslatef(0.0f2.0f0.0f);
    gl.glPushMatrix();
    gl.glRotatef(300.0f1.0f0.0f0.0f);
    gl.glCallList(startList + 1);
    gl.glPopMatrix();

    gl.glDisable(GL.GL_LIGHTING);
    gl.glColor3f(0.0f1.0f1.0f);
    gl.glTranslatef(2.0f, -2.0f0.0f);
    gl.glCallList(startList + 2);

    gl.glColor3f(1.0f1.0f0.0f);
    gl.glTranslatef(0.0f2.0f0.0f);
    gl.glCallList(startList + 3);

    gl.glPopMatrix();
    gl.glFlush();

  }

  public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h)
  {
    GL gl = drawable.getGL();

    gl.glViewport(00, w, h);
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    if (w <= hgl.glOrtho(-2.52.5, -2.5 (floath / (floatw,
        2.5 (floath / (floatw, -10.010.0);
    else gl.glOrtho(-2.5 (floatw / (floath, 2.5 (floatw / (floath,
        -2.52.5, -10.010.0);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glLoadIdentity();
  }

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

  public void keyTyped(KeyEvent key)
  {
  }

  public void keyPressed(KeyEvent key)
  {
    switch (key.getKeyChar()) {

      case KeyEvent.VK_ESCAPE:
        System.exit(0);
        break;

      default:
        System.out.println("nothin pressed.");
        break;
    }
  }

  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.