Package java.nio

Examples of java.nio.IntBuffer


      angleRotation = MAX_SPEED;
    }
  }

  private void destroyTexture() {
    IntBuffer buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    buffer.put(0, tex_handle);
    glDeleteTextures(buffer);
  }
View Full Code Here


    Display.setVSyncEnabled(true);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glEnable(GL_TEXTURE_2D);
    // Create shared texture
    IntBuffer buffer = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
    glGenTextures(buffer);
    tex_handle = buffer.get(0);
    glBindTexture(GL_TEXTURE_2D, tex_handle);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
View Full Code Here

    glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
    if ( !GLContext.getCapabilities().GL_ARB_vertex_buffer_object ) {
      System.out.println("ARB VBO not supported!");
      System.exit(1);
    }
    IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
    glGenBuffersARB(int_buffer);
    buffer_id = int_buffer.get(0);
    indices_buffer_id = int_buffer.get(1);
    glBindBufferARB(GL_ARRAY_BUFFER_ARB, buffer_id);
    glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indices_buffer_id);
    vertices = ByteBuffer.allocateDirect(2 * 4 * 4).order(ByteOrder.nativeOrder()).asFloatBuffer();
    vertices.put(-50).put(-50).put(50).put(-50).put(50).put(50).put(-50).put(50);
    vertices.rewind();
 
View Full Code Here

  /**
   * Cleanup
   */
  private static void cleanup() {
    IntBuffer int_buffer = ByteBuffer.allocateDirect(8).order(ByteOrder.nativeOrder()).asIntBuffer();
    int_buffer.put(0, buffer_id);
    int_buffer.put(1, indices_buffer_id);
    glDeleteBuffersARB(int_buffer);
    Display.destroy();
  }
View Full Code Here

   */
  private void executeAudioTest() {
    int lastError;

    //create 1 buffer and 1 source
    IntBuffer buffers = createIntBuffer(1);
    IntBuffer sources = createIntBuffer(1);

    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //load wave data
    WaveData wavefile = WaveData.create("Footsteps.wav");

    //copy to buffers
    AL10.alBufferData(
      buffers.get(0),
      wavefile.format,
      wavefile.data,
      wavefile.samplerate);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //unload file again
    wavefile.dispose();

    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //wait 5 secs
    try {
      System.out.print("Playing 'Footsteps.wav' for 2 seconds...");
      Thread.sleep(2000);
    } catch (InterruptedException inte) {
    }
    System.out.println("done");

    //stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

    //delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
      exit(lastError);
    }

View Full Code Here

    // Attach UBO and associate uniform block to binding point 0
    glBindBufferBase(GL_UNIFORM_BUFFER, 0, bufferID);
    glUniformBlockBinding(programID, blockIndex, 0);

    // Get uniform information
    IntBuffer indexes = BufferUtils.createIntBuffer(uniformNames.length);
    IntBuffer params = BufferUtils.createIntBuffer(uniformNames.length);

    glGetUniformIndices(programID, uniformNames, indexes);
    uniformA_index = indexes.get(0);
    uniformB_index = indexes.get(1);

    glGetActiveUniforms(programID, indexes, GL_UNIFORM_OFFSET, params);
    uniformA_offset = params.get(0);
    uniformB_offset = params.get(1);

    System.out.println("\nuniformA index = " + uniformA_index);
    System.out.println("uniformB index = " + uniformB_index);

    System.out.println("\nuniformA offset = " + uniformA_offset + " - should be 0 for std140");
View Full Code Here

   */
  protected void CreateAllSources() {
    int lastError;

    //make bytbuffer that can hold sourcesToCreate sources
    IntBuffer sources = BufferUtils.createIntBuffer(sourcesToCreate);

    //Create sourcesToCreate sources in one fell swoop
    try {
      sources.position(0).limit(sourcesToCreate);
      AL10.alGenSources(sources);
 
      //delete sources
      sources.position(0).limit(sourcesToCreate);
      AL10.alDeleteSources(sources);

      System.out.println("created " + sourcesToCreate + " sources successfully!");
    } catch (OpenALException oale) {
      System.out.println("Unable to create " + sourcesToCreate + " sources");
View Full Code Here

  protected void execute(String[] args) {
    //error stuff
    int lastError = ALC10.ALC_NO_ERROR;

    //create attribute list for context creation
    IntBuffer buffer = BufferUtils.createIntBuffer(7);

    if ((lastError = ALC10.alcGetError(AL.getDevice())) != ALC10.ALC_NO_ERROR) {
      System.out.println("ALC Error: " + ALC10.alcGetString(AL.getDevice(), lastError));
      System.exit(-1);
    }

    //query       
    System.out.println(
      "DEFAULT_DEVICE_SPECIFIER: "
        + ALC10.alcGetString(AL.getDevice(), ALC10.ALC_DEFAULT_DEVICE_SPECIFIER));
    System.out.println(
      "DEVICE_SPECIFIER: " + ALC10.alcGetString(AL.getDevice(), ALC10.ALC_DEVICE_SPECIFIER));
    System.out.println("EXTENSIONS: " + ALC10.alcGetString(AL.getDevice(), ALC10.ALC_EXTENSIONS));

    //mo query
    buffer.rewind();
    buffer.position(0);
      ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MAJOR_VERSION, buffer);
      ALC10.alcGetInteger(AL.getDevice(), ALC10.ALC_MINOR_VERSION, (IntBuffer) buffer.position(1));

    System.out.println("ALC_MAJOR_VERSION: " + buffer.get(0));
    System.out.println("ALC_MINOR_VERSION: " + buffer.get(1));

    //no check for ALC_ALL_ATTRIBUTES / ALC_ATTRIBUTES_SIZE since it
    //is buggy on win32 - my dev platform

    //get an enumerstion value
View Full Code Here

  /**
   * Runs the actual test, using supplied arguments
   */
  protected void execute(String[] args) {
    int lastError = ALC10.ALC_NO_ERROR;
    IntBuffer sampleCount = BufferUtils.createIntBuffer(1);
   
    int state = AL10.AL_PLAYING;
    int FMT = AL10.AL_FORMAT_MONO16;
    int FMTSIZE  = 16/8;
    int FREQ = 44100;
    int TIME = 5;
    int SAMPS = (FREQ * TIME);
    ByteBuffer buf = BufferUtils.createByteBuffer(SAMPS * FMTSIZE);   

    // check that capture is available
    if(!ALC10.alcIsExtensionPresent(AL.getDevice(), "ALC_EXT_CAPTURE")) {
      throw new OpenALException("ALC_EXT_CAPTURE extension not available");
    }
   
    // get list of devices
    String[] captureDevices = ALC10.alcGetString(null, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER).split("\0");
    System.out.println("Available Capture Devices: ");
    for(int i=0; i<captureDevices.length; i++) {
      System.out.println(i + ": " + captureDevices[i]);
    }
   
    String defaultRecorder = ALC10.alcGetString(AL.getDevice(), ALC11.ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER);
    System.out.println("Default capture device: " + defaultRecorder);
   
    ALCdevice device = ALC11.alcCaptureOpenDevice(null, FREQ, FMT, SAMPS);

    if(device != null) {
      // record some sound
      // =====================================
      System.out.print("Recording using " + ALC10.alcGetString(device, ALC11.ALC_CAPTURE_DEVICE_SPECIFIER) + "...");
      ALC11.alcCaptureStart(device);
      while (sampleCount.get(0) < SAMPS) {
        pause(1000);
        ALC10.alcGetInteger(device, ALC11.ALC_CAPTURE_SAMPLES, sampleCount);
      }
      System.out.println("done");
      ALC11.alcCaptureStop(device);

      // capure the samples
      ALC11.alcCaptureSamples(device, buf, SAMPS);
      ALC11.alcCaptureCloseDevice(device);
      // -------------------------------------
     
      // play back recording
      // ===================
          IntBuffer buffers = BufferUtils.createIntBuffer(1);
          IntBuffer sources = BufferUtils.createIntBuffer(1);       
         
          buffers.position(0).limit(1);
          AL10.alGenBuffers(buffers);

          sources.position(0).limit(1);
          AL10.alGenSources(sources);

          System.out.print("Playing...");

        AL10.alBufferData(buffers.get(0), FMT, buf, FREQ);
        AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
        AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_FALSE);
        AL10.alSourcePlay(sources.get(0));

        while (state == AL10.AL_PLAYING)
        {
            pause(100);
            state = AL10.alGetSourcei(sources.get(0), AL10.AL_SOURCE_STATE);
        }

        System.out.println("done");

        AL10.alDeleteSources(sources);
View Full Code Here

        }       
       
        int lastError;

        //create 1 buffer and 1 source
        IntBuffer buffers = BufferUtils.createIntBuffer(1);
        IntBuffer sources = BufferUtils.createIntBuffer(1);
       
        // al generate buffers and sources
        buffers.position(0).limit(1);
        AL10.alGenBuffers(buffers);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }

        sources.position(0).limit(1);
        AL10.alGenSources(sources);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }
       
        if(usingVorbis) {
          ByteBuffer filebuffer = getData(args[0]);
         
          // pass directly to buffer data
          AL10.alBufferData(buffers.get(0), AL10.AL_FORMAT_VORBIS_EXT, filebuffer, -1);
          filebuffer.clear();
        } else {
          // load wave data from buffer
          WaveData wavefile = WaveData.create(args[0]);

          //copy to buffers
          AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
         
          //unload file again
          wavefile.dispose();       
        }
       
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       

        //set up source input
        AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //lets loop the sound
        AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //play source 0
        AL10.alSourcePlay(sources.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //wait 5 secs
        try {
            System.out.println("Waiting 5 seconds for sound to complete");
            Thread.sleep(5000);
        } catch (InterruptedException inte) {
        }
       
        //stop source 0
        AL10.alSourceStop(sources.get(0));
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }       
       
        //delete buffers and sources
        sources.position(0).limit(1);
        AL10.alDeleteSources(sources);
        if((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
            exit(lastError);
        }
       
View Full Code Here

TOP

Related Classes of java.nio.IntBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.