private static void setUpLighting() {
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightModel(
       GL_LIGHT_MODEL_AMBIENT,
       BufferTools.asFlippedFloatBuffer(new float[] {0.05f, 0.05f, 0.05f, 1f}));
   glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(new float[] {0, 0, 0, 1}));
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT, GL_DIFFUSE);
 }
 protected void unpackFrameData(byte[] bytes) throws InvalidDataException {
   int marker;
   for (marker = 1; marker < bytes.length; marker++) {
     if (bytes[marker] == 0) break;
   }
   mimeType = BufferTools.byteBufferToString(bytes, 1, marker - 1);
   pictureType = bytes[marker + 1];
   marker += 2;
   int marker2;
   for (marker2 = marker; marker2 < bytes.length; marker2++) {
     if (bytes[marker2] == 0) break;
   }
   description =
       new EncodedText(bytes[0], BufferTools.copyBuffer(bytes, marker, marker2 - marker));
   imageData = BufferTools.copyBuffer(bytes, marker2 + 1, bytes.length - marker2 - 1);
 }
示例#3
0
 public void packTag(byte[] bytes) {
   Arrays.fill(bytes, (byte) 0);
   BufferTools.stringIntoByteBuffer(TAG, 0, 3, bytes, 0);
   packField(bytes, title, TITLE_LENGTH, TITLE_OFFSET);
   packField(bytes, artist, ARTIST_LENGTH, ARTIST_OFFSET);
   packField(bytes, album, ALBUM_LENGTH, ALBUM_OFFSET);
   packField(bytes, year, YEAR_LENGTH, YEAR_OFFSET);
   if (genre < 128) {
     bytes[GENRE_OFFSET] = (byte) genre;
   } else {
     bytes[GENRE_OFFSET] = (byte) (genre - 256);
   }
   if (track == null) {
     packField(bytes, comment, COMMENT_LENGTH_V1_0, COMMENT_OFFSET);
   } else {
     packField(bytes, comment, COMMENT_LENGTH_V1_1, COMMENT_OFFSET);
     String trackTemp = numericsOnly(track);
     if (trackTemp.length() > 0) {
       int trackInt = Integer.parseInt(trackTemp.toString());
       if (trackInt < 128) {
         bytes[TRACK_OFFSET] = (byte) trackInt;
       } else {
         bytes[TRACK_OFFSET] = (byte) (trackInt - 256);
       }
     }
   }
 }
示例#4
0
 private void sanityCheckTag(byte[] bytes) throws NoSuchTagException {
   if (bytes.length != TAG_LENGTH) {
     throw new NoSuchTagException("Buffer length wrong");
   }
   if (!TAG.equals(BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, 0, TAG.length()))) {
     throw new NoSuchTagException();
   }
 }
 protected void unpackDataLength(byte[] buffer, int offset) {
   dataLength =
       BufferTools.unpackInteger(
           (byte) 0,
           buffer[offset + DATA_LENGTH_OFFSET],
           buffer[offset + DATA_LENGTH_OFFSET + 1],
           buffer[offset + DATA_LENGTH_OFFSET + 2]);
 }
 private static void checkInput() {
   camera.processMouse(1, 80, -80);
   camera.processKeyboard(16, 1, 1, 1);
   glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(lightPosition));
   if (Keyboard.isKeyDown(Keyboard.KEY_G)) {
     lightPosition = new float[] {camera.x(), camera.y(), camera.z(), 1};
   }
   if (Mouse.isButtonDown(0)) Mouse.setGrabbed(true);
   else if (Mouse.isButtonDown(1)) Mouse.setGrabbed(false);
 }
 private static void setUpStates() {
   glShadeModel(GL_SMOOTH);
   glEnable(GL_DEPTH_TEST);
   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glLightModel(
       GL_LIGHT_MODEL_AMBIENT,
       BufferTools.asFlippedFloatBuffer(new float[] {0.05f, 0.05f, 0.05f, 1f}));
   glLight(GL_LIGHT0, GL_POSITION, BufferTools.asFlippedFloatBuffer(new float[] {0, 0, 0, 1}));
   glEnable(GL_CULL_FACE);
   glCullFace(GL_BACK);
   glEnable(GL_COLOR_MATERIAL);
   glColorMaterial(GL_FRONT, GL_DIFFUSE);
   glColor3f(0.4f, 0.27f, 0.17f);
   glMaterialf(GL_FRONT, GL_SHININESS, 10f);
   if (GLContext.getCapabilities().GL_ARB_depth_clamp) {
     glEnable(ARBDepthClamp.GL_DEPTH_CLAMP);
   }
 }
 private static void render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   camera.applyTranslations();
   glUseProgram(currentShaderProgram);
   glLight(
       GL_LIGHT0,
       GL_POSITION,
       BufferTools.asFlippedFloatBuffer(camera.x(), camera.y(), camera.z(), 1));
   glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3);
 }
 protected byte[] packFrameData() {
   byte[] bytes = new byte[getLength()];
   if (description != null) bytes[0] = description.getTextEncoding();
   else bytes[0] = 0;
   int mimeTypeLength = 0;
   if (mimeType != null && mimeType.length() > 0) {
     mimeTypeLength = mimeType.length();
     BufferTools.stringIntoByteBuffer(mimeType, 0, mimeTypeLength, bytes, 1);
   }
   bytes[mimeTypeLength + 1] = 0;
   bytes[mimeTypeLength + 2] = pictureType;
   int descriptionLength = 0;
   if (description != null && description.toBytes().length > 0) {
     descriptionLength = description.toBytes().length;
     BufferTools.copyIntoByteBuffer(
         description.toBytes(), 0, descriptionLength, bytes, mimeTypeLength + 3);
   }
   bytes[mimeTypeLength + descriptionLength + 3] = 0;
   if (imageData != null && imageData.length > 0) {
     BufferTools.copyIntoByteBuffer(
         imageData, 0, imageData.length, bytes, mimeTypeLength + descriptionLength + 4);
   }
   return bytes;
 }
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     int vboVertexHandle = glGenBuffers();
     int vboNormalHandle = glGenBuffers();
     FloatBuffer vertices = BufferTools.reserveData(model.faces.size() * 9);
     FloatBuffer normals = BufferTools.reserveData(model.faces.size() * 9);
     for (Face face : model.faces) {
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.x - 1)));
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.y - 1)));
       vertices.put(BufferTools.asFloats(model.vertices.get((int) face.vertex.z - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.x - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.y - 1)));
       normals.put(BufferTools.asFloats(model.normals.get((int) face.normal.z - 1)));
     }
     vertices.flip();
     normals.flip();
     glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
     glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
     glEnableVertexAttribArray(attributeVertex);
     glVertexAttribPointer(attributeVertex, 3, false, 0, vertices);
     glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
     glEnableVertexAttribArray(attributeNormal);
     glBufferData(GL_ARRAY_BUFFER, normals, GL_STATIC_DRAW);
     glNormalPointer(GL_FLOAT, 0, 0L);
     // TODO: This really isn't finished yet. :-(
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
 }
示例#11
0
 protected void packFlags(byte[] bytes, int offset) {
   bytes[offset + FLAGS_OFFSET] =
       BufferTools.setBit(bytes[offset + FLAGS_OFFSET], UNSYNCHRONISATION_BIT, unsynchronisation);
   bytes[offset + FLAGS_OFFSET] =
       BufferTools.setBit(bytes[offset + FLAGS_OFFSET], COMPRESSION_BIT, compression);
 }
示例#12
0
 protected void unpackFlags(byte[] bytes) {
   unsynchronisation = BufferTools.checkBit(bytes[FLAGS_OFFSET], UNSYNCHRONISATION_BIT);
   compression = BufferTools.checkBit(bytes[FLAGS_OFFSET], COMPRESSION_BIT);
 }
示例#13
0
 private void unpackTag(byte[] bytes) throws NoSuchTagException {
   sanityCheckTag(bytes);
   title =
       BufferTools.trimStringRight(
           BufferTools.byteBufferToStringIgnoringEncodingIssues(
               bytes, TITLE_OFFSET, TITLE_LENGTH));
   artist =
       BufferTools.trimStringRight(
           BufferTools.byteBufferToStringIgnoringEncodingIssues(
               bytes, ARTIST_OFFSET, ARTIST_LENGTH));
   album =
       BufferTools.trimStringRight(
           BufferTools.byteBufferToStringIgnoringEncodingIssues(
               bytes, ALBUM_OFFSET, ALBUM_LENGTH));
   year =
       BufferTools.trimStringRight(
           BufferTools.byteBufferToStringIgnoringEncodingIssues(bytes, YEAR_OFFSET, YEAR_LENGTH));
   genre = bytes[GENRE_OFFSET] & 0xFF;
   if (genre == 0xFF) {
     genre = -1;
   }
   if (bytes[TRACK_MARKER_OFFSET] != 0) {
     comment =
         BufferTools.trimStringRight(
             BufferTools.byteBufferToStringIgnoringEncodingIssues(
                 bytes, COMMENT_OFFSET, COMMENT_LENGTH_V1_0));
     track = null;
   } else {
     comment =
         BufferTools.trimStringRight(
             BufferTools.byteBufferToStringIgnoringEncodingIssues(
                 bytes, COMMENT_OFFSET, COMMENT_LENGTH_V1_1));
     int trackInt = bytes[TRACK_OFFSET];
     if (trackInt == 0) {
       track = "";
     } else {
       track = Integer.toString(trackInt);
     }
   }
 }
示例#14
0
 private void packField(byte[] bytes, String value, int maxLength, int offset) {
   if (value != null) {
     BufferTools.stringIntoByteBuffer(
         value, 0, Math.min(value.length(), maxLength), bytes, offset);
   }
 }
 protected int unpackHeader(byte[] buffer, int offset) {
   id =
       BufferTools.byteBufferToStringIgnoringEncodingIssues(buffer, offset + ID_OFFSET, ID_LENGTH);
   unpackDataLength(buffer, offset);
   return offset + HEADER_LENGTH;
 }