~ubuntu-branches/ubuntu/oneiric/lwjgl/oneiric

« back to all changes in this revision

Viewing changes to src/java/org/lwjgl/test/DisplayTest.java

  • Committer: Bazaar Package Importer
  • Author(s): Michael Gilbert, Michael Gilbert, Niels Thykier
  • Date: 2011-05-08 22:50:00 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110508225000-w0fmroiy6kvgo944
Tags: 2.7.1+dfsg-1
[ Michael Gilbert ]
* new upstream release:
  - refresh debian patches.
* add myself as an uploader.
* don't build-depend on sun-java-6
* use jh_clean

[ Niels Thykier ]
* Bumped Standards-Version to 3.9.2 - no changes required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* 
 
1
/*
2
2
 * Copyright (c) 2002-2008 LWJGL Project
3
3
 * All rights reserved.
4
 
 * 
 
4
 *
5
5
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are 
 
6
 * modification, are permitted provided that the following conditions are
7
7
 * met:
8
 
 * 
9
 
 * * Redistributions of source code must retain the above copyright 
 
8
 *
 
9
 * * Redistributions of source code must retain the above copyright
10
10
 *   notice, this list of conditions and the following disclaimer.
11
11
 *
12
12
 * * Redistributions in binary form must reproduce the above copyright
13
13
 *   notice, this list of conditions and the following disclaimer in the
14
14
 *   documentation and/or other materials provided with the distribution.
15
15
 *
16
 
 * * Neither the name of 'LWJGL' nor the names of 
17
 
 *   its contributors may be used to endorse or promote products derived 
 
16
 * * Neither the name of 'LWJGL' nor the names of
 
17
 *   its contributors may be used to endorse or promote products derived
18
18
 *   from this software without specific prior written permission.
19
 
 * 
 
19
 *
20
20
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
21
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22
22
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23
 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
24
 
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
25
 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
26
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 
 
23
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 
24
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 
25
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 
26
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27
27
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28
 
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
 
28
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29
29
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30
30
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
31
 */
40
40
 * Test class for Display & DisplayMode
41
41
 *
42
42
 * @author Brian Matzon <brian@matzon.dk>
43
 
 * @version $Revision: 2983 $
44
 
 * $Id: DisplayTest.java 2983 2008-04-07 18:36:09Z matzon $
 
43
 * @version $Revision: 3418 $
 
44
 * $Id: DisplayTest.java 3418 2010-09-28 21:11:35Z spasi $
45
45
 */
46
46
public class DisplayTest {
47
 
  
 
47
 
48
48
  /**
49
49
   * Creates a new DisplayTest
50
50
   */
51
51
  public DisplayTest() {
52
52
  }
53
 
  
 
53
 
54
54
  /**
55
55
   * Runs the tests
56
56
   */
58
58
    currentTest();
59
59
    queryModesTest();
60
60
    setDisplayModeTest();
61
 
    setDisplayConfigurationTest();    
 
61
    setDisplayConfigurationTest();
62
62
  }
63
 
  
 
63
 
64
64
  /**
65
65
   * Prints some info about the current mode
66
66
   */
67
67
  private void currentTest() {
68
68
    System.out.println("==== Test Current ====");
69
 
    
 
69
 
70
70
    System.out.println("Info about current:");
71
71
    System.out.println("Graphics card: " + Display.getAdapter() + ", version: " + Display.getVersion());
72
 
    System.out.println("Resolution: " + 
73
 
        Display.getDisplayMode().getWidth()      + "x" + 
74
 
        Display.getDisplayMode().getHeight()     + "x" + 
75
 
        Display.getDisplayMode().getBitsPerPixel()      + "@" + 
 
72
    System.out.println("Resolution: " +
 
73
        Display.getDisplayMode().getWidth()      + "x" +
 
74
        Display.getDisplayMode().getHeight()     + "x" +
 
75
        Display.getDisplayMode().getBitsPerPixel()      + "@" +
76
76
        Display.getDisplayMode().getFrequency()  + "Hz");
77
77
    System.out.println("---- Test Current ----");
78
78
  }
79
 
  
 
79
 
80
80
  /**
81
81
   * Tests querying for modes
82
82
   */
83
83
  private void queryModesTest() throws LWJGLException {
84
84
    DisplayMode[] modes = null;
85
 
    
 
85
 
86
86
    System.out.println("==== Test query ====");
87
87
    System.out.println("Retrieving available displaymodes");
88
88
    modes = Display.getAvailableDisplayModes();
92
92
      System.out.println("FATAL: unable to find any modes!");
93
93
      System.exit(-1);
94
94
    }
95
 
    
 
95
 
96
96
    // write some info
97
97
    System.out.println("Found " + modes.length + " modes");
98
98
    System.out.println("The first 5 are:");
104
104
    }
105
105
    System.out.println("---- Test query ----");
106
106
  }
107
 
  
108
 
  
 
107
 
 
108
 
109
109
  /**
110
110
   * Tests setting display modes
111
111
   */
112
112
  private void setDisplayModeTest() throws LWJGLException {
113
113
    DisplayMode mode = null;
114
114
    DisplayMode[] modes = null;
115
 
    
 
115
 
116
116
    System.out.println("==== Test setDisplayMode ====");
117
117
    System.out.println("Retrieving available displaymodes");
118
118
    modes = Display.getAvailableDisplayModes();
119
 
    
 
119
 
120
120
    // no modes check
121
121
    if (modes == null) {
122
122
      System.out.println("FATAL: unable to find any modes!");
123
123
      System.exit(-1);
124
124
    }
125
 
    
 
125
 
126
126
    // find a mode
127
127
    System.out.print("Looking for 640x480...");
128
 
    for(int i=0; i<modes.length;i++) {
129
 
      if (modes[i].getWidth()  == 640  &&
130
 
          modes[i].getHeight() == 480) {
131
 
        mode = modes[i];
132
 
        System.out.println("found!");
133
 
        break;
134
 
      }
135
 
    }
136
 
    
 
128
          for ( DisplayMode mode1 : modes ) {
 
129
                  if ( mode1.getWidth() == 640 &&
 
130
                       mode1.getHeight() == 480 ) {
 
131
                          mode = mode1;
 
132
                          System.out.println("found!");
 
133
                          break;
 
134
                  }
 
135
          }
 
136
 
137
137
    // no mode check
138
138
    if (mode == null) {
139
139
      System.out.println("error\nFATAL: Unable to find basic mode.");
140
140
      System.exit(-1);
141
141
    }
142
 
    
 
142
 
143
143
    // change to mode, and wait a bit
144
144
    System.out.print("Changing to mode...");
145
145
    try {
151
151
      System.exit(-1);
152
152
    }
153
153
    System.out.println("done");
154
 
    
155
 
    System.out.println("Resolution: " + 
156
 
        Display.getDisplayMode().getWidth()      + "x" + 
157
 
        Display.getDisplayMode().getHeight()     + "x" + 
158
 
        Display.getDisplayMode().getBitsPerPixel()      + "@" + 
 
154
 
 
155
    System.out.println("Resolution: " +
 
156
        Display.getDisplayMode().getWidth()      + "x" +
 
157
        Display.getDisplayMode().getHeight()     + "x" +
 
158
        Display.getDisplayMode().getBitsPerPixel()      + "@" +
159
159
        Display.getDisplayMode().getFrequency()  + "Hz");
160
 
    
 
160
 
161
161
    pause(5000);
162
162
 
163
163
    // reset
168
168
        e.printStackTrace();
169
169
    }
170
170
    System.out.println("done");
171
 
    
172
 
    System.out.println("---- Test setDisplayMode ----");    
 
171
 
 
172
    System.out.println("---- Test setDisplayMode ----");
173
173
  }
174
 
  
 
174
 
175
175
  /**
176
176
   * Tests the DisplayConfiguration
177
177
   */
178
178
  private void setDisplayConfigurationTest() {
179
179
    System.out.println("==== Test setDisplayConfigurationTest ====");
180
 
    
 
180
 
181
181
    System.out.println("Testing normal setting");
182
182
    changeConfig(1.0f, 0f, 1f);
183
 
    
 
183
 
184
184
    System.out.println("Testing gamma settings");
185
185
    changeConfig(5.0f, 0f, 1f);
186
186
    changeConfig(0.5f, 0f, 1f);
187
 
    
 
187
 
188
188
    System.out.println("Testing brightness settings");
189
189
    changeConfig(1.0f, -1.0f, 1f);
190
190
    changeConfig(1.0f, -0.5f, 1f);
191
191
    changeConfig(1.0f, 0.5f, 1f);
192
192
    changeConfig(1.0f, 1.0f, 1f);
193
 
    
 
193
 
194
194
    System.out.println("Testing contrast settings");
195
195
    changeConfig(1.0f, 0f, 0f);
196
196
    changeConfig(1.0f, 0f, 0.5f);
197
197
    changeConfig(1.0f, 0f, 10000.0f);
198
 
    
 
198
 
199
199
    System.out.print("resetting...");
200
200
    try {
201
201
        Display.setFullscreen(false);
203
203
        e.printStackTrace();
204
204
    }
205
205
    System.out.println("done");
206
 
    
 
206
 
207
207
    System.out.println("---- Test setDisplayConfigurationTest ----");
208
208
  }
209
 
  
 
209
 
210
210
  /**
211
211
   * Changes the Displat configuration
212
 
   * 
 
212
   *
213
213
   * @param gamma gamma value to change to
214
214
   * @param brightness brightness value to change to
215
215
   * @param contrast contrast value to change to
226
226
 
227
227
  /**
228
228
   * Pause current thread for a specified time
229
 
   * 
 
229
   *
230
230
   * @param time milliseconds to sleep
231
231
   */
232
232
  private void pause(long time) {
238
238
                  } catch (InterruptedException inte) {
239
239
                  }
240
240
          }
241
 
  }  
242
 
  
 
241
  }
 
242
 
243
243
  /**
244
244
   * Tests the Sys class, and serves as basic usage test
245
 
   * 
 
245
   *
246
246
   * @param args ignored
247
247
   */
248
248
  public static void main(String[] args) throws LWJGLException {