Exemple #1
0
 public void setVolume(float volume) {
   this.baseVol = volume;
   if (this.type == 0)
     AL10.alSourcef(this.src, AL10.AL_GAIN, volume * ((float) Globals.getSoundVolume() / 100.0f));
   else
     AL10.alSourcef(this.src, AL10.AL_GAIN, volume * ((float) Globals.getMusicVolume() / 100.0f));
 }
Exemple #2
0
  public static void setWindowResolution(int width, int height) {
    Globals.windowWidth = width;
    Globals.windowHeight = height;
    Globals.aspectRatio = (float) Globals.windowWidth / (float) Globals.windowHeight;
    Globals.windowMatrix.set(
        1 / Globals.aspectRatio,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f,
        0.0f,
        0.0f,
        0.0f,
        0.0f,
        1.0f);

    // for(IWindowChangeListener lis : Globals.windowChangeListener)
    // {
    //	lis.onWindowResolutionChange(Globals.windowWidth, Globals.windowHeight);
    // }

    try {
      DisplayMode[] modes = Display.getAvailableDisplayModes();

      DisplayMode finalMode = new DisplayMode(Globals.getWindowWidth(), Globals.getWindowHeight());

      for (int i = 0; i < modes.length; i++) {
        DisplayMode current = modes[i];
        if (current.getWidth() == Globals.getWindowWidth()
            && current.getHeight() == Globals.getWindowHeight()
            && current.getBitsPerPixel() == 32
            && current.getFrequency() == 60) finalMode = current;
      }

      Display.setDisplayMode(finalMode);

      if (!Display.isCreated()) {
        PixelFormat pixelFormat = new PixelFormat();
        ContextAttribs contextAtrributes =
            new ContextAttribs(3, 2).withForwardCompatible(true).withProfileCore(true);
        Display.create(pixelFormat, contextAtrributes);
      }

      GL11.glViewport(0, 0, Globals.getWindowWidth(), Globals.getWindowHeight());
    } catch (LWJGLException e) {
      e.printStackTrace();
      System.exit(-1);
    }
    Display.update();
  }
Exemple #3
0
 /** @param windowWidth the windowWidth to set */
 public static void setWindowWidth(int windowWidth) {
   Globals.setWindowResolution(windowWidth, Globals.windowHeight);
 }
Exemple #4
0
 public static void resetFrame(String identifier, Frame f) {
   Globals.frames.remove(identifier);
   Globals.addFrame(identifier, f);
 }
Exemple #5
0
  public Sound(String filename, int type, boolean loop, float volume, float pitch) {
    String[] split = filename.split("/");
    System.out.println("loading " + split[split.length - 1]);

    try {
      AL10.alGetError();
    } catch (UnsatisfiedLinkError e) {
      Logger.info("Seems no AL sound device has been created... creating now", "Utility.loadWav");

      try {
        AL.create();
      } catch (LWJGLException e1) {

        Logger.log(e1, "Utility.loadWav", "Unable to create AL sound device");
        return;
      }
    }

    this.buf = AL10.alGenBuffers();

    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
      Logger.error(Utility.getALErrorString(AL10.alGetError()), "Sound.Sound");
    }

    if (filename.endsWith(".wav")) {
      try {

        WaveData waveFile = WaveData.create(new BufferedInputStream(new FileInputStream(filename)));
        System.out.println(waveFile == null);
        AL10.alBufferData(this.buf, waveFile.format, waveFile.data, waveFile.samplerate);
        waveFile.dispose();

      } catch (FileNotFoundException e) {
        Logger.log(e, "Sound.Sound");
        return;
      }
    } else if (filename.endsWith(".ogg") || filename.endsWith(".vorbis")) {
      try {
        OggDecoder oggDecoder = new OggDecoder();
        OggData oggData =
            oggDecoder.getData(new BufferedInputStream(new FileInputStream(filename)));
        AL10.alBufferData(
            this.buf,
            oggData.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16,
            oggData.data,
            oggData.rate);
      } catch (FileNotFoundException e) {
        Logger.log(e, "Sound.Sound");
        return;
      } catch (IOException e) {
        Logger.log(e, "Sound.Sound");
        return;
      }
    }

    this.src = AL10.alGenSources();

    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
      Logger.error(Utility.getALErrorString(AL10.alGetError()), "Utility.loadWav");
      return;
    }

    AL10.alSourcei(this.src, AL10.AL_BUFFER, this.buf);
    AL10.alSourcef(this.src, AL10.AL_PITCH, pitch);
    AL10.alSourcef(this.src, AL10.AL_GAIN, volume);

    FloatBuffer sourcePos =
        (FloatBuffer) BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).rewind();
    FloatBuffer sourceVel =
        (FloatBuffer) BufferUtils.createFloatBuffer(3).put(new float[] {0.0f, 0.0f, 0.0f}).rewind();

    AL10.alSource(this.src, AL10.AL_POSITION, sourcePos);
    AL10.alSource(this.src, AL10.AL_VELOCITY, sourceVel);

    this.type = type;

    this.setLoop(loop);
    this.setPitch(pitch);
    this.setVolume(volume);

    Globals.addVolumeChangedListener(this);
  }
Exemple #6
0
 public static void resetFrame(String identifier) {
   Globals.getFrame(identifier).reset();
 }