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); }
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 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 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); }
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); } }