コード例 #1
0
 private static void render() {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   glLoadIdentity();
   cam.applyTranslations();
   glUseProgram(shaderProgram);
   glLight(GL_LIGHT0, GL_POSITION, asFloatBuffer(cam.x(), cam.y(), cam.z(), 1));
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glColor3f(0.4f, 0.27f, 0.17f);
   glMaterialf(GL_FRONT, GL_SHININESS, 10f);
   glDrawArrays(GL_TRIANGLES, 0, model.faces.size() * 3);
   glDisableClientState(GL_VERTEX_ARRAY);
   glDisableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, 0);
   glUseProgram(0);
 }
コード例 #2
0
 private static void setUpVBOs() {
   int[] vbos;
   try {
     model = OBJLoader.loadModel(new File(MODEL_LOCATION));
     vbos = OBJLoader.createVBO(model);
     vboVertexHandle = vbos[0];
     vboNormalHandle = vbos[1];
   } catch (FileNotFoundException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   } catch (IOException e) {
     e.printStackTrace();
     cleanUp();
     System.exit(1);
   }
   glEnableClientState(GL_VERTEX_ARRAY);
   glEnableClientState(GL_NORMAL_ARRAY);
   glBindBuffer(GL_ARRAY_BUFFER, vboVertexHandle);
   glVertexPointer(3, GL_FLOAT, 0, 0L);
   glBindBuffer(GL_ARRAY_BUFFER, vboNormalHandle);
   glNormalPointer(GL_FLOAT, 0, 0L);
 }
コード例 #3
0
 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);
   }
 }