aboutsummaryrefslogtreecommitdiffstats
path: root/demos/MiscDemos/gearsFullScreen.java
blob: 8cabd83440137a57b385f1c2257b2a34e2243434 (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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
 * @(#) gearsFullScreen.java
 * @(#) author: Brian Paul (converted to Java by Ron Cemer and Sven Goethel)
 *
 * This version is equal to Brian Paul's version 1.2 1999/10/21
 */

import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.*;
import java.io.*;
import gl4java.*;
import gl4java.drawable.*;
import gl4java.awt.GLAnimCanvas;
import gl4java.applet.SimpleGLAnimApplet1;

public class gearsFullScreen extends SimpleGLAnimApplet1 
    implements MouseListener
{

        /* Initialize the applet */
	public void init()
	{
	  init(false);
	}

	public void init(boolean showGL)
	{
	super.init();

        Dimension d = getSize();

        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);
	}

	public void destroy()
	{
            removeMouseListener(this);
	    super.destroy();
	}


	public static void main( String args[] ) 
	{
		int i = 0;
		String gljLib = null;
		String glLib = null;
		String gluLib = null;
		boolean perftest=false;

	        GLContext.gljNativeDebug = false;
	        GLContext.gljClassDebug = false;
	        GLContext.gljThreadDebug = false;

		while(args.length>i)
		{
			if(args[i].equals("-perftest"))
			{
				perftest=true;
			} else if(args[i].equals("-gljLib"))
			{
				i++;
				if(args.length>i)
					gljLib=args[i];
			} else if(args[i].equals("-glLib"))
			{
				i++;
				if(args.length>i)
					glLib=args[i];
			} else if(args[i].equals("-gluLib"))
			{
				i++;
				if(args.length>i)
					gluLib=args[i];
			} else {
			  System.out.println("illegal arg "+i+": "+args[i]);
			}
			i++;
		}

		if(perftest)
		{
			GLContext.gljNativeDebug = false;
			GLContext.gljThreadDebug = false;
			GLContext.gljClassDebug = false;
		}

		if(perftest)
			GLContext.gljClassDebug=true;
		GLContext.doLoadNativeLibraries(gljLib, glLib, gluLib);
		if(perftest)
			GLContext.gljClassDebug=false;

	        GraphicsEnvironment env = 
			GraphicsEnvironment.getLocalGraphicsEnvironment();
	        GraphicsDevice device = env.getDefaultScreenDevice();
		Frame mainFrame = null;

		System.out.println("isFullScreenSupported: "+
			device.isFullScreenSupported() );

		try {
		        GraphicsConfiguration gc ;
			gl4java.drawable.GLDrawableFactory df =
				gl4java.drawable.GLDrawableFactory.getFactory();
		 
			if(df instanceof gl4java.drawable.SunJDK13GLDrawableFactory)
			{
			    GLCapabilities glCaps = new GLCapabilities();
			    gl4java.drawable.SunJDK13GLDrawableFactory sdf =
			      (gl4java.drawable.SunJDK13GLDrawableFactory)df;

			    gc = sdf.getGraphicsConfiguration(glCaps, device);	
			} else {
		            gc = device.getDefaultConfiguration();
			}

		        mainFrame = new Frame(gc);

		        gearsFullScreen applet = new gearsFullScreen();
        		mainFrame.add(applet);
        		applet.setSize(400,500);
        		applet.init();
        
        		if(perftest)
        		{
        			applet.canvas.setUseFpsSleep(false);
        			applet.canvas.setUseRepaint(false);
        			applet.canvas.setUseYield(false);
        
        			System.out.println("useFpsSleep: "+
        				applet.canvas.getUseFpsSleep());
        			System.out.println("useRepaint: "+
        				applet.canvas.getUseRepaint());
        
        			System.out.println("useFpsSleep: "+
        				applet.canvas.getUseFpsSleep());
        		}
        
        		applet.start();
        
        		Dimension ps = applet.getPreferredSize();
        		mainFrame.setBounds(-100,-100,99,99);
        		mainFrame.setVisible(true);
        		mainFrame.setVisible(false);
        		mainFrame.setVisible(true);
        		Insets is = mainFrame.getInsets();
        		mainFrame.setBounds(0,0,
        			    ps.width+is.left+is.right, 
        			    ps.height+is.top+is.bottom);
        		mainFrame.setVisible(true);
			Thread.currentThread().sleep(10000, 0 );
		} catch (Exception e) {
		    e.printStackTrace();
		} finally {
		    device.setFullScreenWindow(null);
		}

	}

        // Methods required for the implementation of MouseListener
        public void mouseEntered( MouseEvent evt )
        {
		//System.out.println("mouse entered: ");
		super.mouseEntered(evt);
        }
    
        public void mouseExited( MouseEvent evt )
        {
		//System.out.println("mouse exit: ");
		super.mouseExited(evt);
        }
    
        public void mousePressed( MouseEvent evt )
        {
		//System.out.println("mouse pressed: ");
		super.mousePressed(evt);
        }
    
        public void mouseReleased( MouseEvent evt )
        {
		//System.out.println("mouse released: ");
		super.mouseReleased(evt);
        }
    
        public void mouseClicked( MouseEvent evt )
        {
		//System.out.println("mouse clicked: ");
		super.mouseClicked(evt);

            if ((evt.getModifiers() & evt.BUTTON2_MASK) != 0)
            {
	        System.out.println("stopping applet now .. (after 1s, restart)");
		stop();
		try {
			Thread.sleep(1000);
		} catch (Exception e)
		{ System.out.println("oops, somebody woke us up .."); }
	        System.out.println("restarting applet now .. ");
		canvas.setVisible(true);
		start();
            }
        }
}