Package java.nio

Examples of java.nio.FloatBuffer


   * @return
   */
  private static boolean __gluInvertMatrixf(FloatBuffer src, FloatBuffer inverse) {
    int i, j, k, swap;
    float t;
    FloatBuffer temp = Project.tempMatrix;


    for (i = 0; i < 16; i++) {
      temp.put(i, src.get(i + src.position()));
    }
    __gluMakeIdentityf(inverse);

    for (i = 0; i < 4; i++) {
      /*
       * * Look for largest element in column
       */
      swap = i;
      for (j = i + 1; j < 4; j++) {
        /*
         * if (fabs(temp[j][i]) > fabs(temp[i][i])) { swap = j;
         */
        if (Math.abs(temp.get(j*4 + i)) > Math.abs(temp.get(i* 4 + i))) {
          swap = j;
        }
      }

      if (swap != i) {
        /*
         * * Swap rows.
         */
        for (k = 0; k < 4; k++) {
          t = temp.get(i*4 + k);
          temp.put(i*4 + k, temp.get(swap*4 + k));
          temp.put(swap*4 + k, t);

          t = inverse.get(i*4 + k);
          inverse.put(i*4 + k, inverse.get(swap*4 + k));
          //inverse.put((i << 2) + k, inverse.get((swap << 2) + k));
          inverse.put(swap*4 + k, t);
          //inverse.put((swap << 2) + k, t);
        }
      }

      if (temp.get(i*4 + i) == 0) {
        /*
         * * No non-zero pivot. The matrix is singular, which shouldn't *
         * happen. This means the user gave us a bad matrix.
         */
        return false;
      }

      t = temp.get(i*4 + i);
      for (k = 0; k < 4; k++) {
        temp.put(i*4 + k, temp.get(i*4 + k)/t);
        inverse.put(i*4 + k, inverse.get(i*4 + k)/t);
      }
      for (j = 0; j < 4; j++) {
        if (j != i) {
          t = temp.get(j*4 + i);
          for (k = 0; k < 4; k++) {
            temp.put(j*4 + k, temp.get(j*4 + k) - temp.get(i*4 + k) * t);
            inverse.put(j*4 + k, inverse.get(j*4 + k) - inverse.get(i*4 + k) * t);
            /*inverse.put(
              (j << 2) + k,
              inverse.get((j << 2) + k) - inverse.get((i << 2) + k) * t);*/
          }
 
View Full Code Here


    direct_buffer.position(buffer.position());
    return direct_buffer;
  }

  private static FloatBuffer doNoCopyWrap(FloatBuffer buffer) {
    FloatBuffer direct_buffer = lookupBuffer(buffer);
    direct_buffer.limit(buffer.limit());
    direct_buffer.position(buffer.position());
    return direct_buffer;
  }
View Full Code Here

    CachedBuffers buffers = getCachedBuffers(buffer.remaining()*4);
    return buffer.order() == ByteOrder.LITTLE_ENDIAN ? buffers.float_buffer_little : buffers.float_buffer_big;
  }

  private static FloatBuffer doWrap(FloatBuffer buffer) {
    FloatBuffer direct_buffer = lookupBuffer(buffer);
    direct_buffer.clear();
    int saved_position = buffer.position();
    direct_buffer.put(buffer);
    buffer.position(saved_position);
    direct_buffer.flip();
    return direct_buffer;
  }
View Full Code Here

    Display.setDisplayMode(new DisplayMode(300, 300));
    Display.setTitle("Gears");
    Display.create();

    // setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});

    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
                                                                                  new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
                                                                                      0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
View Full Code Here

    setVisible(true);
  }

  private void setup() {
    //   setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("LWJGL: " + Sys.getVersion() + " / " + LWJGLUtil.getPlatformName());
    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
                                                                                  new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
                                                                                      0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
View Full Code Here

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_BLEND);

    glShadeModel(GL_SMOOTH);

    final FloatBuffer vectorBuffer = BufferUtils.createFloatBuffer(4);

    vectorBuffer.clear();
    vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
    glLight(GL_LIGHT0, GL_DIFFUSE, vectorBuffer);

    vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 1.0f).put(3, 1.0f);
    glLight(GL_LIGHT0, GL_AMBIENT, vectorBuffer);

    vectorBuffer.put(0, 1.0f).put(1, 1.0f).put(2, 0.5f).put(3, 1.0f);
    glLight(GL_LIGHT0, GL_SPECULAR, vectorBuffer);

    vectorBuffer.put(0, -1.0f / 3.0f).put(1, 1.0f / 3.0f).put(2, 1.0f / 3.0f).put(3, 0.0f); // Infinite
    glLight(GL_LIGHT0, GL_POSITION, vectorBuffer);

    vectorBuffer.put(0, 0.2f).put(1, 0.2f).put(2, 0.2f).put(3, 1.0f);
    glLightModel(GL_LIGHT_MODEL_AMBIENT, vectorBuffer);

    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHTING);
View Full Code Here

   *
   * @param array to hold
   * @return created FloatBuffer
   */
  protected FloatBuffer createFloatBuffer(float[] data) {
    FloatBuffer temp = BufferUtils.createFloatBuffer(data.length).put(data);
    temp.flip();
    return temp;
  }
View Full Code Here

      return initialized;
    }

    public boolean initialize() {
      //     setup ogl
      FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
      FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
      FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
      FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
      pos.flip();
      red.flip();
      green.flip();
      blue.flip();

      glClearColor(0, 0, 0, 1f);

      glLight(GL_LIGHT0, GL_POSITION, pos);
      glEnable(GL_CULL_FACE);
      glEnable(GL_LIGHTING);
      glEnable(GL_LIGHT0);
      glEnable(GL_DEPTH_TEST);

      /* make the gears */
      gear1 = glGenLists(1);
      glNewList(gear1, GL_COMPILE);
      glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
      gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
      glEndList();

      gear2 = glGenLists(1);
      glNewList(gear2, GL_COMPILE);
      glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
      gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
      glEndList();

      gear3 = glGenLists(1);
      glNewList(gear3, GL_COMPILE);
      glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
      gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
      glEndList();

      glEnable(GL_NORMALIZE);

      glMatrixMode(GL_PROJECTION);

      System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
      System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
      System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
      System.err.println();
      System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
      if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
        // --- not using extensions
        glLoadIdentity();
      } else {
        // --- using extensions
        final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
                                                                                    new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
                                                                                        0, 0, 1, 0, 0, 0, 0, 1});
        identityTranspose.flip();
        glLoadTransposeMatrixARB(identityTranspose);
      }

      float h = (float) 300 / (float) 300;
      glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
View Full Code Here

        throw new IllegalArgumentException("Invalid contrast value");
      int rampSize = display_impl.getGammaRampLength();
      if ( rampSize == 0 ) {
        throw new LWJGLException("Display configuration not supported");
      }
      FloatBuffer gammaRamp = BufferUtils.createFloatBuffer(rampSize);
      for ( int i = 0; i < rampSize; i++ ) {
        float intensity = (float)i / (rampSize - 1);
        // apply gamma
        float rampEntry = (float)java.lang.Math.pow(intensity, gamma);
        // apply brightness
        rampEntry += brightness;
        // apply contrast
        rampEntry = (rampEntry - 0.5f) * contrast + 0.5f;
        // Clamp entry to [0, 1]
        if ( rampEntry > 1.0f )
          rampEntry = 1.0f;
        else if ( rampEntry < 0.0f )
          rampEntry = 0.0f;
        gammaRamp.put(i, rampEntry);
      }
      display_impl.setGammaRamp(gammaRamp);
      LWJGLUtil.log("Gamma set, gamma = " + gamma + ", brightness = " + brightness + ", contrast = " + contrast);
    }
  }
View Full Code Here

    }
  }

  private void setup() {
    //   setup ogl
    FloatBuffer pos = BufferUtils.createFloatBuffer(4).put(new float[] { 5.0f, 5.0f, 10.0f, 0.0f});
    FloatBuffer red = BufferUtils.createFloatBuffer(4).put(new float[] { 0.8f, 0.1f, 0.0f, 1.0f});
    FloatBuffer green = BufferUtils.createFloatBuffer(4).put(new float[] { 0.0f, 0.8f, 0.2f, 1.0f});
    FloatBuffer blue = BufferUtils.createFloatBuffer(4).put(new float[] { 0.2f, 0.2f, 1.0f, 1.0f});
    pos.flip();
    red.flip();
    green.flip();
    blue.flip();

    glLight(GL_LIGHT0, GL_POSITION, pos);
    glEnable(GL_CULL_FACE);
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_DEPTH_TEST);

    /* make the gears */
    gear1 = glGenLists(1);
    glNewList(gear1, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
    gear(1.0f, 4.0f, 1.0f, 20, 0.7f);
    glEndList();

    gear2 = glGenLists(1);
    glNewList(gear2, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
    gear(0.5f, 2.0f, 2.0f, 10, 0.7f);
    glEndList();

    gear3 = glGenLists(1);
    glNewList(gear3, GL_COMPILE);
    glMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
    gear(1.3f, 2.0f, 0.5f, 10, 0.7f);
    glEndList();

    glEnable(GL_NORMALIZE);

    glMatrixMode(GL_PROJECTION);

    System.err.println("GL_VENDOR: " + glGetString(GL_VENDOR));
    System.err.println("GL_RENDERER: " + glGetString(GL_RENDERER));
    System.err.println("GL_VERSION: " + glGetString(GL_VERSION));
    System.err.println();
    System.err.println("glLoadTransposeMatrixfARB() supported: " + GLContext.getCapabilities().GL_ARB_transpose_matrix);
    if (!GLContext.getCapabilities().GL_ARB_transpose_matrix) {
      // --- not using extensions
      glLoadIdentity();
    } else {
      // --- using extensions
      final FloatBuffer identityTranspose = BufferUtils.createFloatBuffer(16).put(
                                                                                  new float[] { 1, 0, 0, 0, 0, 1, 0, 0,
                                                                                      0, 0, 1, 0, 0, 0, 0, 1});
      identityTranspose.flip();
      glLoadTransposeMatrixARB(identityTranspose);
    }

    float h = (float) 300 / (float) 300;
    glFrustum(-1.0f, 1.0f, -h, h, 5.0f, 60.0f);
View Full Code Here

TOP

Related Classes of java.nio.FloatBuffer

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.