aboutsummaryrefslogtreecommitdiffstats
path: root/demos/MiscDemos/depthcue.java
blob: 3b6f04bb6aad5eda424204a2913059f6677a269a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
 * @(#) depthcue.java
 * @(#) author: Silicon Graphics, Inc. (converted to Java by Ron Cemer)
 */

/*
 *  This program demonstrates lots of material properties.
 *  A single light source illuminates the objects.
 */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import java.util.*;
import gl4java.GLContext;
import gl4java.awt.GLCanvas;

import gl4java.utils.glut.*;

public class depthcue extends Applet 
{
    depthcueCanvas canvas = null;


        /* Initialize the applet */


	public void init()
	{
        Dimension d = getSize();
        setLayout(new BorderLayout());
        canvas = new depthcueCanvas(d.width, d.height);
        add("Center", canvas);
	}


        /* Start the applet */


    public void start()
    {
    }


        /* Stop the applet */


    public void stop()
    {
    }

	public static void main( String args[] ) 
	{
		Frame mainFrame = new Frame("teapots");

		depthcue applet = new depthcue();

		applet.setSize(400, 400);
		applet.init();
		applet.start();

		mainFrame.add(applet);

		mainFrame.pack();
		mainFrame.setVisible(true);
	}


        /* Local GLCanvas extension class */


    private class depthcueCanvas extends GLCanvas
    {
	GLUTFunc glut = null;

        public depthcueCanvas(int w, int h)
        {
            super(w, h);
            GLContext.gljNativeDebug = false;
            GLContext.gljClassDebug = false;
        }
    
        public void preInit()
        {
            doubleBuffer = true;
            stereoView = false;
        }
    
/*  Initialize depthcuealia(float)Math.sing for RGBA mode, including alpha 
 *  blending, hint, and line width.  Print out implementation 
 *  specific info on line width granularity and width.
 */
        public void init()
        {
	    glut = new GLUTFuncLightImpl(gl, glu);
	
            reshape(getSize().width, getSize().height);

	    float fogColor[] = {0.0f, 0.0f, 0.0f, 1.0f};

	     gl.glEnable(GL_FOG);
	     gl.glFogi (GL_FOG_MODE, GL_LINEAR);
	     gl.glHint (GL_FOG_HINT, GL_NICEST);  /*  per pixel   */
	     gl.glFogf (GL_FOG_START, 3.0f);
	     gl.glFogf (GL_FOG_END, 5.0f);
	     gl.glFogfv (GL_FOG_COLOR, fogColor);
	     gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

	    gl.glShadeModel(GL_FLAT);
	    gl.glDepthFunc(GL_LESS);
	    gl.glEnable(GL_DEPTH_TEST);
	}

        public void display()
	{
            if (glj.gljMakeCurrent() == false) return;
	    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	    gl.glColor3f (1.0f, 1.0f, 1.0f);
	    glut.glutWireIcosahedron();
	    glj.gljSwap();
	    glj.gljFree();
	}

        public void reshape(int w, int h)
	{
	    gl.glViewport(0, 0, w, h);
	    gl.glMatrixMode(GL_PROJECTION);
	    gl.glLoadIdentity();
	    glu.gluPerspective (45.0f, (float) w/(float) h, 3.0f, 5.0f);

	    gl.glMatrixMode(GL_MODELVIEW);
	    gl.glLoadIdentity ();
	    gl.glTranslatef (0.0f, 0.0f, -4.0f);  /*  move object into view   */
	}
    }
}