diff options
author | Sven Gothel <[email protected]> | 2001-02-23 05:08:10 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2001-02-23 05:08:10 +0000 |
commit | 82cd20ed209f12e22e2f5a92719b3be2bb92d8ed (patch) | |
tree | 6db7f6e46a2195c49bd20e4c6b42c9b206a920fb /demos/MiscDemos | |
parent | 70be669b0db3713117982dbeeadbb91ed670e901 (diff) |
Version 2.6.0.0
Diffstat (limited to 'demos/MiscDemos')
-rwxr-xr-x | demos/MiscDemos/TriangleRotate.java | 70 | ||||
-rw-r--r-- | demos/MiscDemos/alpha3D.java | 42 | ||||
-rw-r--r-- | demos/MiscDemos/gears.java | 85 | ||||
-rw-r--r-- | demos/MiscDemos/stencil.java | 90 |
4 files changed, 166 insertions, 121 deletions
diff --git a/demos/MiscDemos/TriangleRotate.java b/demos/MiscDemos/TriangleRotate.java index 25bccdd..1775b68 100755 --- a/demos/MiscDemos/TriangleRotate.java +++ b/demos/MiscDemos/TriangleRotate.java @@ -12,18 +12,32 @@ import java.lang.*; import java.util.*;
import java.io.*;
import java.util.*;
-import gl4java.GLContext;
-import gl4java.awt.GLAnimCanvas;
-import gl4java.applet.SimpleGLAnimApplet1;
+
+import gl4java.*;
+import gl4java.drawable.*;
+import gl4java.awt.*;
+import gl4java.applet.*;
public class TriangleRotate extends SimpleGLAnimApplet1
{
public void init()
{
+ GLContext.gljNativeDebug = true;
+ GLContext.gljThreadDebug = false;
+ GLContext.gljClassDebug = true;
+
super.init();
Dimension d = getSize();
- canvas = new gldemo(d.width, d.height);
+ System.out.println("applet size: "+d);
+ GLCapabilities caps = new GLCapabilities();
+
+ canvas =
+ GLDrawableFactory.getFactory().createGLAnimCanvas(caps, d.width, d.height);
+
+ gldemo demo = new gldemo();
+ canvas.addGLEventListener(demo);
+
add("Center", canvas);
}
@@ -65,7 +79,8 @@ public class TriangleRotate extends SimpleGLAnimApplet1 f.setVisible(true);
}
- private class gldemo extends GLAnimCanvas
+ private class gldemo
+ implements GLEventListener
{
float rotate;
@@ -73,24 +88,25 @@ public class TriangleRotate extends SimpleGLAnimApplet1 float LightDiffuse[] = { 1.0f, 1.0f, 1.0f, 0.9f};
float LightSpecular[] = { 0.8f, 0.8f, 0.8f, 1.0f};
- public gldemo(int w, int h)
- {
- super(w, h);
- GLContext.gljNativeDebug = false;
- GLContext.gljClassDebug = false;
- setAnimateFps(30.0);
- }
-
- public void preInit()
+ private GLFunc gl;
+ private GLUFunc glu;
+ private GLContext glj;
+
+ public gldemo()
{
- doubleBuffer = true;
- stereoView = false;
- createOwnWindow = true;
}
- public void init()
+ public void cleanup(GLDrawable drawable)
+ {
+ }
+
+ public void init(GLDrawable drawable)
{
- reshape(getSize().width, getSize().height);
+ gl = drawable.getGL();
+ glu = drawable.getGLU();
+ glj = drawable.getGLContext();
+
+ //drawable.reshape(getSize().width, getSize().height);
gl.glEnable(GL_LIGHT0);
gl.glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
@@ -100,7 +116,7 @@ public class TriangleRotate extends SimpleGLAnimApplet1 glj.gljCheckGL();
}
- public void reshape(int width, int height)
+ public void reshape(gl4java.drawable.GLDrawable d,int width,int height)
{
gl.glMatrixMode(GL_PROJECTION);
gl.glLoadIdentity();
@@ -110,10 +126,8 @@ public class TriangleRotate extends SimpleGLAnimApplet1 gl.glViewport(0,0,width,height);
}
- public void display()
+ public void display(GLDrawable drawable)
{
- if (glj.gljMakeCurrent() == false) return;
-
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL_MODELVIEW);
@@ -132,9 +146,15 @@ public class TriangleRotate extends SimpleGLAnimApplet1 gl.glVertex3f( 1, -1, 0);
gl.glEnd();
- glj.gljSwap();
glj.gljCheckGL();
- glj.gljFree();
}
+
+ public void preDisplay(GLDrawable drawable)
+ {
+ }
+
+ public void postDisplay(GLDrawable drawable)
+ {
+ }
}
}
diff --git a/demos/MiscDemos/alpha3D.java b/demos/MiscDemos/alpha3D.java index 5bd72ef..efbf433 100644 --- a/demos/MiscDemos/alpha3D.java +++ b/demos/MiscDemos/alpha3D.java @@ -15,9 +15,9 @@ import java.lang.*; import java.util.*; import java.io.*; import java.util.*; -import gl4java.GLContext; -import gl4java.awt.GLCanvas; -import gl4java.awt.GLAnimCanvas; +import gl4java.*; +import gl4java.awt.*; +import gl4java.drawable.*; import gl4java.applet.SimpleGLAnimApplet1; import gl4java.utils.glut.*; @@ -35,7 +35,23 @@ public class alpha3D extends SimpleGLAnimApplet1 { super.init(); Dimension d = getSize(); - canvas = new alpha3DCanvas(d.width, d.height); + GLCapabilities glCaps = new GLCapabilities(); + glCaps.setAlphaBits(8); + glCaps.setAccumAlphaBits(8); + + gl4java.drawable.GLDrawableFactory df = + gl4java.drawable.GLDrawableFactory.getFactory(); + + if(df instanceof gl4java.drawable.SunJDK13GLDrawableFactory) + { + gl4java.drawable.SunJDK13GLDrawableFactory sdf = + (gl4java.drawable.SunJDK13GLDrawableFactory)df; + canvas = new alpha3DCanvas + (sdf.getGraphicsConfiguration(glCaps), glCaps, d.width, d.height); + } else { + canvas = new alpha3DCanvas(glCaps, d.width, d.height); + } + add("Center", canvas); } @@ -46,6 +62,10 @@ public class alpha3D extends SimpleGLAnimApplet1 Frame f = new Frame("alpha3D"); + GLContext.gljNativeDebug = true; + GLContext.gljThreadDebug = false; + GLContext.gljClassDebug = true; + f.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e) @@ -93,21 +113,19 @@ public class alpha3D extends SimpleGLAnimApplet1 float transparentZ = MINZ; int sphereList, cubeList; - public alpha3DCanvas(int w, int h) + public alpha3DCanvas(GraphicsConfiguration g, GLCapabilities glCaps, + int w, int h) { - super(w, h); - GLContext.gljNativeDebug = false; - GLContext.gljClassDebug = false; + super(g, glCaps, w, h); setAnimateFps(30.0); } - public void preInit() + public alpha3DCanvas(GLCapabilities glCaps, int w, int h) { - doubleBuffer = true; - stereoView = false; + super(glCaps, w, h); + setAnimateFps(30.0); } - public void init() { glut = new GLUTFuncLightImpl(gl, glu); diff --git a/demos/MiscDemos/gears.java b/demos/MiscDemos/gears.java index e544a08..8775c6e 100644 --- a/demos/MiscDemos/gears.java +++ b/demos/MiscDemos/gears.java @@ -12,8 +12,8 @@ import java.lang.*; import java.util.*;
import java.io.*;
import java.util.*;
-import gl4java.GLContext;
-import gl4java.GLEnum;
+import gl4java.*;
+import gl4java.drawable.*;
import gl4java.awt.GLAnimCanvas;
import gl4java.applet.SimpleGLAnimApplet1;
@@ -22,18 +22,8 @@ public class gears extends SimpleGLAnimApplet1 {
/* Initialize the applet */
- static {
- GLContext.gljNativeDebug = true;
- GLContext.gljThreadDebug = false;
- GLContext.gljClassDebug = true;
- }
-
-
public void init()
{
- GLContext.gljNativeDebug = true;
- GLContext.gljThreadDebug = false;
- GLContext.gljClassDebug = true;
init(false);
}
@@ -41,12 +31,19 @@ public class gears extends SimpleGLAnimApplet1 {
super.init();
Dimension d = getSize();
- canvas = new gearsCanvas(showGL, d.width, d.height);
+
+ GLCapabilities caps = new GLCapabilities();
+
+ canvas =
+ GLDrawableFactory.getFactory().createGLAnimCanvas(caps, d.width, d.height);
+
+ gearRenderer gear = new gearRenderer(showGL);
+ canvas.addGLEventListener(gear);
+
add("Center", canvas);
- addMouseListener(this);
+ addMouseListener(this);
}
-
public static void main( String args[] )
{
int i = 0;
@@ -110,6 +107,9 @@ public class gears extends SimpleGLAnimApplet1 );
gears applet = new gears();
+ mainFrame.add(applet);
+ applet.setSize(400,500);
+ applet.init();
if(perftest)
{
@@ -124,10 +124,8 @@ public class gears extends SimpleGLAnimApplet1 applet.canvas.getUseFpsSleep());
}
- mainFrame.add(applet);
- applet.setSize(400,500);
- applet.init();
applet.start();
+
Dimension ps = applet.getPreferredSize();
mainFrame.setBounds(-100,-100,99,99);
mainFrame.setVisible(true);
@@ -188,7 +186,7 @@ public class gears extends SimpleGLAnimApplet1 /* Local GLAnimCanvas extension class */
- public class gearsCanvas extends GLAnimCanvas implements MouseListener, MouseMotionListener
+ public class gearRenderer implements GLEventListener, MouseListener, MouseMotionListener
{
private static final float M_PI = 3.14159265f;
@@ -204,28 +202,20 @@ public class gears extends SimpleGLAnimApplet1 private boolean showGL = false;
- public gearsCanvas(int w, int h)
- {
- this(false, w, h);
- }
-
- public gearsCanvas(boolean showGL, int w, int h)
- {
- super(w, h);
- setAnimateFps(30.0);
+ private GLFunc gl;
+ private GLUFunc glu;
+ private GLContext glj;
- this.showGL=showGL;
- }
-
- public void preInit()
+ public gearRenderer(boolean showGL)
{
- doubleBuffer = true;
- stereoView = false;
+ this.showGL=showGL;
}
- public void init()
+ public void init(GLDrawable drawable)
{
- reshape(getSize().width, getSize().height);
+ gl = drawable.getGL();
+ glu = drawable.getGLU();
+ glj = drawable.getGLContext();
float pos[] = { 5.0f, 5.0f, 10.0f, 0.0f };
float red[] = { 0.8f, 0.1f, 0.0f, 1.0f };
@@ -261,21 +251,21 @@ public class gears extends SimpleGLAnimApplet1 glj.gljCheckGL();
- addMouseListener(this);
- addMouseMotionListener(this);
+ drawable.addMouseListener(this);
+ drawable.addMouseMotionListener(this);
T0=System.currentTimeMillis();
System.out.println("init ..");
}
- public void doCleanup()
+ public void cleanup(GLDrawable drawable)
{
System.out.println("destroy(): " + this);
removeMouseListener(this);
removeMouseMotionListener(this);
}
- public void reshape(int width, int height)
+ public void reshape(gl4java.drawable.GLDrawable gld,int width,int height)
{
float h = (float)height / (float)width;
@@ -288,10 +278,8 @@ public class gears extends SimpleGLAnimApplet1 gl.glTranslatef(0.0f, 0.0f, -40.0f);
}
- public void display()
+ public void display(GLDrawable drawable)
{
- if (glj.gljMakeCurrent() == false) return;
-
if(showGL)
{
showGL=false;
@@ -329,12 +317,15 @@ public class gears extends SimpleGLAnimApplet1 gl.glPopMatrix();
- glj.gljSwap();
- glj.gljCheckGL();
- glj.gljFree();
-
Frames++;
+ }
+ public void preDisplay(GLDrawable drawable)
+ {
+ }
+
+ public void postDisplay(GLDrawable drawable)
+ {
long t=System.currentTimeMillis();
if(t - T0 >= 5000)
{
diff --git a/demos/MiscDemos/stencil.java b/demos/MiscDemos/stencil.java index b5f7fe7..09a2092 100644 --- a/demos/MiscDemos/stencil.java +++ b/demos/MiscDemos/stencil.java @@ -57,14 +57,12 @@ import java.lang.*; import java.util.*;
import java.io.*;
import java.util.*;
-import gl4java.GLContext;
+import gl4java.*;
+import gl4java.drawable.*;
import gl4java.awt.GLCanvas;
public class stencil extends Applet
{
- stencilCanvas canvas1 = null;
- stencilCanvas canvas2 = null;
-
Panel cvs = null;
/* Initialize the applet */
@@ -75,10 +73,29 @@ public class stencil extends Applet Dimension d = getSize();
setLayout(new BorderLayout());
- canvas1 = new stencilCanvas(d.width, d.height, 0, false);
- System.out.println("the left canvas has 0 stencil-bits, self-window");
- canvas2 = new stencilCanvas(d.width, d.height, 8, true);
- System.out.println("the right canvas should have 8 stencil-bits, ownWindow");
+ GLCapabilities caps1 = new GLCapabilities();
+ caps1.setStencilBits(0);
+
+ System.out.println("the left canvas has 0 stencil-bits");
+ System.out.println("caps1: "+caps1);
+
+ GLCanvas canvas1 =
+ GLDrawableFactory.getFactory().createGLCanvas(caps1, d.width, d.height);
+
+ stencilDemo demo1 = new stencilDemo(d.width, d.height);
+ canvas1.addGLEventListener(demo1);
+
+ GLCapabilities caps2 = new GLCapabilities();
+ caps2.setStencilBits(8);
+
+ System.out.println("the right canvas should have >=8 stencil-bits");
+ System.out.println("caps2: "+caps2);
+
+ GLCanvas canvas2 =
+ GLDrawableFactory.getFactory().createGLCanvas(caps2, d.width, d.height);
+
+ stencilDemo demo2 = new stencilDemo(d.width, d.height);
+ canvas2.addGLEventListener(demo2);
cvs = new Panel();
cvs.setLayout(new GridLayout(1,2));
@@ -131,37 +148,39 @@ public class stencil extends Applet /* Local GLCanvas extension class */
- private class stencilCanvas extends GLCanvas
+ private class stencilDemo
+ implements GLEventListener
{
private static final float M_PI = 3.14159265359f;
private static final int YELLOWMAT = 1, BLUEMAT = 2;
private boolean initdone = false;
- public stencilCanvas(int w, int h,
- int _stencilBits,
- boolean _createOwnWindow)
- {
- super(w, h);
- stencilBits = _stencilBits;
- createOwnWindow = _createOwnWindow;
- }
-
- public void preInit()
+ private GLFunc gl;
+ private GLUFunc glu;
+ private GLContext glj;
+
+
+ public stencilDemo(int w, int h)
{
- doubleBuffer = true;
- stereoView = false;
}
- public void init()
+ public void cleanup(GLDrawable drawable)
+ {
+ }
+
+ public void init(GLDrawable drawable)
{
+ gl = drawable.getGL();
+ glu = drawable.getGLU();
+ glj = drawable.getGLContext();
+
// Examine some OpenGL properties
int [] res=new int[6];
gl.glGetIntegerv(GL_STENCIL_BITS,res);
System.out.println("init(): " + this + "\n\t" +
- "Stencil bits are "+res[0] +"\n\t" +
- "IsOwnCreatedWindow: "+createOwnWindow);
+ "Stencil bits are "+res[0] +"\n\t");
float yellow_diffuse[] = { 0.7f, 0.7f, 0.0f, 1.0f };
float yellow_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
@@ -195,16 +214,9 @@ public class stencil extends Applet glj.gljCheckGL();
initdone = true;
- reshape(getSize().width, getSize().height);
}
- public void cvsDispose()
- {
- System.out.println("destroy(): " + this);
- super.cvsDispose();
- }
-
- public void reshape(int width, int height)
+ public void reshape(gl4java.drawable.GLDrawable d,int width,int height)
{
gl.glViewport(0,0,width,height);
@@ -247,10 +259,8 @@ public class stencil extends Applet gl.glTranslatef(0.0f, 0.0f, -5.0f);
}
- public void display()
+ public void display(GLDrawable drawable)
{
- if (glj.gljMakeCurrent() == false) return;
-
/* Draw a sphere in a diamond-shaped section in the
* middle of a window with 2 torii.
*/
@@ -281,11 +291,17 @@ public class stencil extends Applet gl.glPopMatrix();
gl.glPopMatrix();
- glj.gljSwap();
glj.gljCheckGL();
- glj.gljFree();
}
+ public void preDisplay(GLDrawable drawable)
+ {
+ }
+
+ public void postDisplay(GLDrawable drawable)
+ {
+ }
+
// Imported from glut.
private void glutSolidTorus
(float innerRadius,
|