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: 4100
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:
 
 
 
Polygon Stippling in JOGL E-mail
User Rating: / 4
PoorBest 

Polygon stippling, like line stippling (see glLineStipple), masks out certain fragments produced by rasterization, creating a pattern. This program demonstrates polygon stippling in JOGL. The example is ported from C examples in the OpenGL Programming Guide (known as the "red book").


Image

-> Copyright and Permission Notice

package glredbook10;

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 polygon stippling.
 
 @author Kiet Le (Java conversin)
 */
public class polys
  extends JFrame
    implements GLEventListener, KeyListener
{
  private GLU glu;
  private GLUT glut;
  private GLCapabilities caps;
  private GLCanvas canvas;
  private FPSAnimator animator;
  private byte fly[] =
  { (byte0x00(byte0x00(byte0x00(byte0x00(byte0x00,
    (byte0x00(byte0x00(byte0x00(byte0x03(byte0x80,
    (byte0x01(byte0xC0(byte0x06(byte0xC0(byte0x03,
    (byte0x60(byte0x04(byte0x60(byte0x06(byte0x20,
    (byte0x04(byte0x30(byte0x0C(byte0x20(byte0x04,
    (byte0x18(byte0x18(byte0x20(byte0x04(byte0x0C,
    (byte0x30(byte0x20(byte0x04(byte0x06(byte0x60,
    (byte0x20(byte0x44(byte0x03(byte0xC0(byte0x22,
    (byte0x44(byte0x01(byte0x80(byte0x22(byte0x44,
    (byte0x01(byte0x80(byte0x22(byte0x44(byte0x01,
    (byte0x80(byte0x22(byte0x44(byte0x01(byte0x80,
    (byte0x22(byte0x44(byte0x01(byte0x80(byte0x22,
    (byte0x44(byte0x01(byte0x80(byte0x22(byte0x66,
    (byte0x01(byte0x80(byte0x66(byte0x33(byte0x01,
    (byte0x80(byte0xCC(byte0x19(byte0x81(byte0x81,
    (byte0x98(byte0x0C(byte0xC1(byte0x83(byte0x30,
    (byte0x07(byte0xe1(byte0x87(byte0xe0(byte0x03,
    (byte0x3f(byte0xfc(byte0xc0(byte0x03(byte0x31,
    (byte0x8c(byte0xc0(byte0x03(byte0x33(byte0xcc,
    (byte0xc0(byte0x06(byte0x64(byte0x26(byte0x60,
    (byte0x0c(byte0xcc(byte0x33(byte0x30(byte0x18,
    (byte0xcc(byte0x33(byte0x18(byte0x10(byte0xc4,
    (byte0x23(byte0x08(byte0x10(byte0x63(byte0xC6,
    (byte0x08(byte0x10(byte0x30(byte0x0c(byte0x08,
    (byte0x10(byte0x18(byte0x18(byte0x08(byte0x10,
    (byte0x00(byte0x00(byte0x08 };

  private byte halftone[] =
  { (byte0xAA(byte0xAA(byte0xAA(byte0xAA(byte0x55,
    (byte0x55(byte0x55(byte0x55(byte0xAA(byte0xAA,
    (byte0xAA(byte0xAA(byte0x55(byte0x55(byte0x55,
    (byte0x55(byte0xAA(byte0xAA(byte0xAA(byte0xAA,
    (byte0x55(byte0x55(byte0x55(byte0x55(byte0xAA,
    (byte0xAA(byte0xAA(byte0xAA(byte0x55(byte0x55,
    (byte0x55(byte0x55(byte0xAA(byte0xAA(byte0xAA,
    (byte0xAA(byte0x55(byte0x55(byte0x55(byte0x55,
    (byte0xAA(byte0xAA(byte0xAA(byte0xAA(byte0x55,
    (byte0x55(byte0x55(byte0x55(byte0xAA(byte0xAA,
    (byte0xAA(byte0xAA(byte0x55(byte0x55(byte0x55,
    (byte0x55(byte0xAA(byte0xAA(byte0xAA(byte0xAA,
    (byte0x55(byte0x55(byte0x55(byte0x55(byte0xAA,
    (byte0xAA(byte0xAA(byte0xAA(byte0x55(byte0x55,
    (byte0x55(byte0x55(byte0xAA(byte0xAA(byte0xAA,
    (byte0xAA(byte0x55(byte0x55(byte0x55(byte0x55,
    (byte0xAA(byte0xAA(byte0xAA(byte0xAA(byte0x55,
    (byte0x55(byte0x55(byte0x55(byte0xAA(byte0xAA,
    (byte0xAA(byte0xAA(byte0x55(byte0x55(byte0x55,
    (byte0x55(byte0xAA(byte0xAA(byte0xAA(byte0xAA,
    (byte0x55(byte0x55(byte0x55(byte0x55(byte0xAA,
    (byte0xAA(byte0xAA(byte0xAA(byte0x55(byte0x55,
    (byte0x55(byte0x55(byte0xAA(byte0xAA(byte0xAA,
    (byte0xAA(byte0x55(byte0x55(byte0x55(byte0x55,
    (byte0xAA(byte0xAA(byte0xAA(byte0xAA(byte0x55,
    (byte0x55(byte0x55(byte0x55 };

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

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

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

  public void init(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    glu = new GLU();
    glut = new GLUT();
    //
    gl.glClearColor(0.0f0.0f0.0f0.0f);
    gl.glShadeModel(GL.GL_FLAT);
  }

  public void display(GLAutoDrawable drawable)
  {
    GL gl = drawable.getGL();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glColor3f(1.0f1.0f1.0f);

    /* draw one solid, unstippled rectangle, */
    /* then two stippled rectangles */
    gl.glRectf(25.0f25.0f125.0f125.0f);
    gl.glEnable(GL.GL_POLYGON_STIPPLE);
    gl.glPolygonStipple(fly, 0);
    gl.glRectf(125.0f25.0f225.0f125.0f);
    gl.glPolygonStipple(halftone, 0);
    gl.glRectf(225.0f25.0f325.0f125.0f);
    gl.glDisable(GL.GL_POLYGON_STIPPLE);

    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.gluOrtho2D(0.0(doublew, 0.0(doubleh);
  }

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

  public void keyTyped(KeyEvent key)
  {
  }

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

      default:
        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.