java left logo
java middle logo
java right logo
 

Home arrow Other API Tips arrow JOGL arrow Demonstration of point parameters and their effect on point primitives
 
 
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: 4089
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:
 
 
 
Demonstration of point parameters and their effect on point primitives E-mail
User Rating: / 0
PoorBest 

This program demonstrates point parameters and their effect on point primitives. 250 points are randomly generated within a 10 by 10 by 40 region, centered at the origin. In some modes (including the default), points that are closer to the viewer will appear larger.

Pressing the 'l', 'q', and 'c' keys switch the point parameters attenuation mode to linear, quadratic, or constant, respectively.

Pressing the 'f' and 'b' keys move the viewer forward and backwards. In either linear or quadratic attenuation mode, the distance from the viewer to the point will change the size of the point primitive.

Pressing the '+' and '-' keys will change the current point size. In this program, the point size is bounded, so it will not get less than 2.0, nor greater than GL_POINT_SIZE_MAX.

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


Image

-> Copyright and Permission Notice

package glredbook1314;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

import java.nio.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import com.sun.opengl.util.*;

/**
 * This program demonstrates point parameters and their effect on point
 * primitives. 250 points are randomly generated within a 10 by 10 by 40 region,
 * centered at the origin. In some modes (including the default), points that
 * are closer to the viewer will appear larger.<br>
 <br>
 * Pressing the 'l', 'q', and 'c' keys switch the point parameters attenuation
 * mode to linear, quadratic, or constant, respectively. <br>
 * Pressing the 'f' and 'b' keys move the viewer forward and backwards. In
 * either linear or quadratic attenuation mode, the distance from the viewer to
 * the point will change the size of the point primitive. <br>
 * Pressing the '+' and '-' keys will change the current point size. In this
 * program, the point size is bounded, so it will not get less than 2.0, nor
 * greater than GL_POINT_SIZE_MAX.
 
 @author Kiet Le (Java port)
 */
public class pointp extends JFrame implements GLEventListener//
    , KeyListener //
// , MouseListener //
// , MouseMotionListener //
// , MouseWheelListener
{
  private GLCapabilities caps;

  private GLCanvas canvas;

  private GLU glu;

  private GLUT glut;

  
  private static float psize = 7.0f;

  private static float pmax[] new float[1];

  private static float constant[] 1.0f0.0f0.0f };

  private static float linear[] 0.0f0.12f0.0f };

  private static float quadratic[] 0.0f0.0f0.01f };

  private KeyEvent key;


  public pointp() {
    super("piontp");
    
    caps = new GLCapabilities();
    caps.setSampleBuffers(true);

    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 pointp().run();
  }

  public void init(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();
    glu = new GLU();
    glut = new GLUT();
    //
    gl.glNewList(1, GL.GL_COMPILE);
    gl.glBegin(GL.GL_POINTS);
    for (int i = 0; i < 250; i++) {
      gl.glColor3f(1.0f(floatMath.random()(floatMath.random());
      /*
       * randomly generated vertices: -5 < x < 5; -5 < y < 5; -5 < z < -45
       */
      gl.glVertex3f((float) ((Math.random() (- -5)) 5.0f),//
          (float) ((Math.random() (- -5)) 5.0f),//
          (float) (((Math.random() (- -5)) 5.0f)));
    }
    gl.glEnd();
    gl.glEndList();

    gl.glEnable(GL.GL_DEPTH_TEST);
    gl.glEnable(GL.GL_POINT_SMOOTH);
    gl.glEnable(GL.GL_BLEND);
    gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
    gl.glPointSize(psize);
    gl.glGetFloatv(GL.GL_POINT_SIZE_MAX_EXT, pmax, 0);

    gl.glPointParameterfvEXT(GL.GL_DISTANCE_ATTENUATION_EXT, linear, 0);
    gl.glPointParameterfEXT(GL.GL_POINT_FADE_THRESHOLD_SIZE_EXT, 2.0f);

  }

  public void display(GLAutoDrawable drawable) {
    GL gl = drawable.getGL();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

    if (key != null)
      switch (key.getKeyChar()) {
      case 'b':
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glTranslatef(0.0f0.0f, -0.5f);

        break;
      case 'c':
        gl.glPointParameterfvEXT(GL.GL_DISTANCE_ATTENUATION_EXT,
            constant, 0);

        break;
      case 'f':
        gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glTranslatef(0.0f0.0f0.5f);

        break;
      case 'l':
        gl.glPointParameterfvEXT(GL.GL_DISTANCE_ATTENUATION_EXT,
            linear, 0);

        break;
      case 'q':
        gl.glPointParameterfvEXT(GL.GL_DISTANCE_ATTENUATION_EXT,
            quadratic, 0);

        break;
      case '+':
        if (psize < (pmax[01.0f))
          psize = psize + 1.0f;
        gl.glPointSize(psize);

        break;
      case '-':
        if (psize >= 2.0f)
          psize = psize - 1.0f;
        gl.glPointSize(psize);

        break;

      }

    gl.glCallList(1);
    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();
    glu.gluPerspective(35(floatw / h, 0.25200);
    gl.glMatrixMode(GL.GL_MODELVIEW);
    gl.glTranslatef(0.0f0.0f, -10.0f);

  }

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

  public void keyTyped(KeyEvent key) {
  }

  public void keyPressed(KeyEvent key) {
    this.key = key;
    switch (key.getKeyChar()) {

    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.