1 /* 2 * Copyright (c) 2002-2008 LWJGL Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'LWJGL' nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 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 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.lwjgl.test.openal; 33 34 import java.nio.FloatBuffer; 35 36 import org.lwjgl.BufferUtils; 37 import org.lwjgl.openal.AL; 38 import org.lwjgl.openal.AL10; 39 import org.lwjgl.openal.ALC10; 40 import org.lwjgl.opengl.DisplayMode; 41 42 /** 43 * 44 * This is a basic test, which contains the most used stuff 45 * 46 * @author Brian Matzon <brian@matzon.dk> 47 * @version $Revision$ 48 * $Id$ 49 */ 50 public abstract class BasicTest { 51 52 /** 53 * Creates an instance of PlayTest 54 */ BasicTest()55 protected BasicTest() { 56 try { 57 AL.create(); 58 59 System.out.println("Default device: " + ALC10.alcGetString(null, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER)); 60 61 if(ALC10.alcIsExtensionPresent(null, "ALC_ENUMERATION_EXT")) { 62 String[] devices = ALC10.alcGetString(null, ALC10.ALC_DEVICE_SPECIFIER).split("\0"); 63 System.out.println("Available devices: "); 64 for(int i=0; i<devices.length; i++) { 65 System.out.println(i +": " + devices[i]); 66 } 67 } 68 } catch (Exception e) { 69 System.out.println("Unable to create OpenAL.\nPlease make sure that OpenAL is available on this system. Exception: " + e); 70 return; 71 } 72 } 73 74 /** 75 * Shutdowns OpenAL 76 */ alExit()77 protected void alExit() { 78 if(AL.isCreated()) { 79 AL.destroy(); 80 } 81 } 82 83 /** 84 * Creates a float buffer to hold specified float array 85 * - strictly a utility method 86 * 87 * @param array to hold 88 * @return created FloatBuffer 89 */ createFloatBuffer(float[] data)90 protected FloatBuffer createFloatBuffer(float[] data) { 91 FloatBuffer temp = BufferUtils.createFloatBuffer(data.length).put(data); 92 temp.flip(); 93 return temp; 94 } 95 96 /** 97 * Pauses the invoking thread for specified milliseconds 98 * 99 * @param time Milliseconds to sleep 100 */ pause(long time)101 protected void pause(long time) { 102 try { 103 Thread.sleep(time); 104 } catch (InterruptedException inte) { 105 } 106 } 107 108 /** 109 * Exits the test NOW, printing errorcode to stdout 110 * 111 * @param error Error code causing exit 112 */ exit(int error)113 protected void exit(int error) { 114 System.out.println("OpenAL Error: " + AL10.alGetString(error)); 115 alExit(); 116 System.exit(-1); 117 } 118 119 /** 120 * Sets the display mode for fullscreen mode 121 */ setDisplayMode()122 protected boolean setDisplayMode() { 123 try { 124 // get modes 125 DisplayMode[] dm = org.lwjgl.util.Display.getAvailableDisplayModes(640, 480, -1, -1, -1, -1, 60, 60); 126 127 org.lwjgl.util.Display.setDisplayMode(dm, new String[] { 128 "width=" + 640, 129 "height=" + 480, 130 "freq=" + 60, 131 "bpp=" + org.lwjgl.opengl.Display.getDisplayMode().getBitsPerPixel() 132 }); 133 return true; 134 } catch (Exception e) { 135 e.printStackTrace(); 136 } 137 138 return false; 139 } 140 } 141