public static void setupLighting() { FloatBuffer lightPosition = BufferUtils.createFloatBuffer(4); lightPosition.put(0.0f).put(0.0f).put(0.0f).put(0.0f).flip(); FloatBuffer whiteLight = BufferUtils.createFloatBuffer(4); whiteLight.put(1.0f).put(1.0f).put(1.0f).put(1.0f).flip(); FloatBuffer lModelAmbient = BufferUtils.createFloatBuffer(4); lModelAmbient.put(0.4f).put(0.4f).put(0.4f).put(1.0f).flip(); glShadeModel(GL_SMOOTH); glMaterial(GL_FRONT, GL_SPECULAR, whiteLight); glMaterialf(GL_FRONT, GL_SHININESS, 50.0f); glLight(GL_LIGHT0, GL_POSITION, lightPosition); glLight(GL_LIGHT0, GL_SPECULAR, whiteLight); glLight(GL_LIGHT0, GL_DIFFUSE, whiteLight); glLightModel(GL_LIGHT_MODEL_AMBIENT, lModelAmbient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); }
@Override public void init() throws IOException { super.init(); camera = new Camera(true); camera.setPosition(-17f, 20f, 17f, 0, 0, 0, 0, 1, 0); float df = 100.0f; // Precalculate the Sine and Cosine Lookup Tables. // Basically, loop through 360 Degrees and assign the Radian // value to each array index (which represents the Degree). for (int i = 0; i < 360; i++) { g_fSinTable[i] = (float) Math.sin(AR_DegToRad(i)); g_fCosTable[i] = (float) Math.cos(AR_DegToRad(i)); } pObj = new Sphere(); pObj.setOrientation(GLU_OUTSIDE); Octree.debug = new BoundingBox(); // Turn lighting on initially Octree.turnLighting = true; // The current amount of end nodes in our tree (The nodes with vertices stored in them) Octree.totalNodesCount = 0; // This stores the amount of nodes that are in the frustum Octree.totalNodesDrawn = 0; // The maximum amount of triangles per node. If a node has equal or less // than this, stop subdividing and store the face indices in that node Octree.maxTriangles = 800; // The maximum amount of subdivisions allowed (Levels of subdivision) Octree.maxSubdivisions = 5; // The number of Nodes we've checked for collision. Octree.numNodesCollided = 0; // Wheter the Object is Colliding with anything in the World or not. octree.setObjectColliding(false); // Wheter we test the whole world for collision or just the nodes we are in. Octree.octreeCollisionDetection = true; LoadWorld(); // for(int i=0; i < g_World.getNumOfMaterials(); i++) // { // System.out.println(g_World.getMaterials(i).getName() + " indice " + i); // } // for(int i=0; i < g_World.getNumOfObjects(); i++) // { // System.out.println(g_World.getObject(i).getName()); // System.out.println(g_World.getObject(i).getMaterialID()); // System.out.println(g_World.getPObject(i).getMaterialID()); // } // System.out.println(g_World.getPMaterials(12).getColor()[0] + " " + // g_World.getPMaterials(12).getColor()[1] // + " " + g_World.getPMaterials(12).getColor()[2]); // System.out.println(g_World.getPMaterials(g_World.getPObject(6).getMaterialID())); inputManager = new InputManager(); createGameActions(); posLuz1F = Conversion.allocFloats(posLuz1); // Define a cor de fundo da janela de visualização como preto glClearColor(0, 0, 0, 1); // Ajusta iluminação glLight(GL_LIGHT0, GL_AMBIENT, Conversion.allocFloats(luzAmb1)); glLight(GL_LIGHT0, GL_DIFFUSE, Conversion.allocFloats(luzDif1)); glLight(GL_LIGHT0, GL_SPECULAR, Conversion.allocFloats(luzEsp1)); // Habilita todas as fontes de luz glEnable(GL_LIGHT0); glEnable(GL_LIGHTING); // Agora posiciona demais fontes de luz glLight(GL_LIGHT0, GL_POSITION, posLuz1F); // Habilita Z-Buffer glEnable(GL_DEPTH_TEST); // Seleciona o modo de GL_COLOR_MATERIAL // glColorMaterial(GL_FRONT, GL_DIFFUSE); glEnable(GL_COLOR_MATERIAL); glMaterial(GL_FRONT, GL_SPECULAR, Conversion.allocFloats(spec)); glMaterialf(GL_FRONT, GL_SHININESS, df); }