diff options
author | Sven Gothel <[email protected]> | 2019-12-31 18:23:02 +0100 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2019-12-31 18:23:02 +0100 |
commit | 332dd8550a2301427dd942d2a77cb59ebd3ec92e (patch) | |
tree | 0c860a40c05ba5b27d99770a433b922cbf685f70 /demos/src | |
parent | 7ea189170b6ae75b7e15be43344a785eb56bb48a (diff) |
Diffstat (limited to 'demos/src')
-rw-r--r-- | demos/src/jgudemos/BasicGLJFrameDemo.java | 49 | ||||
-rw-r--r-- | demos/src/jgudemos/BouncingText3D.java | 220 | ||||
-rw-r--r-- | demos/src/jgudemos/FontDrawerDemo.java | 25 | ||||
-rw-r--r-- | demos/src/jgudemos/TestRenderer3D.java | 113 |
4 files changed, 215 insertions, 192 deletions
diff --git a/demos/src/jgudemos/BasicGLJFrameDemo.java b/demos/src/jgudemos/BasicGLJFrameDemo.java index 8b4d329..435e8db 100644 --- a/demos/src/jgudemos/BasicGLJFrameDemo.java +++ b/demos/src/jgudemos/BasicGLJFrameDemo.java @@ -1,21 +1,21 @@ /*
* Copyright (c) 2007 Erik Tollerud ([email protected]) All Rights Reserved.
- *
+ *
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
- *
+ *
* - Redistribution of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
- *
+ *
* - Redistribution in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
- *
+ *
* The names of Erik Tollerud, Sun Microsystems, Inc. or the names of
* contributors may not be used to endorse or promote products derived from
* this software without specific prior written permission.
- *
+ *
* This software is provided "AS IS," without a warranty of any kind. ALL
* EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
* INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
@@ -23,12 +23,12 @@ * SUN MICROSYSTEMS, INC. ("SUN"), AND SUN'S LICENSORS SHALL NOT BE LIABLE FOR
* ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
* DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL ERIK
- * TOLLERUD, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
+ * TOLLERUD, SUN, OR SUN'S LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT
* OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
* PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
* ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF ERIK
* TOLLERUD OR SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
- *
+ *
* You acknowledge that this software is not designed or intended for use
* in the design, construction, operation or maintenance of any nuclear
* facility.
@@ -36,9 +36,14 @@ package jgudemos;
-import net.java.joglutils.*;
+import javax.swing.JFrame;
+
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
-import javax.media.opengl.*;
+import net.java.joglutils.GLJFrame;
/**
*
@@ -46,32 +51,32 @@ import javax.media.opengl.*; * @created January 12, 2007
*/
public class BasicGLJFrameDemo {
-
- public static void main(String[] args) {
- GLJFrame gljf = new GLJFrame(new GLEventListener() {
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
+
+ public static void main(final String[] args) {
+ final GLJFrame gljf = new GLJFrame(new GLEventListener() {
+ public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
}
- public void init(GLAutoDrawable drawable) {
+ public void init(final GLAutoDrawable drawable) {
}
- public void display(GLAutoDrawable drawable) {
- GL2 gl = drawable.getGL().getGL2();
- gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ public void display(final GLAutoDrawable drawable) {
+ final GL2 gl = drawable.getGL().getGL2();
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glColor3f(1.0f,0.323f,0.8f);
- gl.glBegin(GL2.GL_TRIANGLE_STRIP);
+ gl.glBegin(GL.GL_TRIANGLE_STRIP);
gl.glVertex2d(0,0);
gl.glVertex2d(0.5,1.0);
gl.glVertex2d(-0.3,-0.9);
gl.glEnd();
}
- public void dispose(GLAutoDrawable drawable) {
+ public void dispose(final GLAutoDrawable drawable) {
}
-
+
});
- gljf.setDefaultCloseOperation(gljf.EXIT_ON_CLOSE);
+ gljf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
gljf.setVisible(true);
}
-
+
}
diff --git a/demos/src/jgudemos/BouncingText3D.java b/demos/src/jgudemos/BouncingText3D.java index 4be64a3..5c26768 100644 --- a/demos/src/jgudemos/BouncingText3D.java +++ b/demos/src/jgudemos/BouncingText3D.java @@ -1,6 +1,6 @@ /**
* Simple bouncing text example. Illustrates use of the TextRenderer3D class
- *
+ *
* Ric Wright
* June 2008
@@ -18,47 +18,53 @@ import java.util.ArrayList; import java.util.Iterator;
import java.util.Random;
-import javax.media.opengl.*;
-import javax.media.opengl.awt.*;
-import javax.media.opengl.glu.*;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.awt.GLCanvas;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.glu.GLUquadric;
+import com.jogamp.opengl.util.Animator;
+
import javax.vecmath.Point3f;
import net.java.joglutils.jogltext.TextRenderer3D;
-import com.sun.opengl.util.Animator;
-
/**
* Simple class to demonstrate the use of compile/call with
* TextRenderer3D
- *
+ *
*/
public class BouncingText3D implements GLEventListener
{
TextRenderer3D tr3;
-
+
float[] LightDiffuse = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] LightAmbient = { 0.8f, 0.8f, 0.8f, 1.0f };
float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f };
float[] mat_specular = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] mat_ambient_magenta = { 1.0f, 0.0f, 1.0f, 1.0f };
- float[] mat_shininess = { 100.0f };
+ float[] mat_shininess = { 100.0f };
protected Random random = new Random();
public static final int NUM_ITEMS = 20;
public static final int MAX_ITEMS = 200;
private static int numItems = NUM_ITEMS;
- private ArrayList<TextInfo3D> textInfo = new ArrayList<TextInfo3D>();
+ private final ArrayList<TextInfo3D> textInfo = new ArrayList<TextInfo3D>();
- private GLU glu = new GLU();
+ private final GLU glu = new GLU();
protected GLUquadric QUADRIC;
/**
- * Main entry point for the app. The only argument that is parsed
+ * Main entry point for the app. The only argument that is parsed
* out is the number of items
* @param args
*/
- public static void main(String[] args)
+ public static void main(final String[] args)
{
if (args != null && Array.getLength(args) > 0)
{
@@ -68,9 +74,9 @@ public class BouncingText3D implements GLEventListener else if (numItems > MAX_ITEMS)
numItems = MAX_ITEMS;
}
-
- Frame frame = new Frame("Bouncing Text 3D");
- GLCanvas canvas = new GLCanvas();
+
+ final Frame frame = new Frame("Bouncing Text 3D");
+ final GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new BouncingText3D());
frame.add(canvas);
@@ -80,7 +86,7 @@ public class BouncingText3D implements GLEventListener {
@Override
- public void windowClosing(WindowEvent e)
+ public void windowClosing(final WindowEvent e)
{
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
@@ -96,7 +102,7 @@ public class BouncingText3D implements GLEventListener }).start();
}
});
-
+
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
@@ -107,37 +113,37 @@ public class BouncingText3D implements GLEventListener * Initialize the GL instance. Set up the lights and other
* variables and conditions specific to this class
*/
- public void init(GLAutoDrawable drawable)
+ public void init(final GLAutoDrawable drawable)
{
- QUADRIC = glu.gluNewQuadric();
+ QUADRIC = glu.gluNewQuadric();
- GL2 gl = drawable.getGL().getGL2();
+ final GL2 gl = drawable.getGL().getGL2();
System.out.println("INIT GL IS: " + gl.getClass().getName());
- System.out.println("init GL called. GL Class: " + gl.getClass().getName()
+ System.out.println("init GL called. GL Class: " + gl.getClass().getName()
+ " and this: " + this.getClass().getName());
gl.setSwapInterval(1);
// Setup the drawing area and shading mode
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glShadeModel(GL2.GL_SMOOTH);
-
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, LightAmbient, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, LightDiffuse, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, LightPosition, 0);
+ gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
- gl.glEnable(GL2.GL_DEPTH_TEST);
- gl.glDepthFunc(GL2.GL_LESS);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, LightAmbient, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, LightDiffuse, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, LightPosition, 0);
- gl.glEnable(GL2.GL_BLEND);
- gl.glEnable(GL2.GL_LINE_SMOOTH);
- gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LESS);
+
+ gl.glEnable(GL.GL_BLEND);
+ gl.glEnable(GL.GL_LINE_SMOOTH);
+ gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
// Note that it has to be a TRUETYPE font - not OpenType. Apparently, AWT can't
// handle CFF glyphs
- tr3 = new TextRenderer3D(new Font("Times New Roman", Font.TRUETYPE_FONT, 3), 0.25f);
-
+ tr3 = new TextRenderer3D(new Font("Times New Roman", Font.TRUETYPE_FONT, 3), 0.25f);
+
// Create random text
textInfo.clear();
for (int i = 0; i < numItems; i++)
@@ -151,20 +157,20 @@ public class BouncingText3D implements GLEventListener * The shape or size of the viewport (client frame) has changed. We need to re-init
* the matrix stack, i.e. the GL_PROJECTION and then initialize back to the GL_MODELVIEW
*/
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, int height)
{
- GL2 gl = drawable.getGL().getGL2();
+ final GL2 gl = drawable.getGL().getGL2();
if (height <= 0) // avoid a divide by zero error!
height = 1;
-
+
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
-
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
@@ -172,15 +178,15 @@ public class BouncingText3D implements GLEventListener * Display needs to be re-rendered. This is where all the heavy-lifting
* gets done.
*/
- public void display(GLAutoDrawable drawable)
+ public void display(final GLAutoDrawable drawable)
{
- GL2 gl = drawable.getGL().getGL2();
+ final GL2 gl = drawable.getGL().getGL2();
// Clear the drawing area
- gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SHININESS, mat_shininess, 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, mat_specular, 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, mat_shininess, 0);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();
@@ -188,42 +194,42 @@ public class BouncingText3D implements GLEventListener gl.glTranslatef(0.0f, 0.0f, -3.0f);
gl.glRotatef(45.0f, 1, 0, 0);
gl.glRotatef(-30.0f, 0, 1, 0);
-
+
try
{
- gl.glEnable(GL2.GL_LIGHTING);
- gl.glEnable(GL2.GL_LIGHT0);
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_LIGHT0);
drawAxes(gl);
-
- for (Iterator iter = textInfo.iterator(); iter.hasNext();)
+
+ for (final Iterator iter = textInfo.iterator(); iter.hasNext();)
{
- TextInfo3D info = (TextInfo3D) iter.next();
-
+ final TextInfo3D info = (TextInfo3D) iter.next();
+
updateTextInfo( info );
-
+
gl.glPushAttrib(GL2.GL_TRANSFORM_BIT);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glPushMatrix();
- gl.glEnable( GL2.GL_NORMALIZE);
-
+ gl.glEnable( GLLightingFunc.GL_NORMALIZE);
+
gl.glTranslatef(info.position.x, info.position.y, info.position.z);
gl.glRotatef(info.angle.x, 1, 0, 0);
gl.glRotatef(info.angle.y, 0, 1, 0);
gl.glRotatef(info.angle.z, 0, 0, 1);
-
+
// System.out.println(" x,y,z: " + info.position.x + " " + info.position.y + " " + info.position.z + " angle: " + info.angle );
-
- gl.glMaterialfv(GL2.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, info.material, 0);
+
+ gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, info.material, 0);
tr3.call(info.index);
-
+
gl.glPopMatrix();
- gl.glPopAttrib();
+ gl.glPopAttrib();
}
-
+
}
- catch (Exception e)
+ catch (final Exception e)
{
e.printStackTrace();
}
@@ -232,10 +238,10 @@ public class BouncingText3D implements GLEventListener /**
* No explicit cleanup necessary.
*/
- public void dispose(GLAutoDrawable drawable)
+ public void dispose(final GLAutoDrawable drawable)
{
}
-
+
//------------------ Private Stuff below here ------------------------------
private static final float INIT_ANG_VEL_MAG = 0.3f;
private static final float INIT_VEL_MAG = 0.25f;
@@ -265,11 +271,11 @@ public class BouncingText3D implements GLEventListener }
Point3f tmp = new Point3f();
-
- private void updateTextInfo( TextInfo3D info )
+
+ private void updateTextInfo( final TextInfo3D info )
{
// Update velocities and positions of all text
- float deltaT = 0.1f;
+ final float deltaT = 0.1f;
// Randomize things a little bit every little once in a while
if (random.nextInt(10000) == 0)
@@ -282,7 +288,7 @@ public class BouncingText3D implements GLEventListener tmp.set(info.angularVelocity);
tmp.scale(deltaT*deltaT);
info.angle.add(tmp);
-
+
tmp.set(info.velocity);
tmp.scale(deltaT);
info.position.add(tmp);
@@ -291,22 +297,22 @@ public class BouncingText3D implements GLEventListener info.angle.x = clampAngle(info.angle.x);
info.angle.y = clampAngle(info.angle.y);
info.angle.z = clampAngle(info.angle.z);
-
+
info.velocity.x = clampBounds(info.position.x, info.velocity.x );
info.velocity.y = clampBounds(info.position.y, info.velocity.y );
info.velocity.z = clampBounds(info.position.z, info.velocity.z );
}
- private float clampBounds( float pos, float velocity )
+ private float clampBounds( final float pos, float velocity )
{
if (pos < -MAX_BOUNDS || pos > MAX_BOUNDS)
{
velocity *= -1.0f;
}
-
+
return velocity;
}
-
+
private float clampAngle(float angle)
{
if (angle < 0)
@@ -317,23 +323,23 @@ public class BouncingText3D implements GLEventListener {
angle -= 360;
}
-
+
return angle;
}
-
+
private TextInfo3D randomTextInfo()
{
- TextInfo3D info = new TextInfo3D();
+ final TextInfo3D info = new TextInfo3D();
info.text = randomString();
info.angle = randomRotation(INIT_ANG_VEL_MAG, INIT_ANG_VEL_MAG, INIT_ANG_VEL_MAG);
info.position = randomVector(MAX_BOUNDS, MAX_BOUNDS, MAX_BOUNDS);
-
-
- Rectangle2D rect = tr3.getBounds(info.text, SCALE_FACTOR);
- float offX = (float) rect.getCenterX();
- float offY = (float) rect.getCenterY();
- float offZ = tr3.getDepth() / 2.0f;
+
+ final Rectangle2D rect = tr3.getBounds(info.text, SCALE_FACTOR);
+
+ final float offX = (float) rect.getCenterX();
+ final float offY = (float) rect.getCenterY();
+ final float offZ = tr3.getDepth() / 2.0f;
tr3.setDepth(0.1f + random.nextFloat() * 2.0f);
info.index = tr3.compile(info.text, -offX, offY, -offZ, SCALE_FACTOR);
@@ -341,11 +347,11 @@ public class BouncingText3D implements GLEventListener info.angularVelocity = randomRotation(INIT_ANG_VEL_MAG, INIT_ANG_VEL_MAG, INIT_ANG_VEL_MAG);
info.velocity = randomVelocity(INIT_VEL_MAG, INIT_VEL_MAG, INIT_VEL_MAG);
- Color c = randomColor();
+ final Color c = randomColor();
c.getColorComponents(info.material);
// Color doesn't set the opacity,so set it to some random non-zero value
info.material[3] = random.nextFloat() * 0.9f + 0.1f;
-
+
return info;
}
@@ -362,21 +368,21 @@ public class BouncingText3D implements GLEventListener }
}
- private Point3f randomVector(float x, float y, float z)
+ private Point3f randomVector(final float x, final float y, final float z)
{
return new Point3f(x * random.nextFloat(), y * random.nextFloat(), z * random.nextFloat());
}
- private Point3f randomVelocity(float x, float y, float z)
+ private Point3f randomVelocity(final float x, final float y, final float z)
{
return new Point3f(x * (random.nextFloat() - 0.5f), y * (random.nextFloat() - 0.5f), z * (random.nextFloat() - 0.5f));
}
- private Point3f randomRotation(float x, float y, float z)
+ private Point3f randomRotation(final float x, final float y, final float z)
{
return new Point3f(random.nextFloat() * 360.0f, random.nextFloat() * 360.0f, random.nextFloat() * 360.0f);
}
-
+
private Color randomColor()
{
// Get a bright and saturated color
@@ -390,21 +396,21 @@ public class BouncingText3D implements GLEventListener g = random.nextFloat();
b = random.nextFloat();
- float[] hsb = Color.RGBtoHSB((int) (255.0f * r), (int) (255.0f * g), (int) (255.0f * b), null);
+ final float[] hsb = Color.RGBtoHSB((int) (255.0f * r), (int) (255.0f * g), (int) (255.0f * b), null);
s = hsb[1];
- }
+ }
while ((r < 0.6f && g < 0.6f && b < 0.6f) || s < 0.8f);
-
+
return new Color(r, g, b);
}
-
+
// draw some striped-pole axes for visdual reference
- protected void drawAxes(GL2 gl)
+ protected void drawAxes(final GL2 gl)
{
- float[] mat_ambient_red = { 1.0f, 0.0f, 0.0f, 1.0f };
- float[] mat_ambient_green = { 0.0f, 1.0f, 0.0f, 1.0f };
- float[] mat_ambient_blue = { 0.0f, 0.0f, 1.0f, 1.0f };
-
+ final float[] mat_ambient_red = { 1.0f, 0.0f, 0.0f, 1.0f };
+ final float[] mat_ambient_green = { 0.0f, 1.0f, 0.0f, 1.0f };
+ final float[] mat_ambient_blue = { 0.0f, 0.0f, 1.0f, 1.0f };
+
drawAxis(gl, 2, mat_ambient_red);
drawAxis(gl, 0, mat_ambient_blue);
@@ -413,36 +419,36 @@ public class BouncingText3D implements GLEventListener }
// draw a single striped pole axis
- private void drawAxis(GL2 gl, int rot, float[] material )
+ private void drawAxis(final GL2 gl, final int rot, final float[] material )
{
- float[] mat_ambient_grey = { 0.5f, 0.5f, 0.5f, 1.0f };
+ final float[] mat_ambient_grey = { 0.5f, 0.5f, 0.5f, 1.0f };
final double AXIS_RADIUS = 0.01;
final int AXIS_HEIGHT = 5;
final float AXIS_STEP = 0.25f;
gl.glPushMatrix();
-
+
if (rot == 1)
gl.glRotatef(90, 1, 0, 0);
else if (rot == 0)
gl.glRotatef(90, 0, 1, 0);
-
- gl.glTranslatef(0.0f, 0.0f, (float)-AXIS_HEIGHT/2.0f);
-
+
+ gl.glTranslatef(0.0f, 0.0f, -AXIS_HEIGHT/2.0f);
+
float pos = -AXIS_HEIGHT/2.0f;
int i = 0;
while ( pos < AXIS_HEIGHT/2.0f )
{
if ((i++ & 1)==0)
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, material, 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, material, 0);
else
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, mat_ambient_grey, 0);
-
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, mat_ambient_grey, 0);
+
glu.gluCylinder(QUADRIC, AXIS_RADIUS, AXIS_RADIUS, AXIS_STEP, 8, 1);
gl.glTranslatef(0.0f, 0.0f, AXIS_STEP);
pos += AXIS_STEP;
}
-
+
gl.glPopMatrix();
}
}
\ No newline at end of file diff --git a/demos/src/jgudemos/FontDrawerDemo.java b/demos/src/jgudemos/FontDrawerDemo.java index 2bf0959..2142f15 100644 --- a/demos/src/jgudemos/FontDrawerDemo.java +++ b/demos/src/jgudemos/FontDrawerDemo.java @@ -36,15 +36,22 @@ package jgudemos;
-import net.java.joglutils.jogltext.*;
-import java.awt.geom.*;
-import java.awt.font.*;
-import java.awt.*;
-import java.awt.event.*;
-import javax.swing.*;
-import javax.media.opengl.*;
-import javax.media.opengl.glu.*;
-import com.sun.opengl.util.Animator;
+import java.awt.Font;
+import java.awt.GraphicsEnvironment;
+import java.awt.event.KeyEvent;
+
+import javax.swing.JComboBox;
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import com.jogamp.opengl.DebugGL2;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.util.Animator;
+
+import net.java.joglutils.jogltext.FontDrawer;
/**
* This Demo application uses the Lighting class and the FontDrawer class to render 3D text into a GLJFrame.
diff --git a/demos/src/jgudemos/TestRenderer3D.java b/demos/src/jgudemos/TestRenderer3D.java index 2398520..916dfee 100644 --- a/demos/src/jgudemos/TestRenderer3D.java +++ b/demos/src/jgudemos/TestRenderer3D.java @@ -1,29 +1,34 @@ /**
* Simple test of the TextRenderer3D class.
- *
+ *
* Ric Wright
* June 2008
*/
package jgudemos;
-import net.java.joglutils.jogltext.TextRenderer3D;
-import com.sun.opengl.util.Animator;
-
import java.awt.Font;
import java.awt.Frame;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.geom.Rectangle2D;
-import javax.media.opengl.*;
-import javax.media.opengl.awt.*;
-import javax.media.opengl.glu.*;
+import com.jogamp.opengl.GL;
+import com.jogamp.opengl.GL2;
+import com.jogamp.opengl.GLAutoDrawable;
+import com.jogamp.opengl.GLEventListener;
+import com.jogamp.opengl.awt.GLCanvas;
+import com.jogamp.opengl.fixedfunc.GLLightingFunc;
+import com.jogamp.opengl.fixedfunc.GLMatrixFunc;
+import com.jogamp.opengl.glu.GLU;
+import com.jogamp.opengl.util.Animator;
+
+import net.java.joglutils.jogltext.TextRenderer3D;
/**
- * TestRenderer3D
+ * TestRenderer3D
* Hello World style test of the TextRenderer3D
- *
+ *
*/
public class TestRenderer3D implements GLEventListener
{
@@ -33,12 +38,12 @@ public class TestRenderer3D implements GLEventListener float[] LightPosition = { 1.0f, 1.0f, 1.0f, 0.0f };
float[] mat_specular = { 1.0f, 1.0f, 1.0f, 1.0f };
float[] mat_ambient_magenta = { 1.0f, 0.0f, 1.0f, 1.0f };
- float[] mat_shininess = { 100.0f };
-
- public static void main(String[] args)
+ float[] mat_shininess = { 100.0f };
+
+ public static void main(final String[] args)
{
- Frame frame = new Frame("Simple JOGL Application");
- GLCanvas canvas = new GLCanvas();
+ final Frame frame = new Frame("Simple JOGL Application");
+ final GLCanvas canvas = new GLCanvas();
canvas.addGLEventListener(new TestRenderer3D());
frame.add(canvas);
@@ -48,7 +53,7 @@ public class TestRenderer3D implements GLEventListener {
@Override
- public void windowClosing(WindowEvent e)
+ public void windowClosing(final WindowEvent e)
{
// Run this on another thread than the AWT event queue to
// make sure the call to Animator.stop() completes before
@@ -64,7 +69,7 @@ public class TestRenderer3D implements GLEventListener }).start();
}
});
-
+
// Center frame
frame.setLocationRelativeTo(null);
frame.setVisible(true);
@@ -75,47 +80,47 @@ public class TestRenderer3D implements GLEventListener * Initialize the GL instance. Set up the lights and other
* variables and conditions specific to this class
*/
- public void init(GLAutoDrawable drawable)
+ public void init(final GLAutoDrawable drawable)
{
- GL2 gl = drawable.getGL().getGL2();
- System.out.println("init GL called. GL Class: " + gl.getClass().getName()
+ final GL2 gl = drawable.getGL().getGL2();
+ System.out.println("init GL called. GL Class: " + gl.getClass().getName()
+ " and this: " + this.getClass().getName());
gl.setSwapInterval(1);
-
+
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- gl.glShadeModel(GL2.GL_SMOOTH);
-
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, LightAmbient, 0);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, LightDiffuse, 0);
+ gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
- gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, LightPosition, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, LightAmbient, 0);
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_DIFFUSE, LightDiffuse, 0);
+
+ gl.glLightfv(GLLightingFunc.GL_LIGHT0, GLLightingFunc.GL_POSITION, LightPosition, 0);
+
+ gl.glEnable(GL.GL_DEPTH_TEST);
+ gl.glDepthFunc(GL.GL_LESS);
- gl.glEnable(GL2.GL_DEPTH_TEST);
- gl.glDepthFunc(GL2.GL_LESS);
-
// Be sure to use a font name on your system otherwise you will get the default
- tr3 = new TextRenderer3D(new Font("Times New Roman", Font.TRUETYPE_FONT, 3), 0.25f);
+ tr3 = new TextRenderer3D(new Font("Times New Roman", Font.TRUETYPE_FONT, 3), 0.25f);
}
/**
* The shape or size of the viewport (client frame) has changed. We need to re-init
* the matrix stack, i.e. the GL_PROJECTION and then initialize back to the GL_MODELVIEW
*/
- public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height)
+ public void reshape(final GLAutoDrawable drawable, final int x, final int y, final int width, int height)
{
- GL2 gl = drawable.getGL().getGL2();
- GLU glu = new GLU();
+ final GL2 gl = drawable.getGL().getGL2();
+ final GLU glu = new GLU();
if (height <= 0) // avoid a divide by zero error!
height = 1;
final float h = (float) width / (float) height;
gl.glViewport(0, 0, width, height);
- gl.glMatrixMode(GL2.GL_PROJECTION);
+ gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(45.0f, h, 1.0, 20.0);
- gl.glMatrixMode(GL2.GL_MODELVIEW);
+ gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
gl.glLoadIdentity();
}
@@ -123,33 +128,33 @@ public class TestRenderer3D implements GLEventListener * Display needs to be re-rendered. This is where all the heavy-lifting
* gets done.
*/
- public void display(GLAutoDrawable drawable)
+ public void display(final GLAutoDrawable drawable)
{
- GL2 gl = drawable.getGL().getGL2();
+ final GL2 gl = drawable.getGL().getGL2();
// Clear the drawing area
- gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
+ gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
// Reset the current matrix to the "identity"
gl.glLoadIdentity();
gl.glTranslatef(1.5f, 0.0f, -6.0f);
gl.glRotatef(45.0f, 0, 1, 0);
-
- String str = "abcde";
- Rectangle2D rect = tr3.getBounds(str, 0.25f);
-
- float offX = (float) rect.getCenterX();
- float offY = (float) rect.getCenterY();
- float offZ = tr3.getDepth() / 2.0f;
-
- gl.glEnable(GL2.GL_LIGHTING);
- gl.glEnable(GL2.GL_LIGHT0);
-
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SPECULAR, mat_specular, 0);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_SHININESS, mat_shininess, 0);
- gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, mat_ambient_magenta, 0);
-
- tr3.draw(str, -offX, offY, -offZ, 1.0f);
+
+ final String str = "abcde";
+ final Rectangle2D rect = tr3.getBounds(str, 0.25f);
+
+ final float offX = (float) rect.getCenterX();
+ final float offY = (float) rect.getCenterY();
+ final float offZ = tr3.getDepth() / 2.0f;
+
+ gl.glEnable(GLLightingFunc.GL_LIGHTING);
+ gl.glEnable(GLLightingFunc.GL_LIGHT0);
+
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SPECULAR, mat_specular, 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_SHININESS, mat_shininess, 0);
+ gl.glMaterialfv(GL.GL_FRONT, GLLightingFunc.GL_AMBIENT_AND_DIFFUSE, mat_ambient_magenta, 0);
+
+ tr3.draw(str, -offX, offY, -offZ, 1.0f);
// Flush all drawing operations to the graphics card
gl.glFlush();
@@ -158,7 +163,7 @@ public class TestRenderer3D implements GLEventListener /**
* No explicit cleanup necessary.
*/
- public void dispose(GLAutoDrawable drawable)
+ public void dispose(final GLAutoDrawable drawable)
{
}
}
\ No newline at end of file |