public void CompileShader() { glLinkProgram(program); if (glGetProgrami(program, GL_LINK_STATUS) == 0) { System.err.println(glGetShaderInfoLog(program, 1024)); System.exit(1); } glValidateProgram(program); if (glGetProgrami(program, GL_VALIDATE_STATUS) == 0) { System.err.println(glGetShaderInfoLog(program, 1024)); System.exit(1); } }
@Override protected void init() { initializeProgram(); try { cylinderMesh = new Mesh("UnitCylinder.xml"); planeMesh = new Mesh("LargePlane.xml"); } catch (Exception exception) { exception.printStackTrace(); System.exit(-1); } glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glFrontFace(GL_CW); glEnable(GL_DEPTH_TEST); glDepthMask(true); glDepthFunc(GL_LEQUAL); glDepthRange(0.0f, 1.0f); glEnable(GL_DEPTH_CLAMP); projectionUniformBuffer = glGenBuffers(); glBindBuffer(GL_UNIFORM_BUFFER, projectionUniformBuffer); glBufferData(GL_UNIFORM_BUFFER, ProjectionBlock.SIZE, GL_DYNAMIC_DRAW); // Bind the static buffers. glBindBufferRange( GL_UNIFORM_BUFFER, projectionBlockIndex, projectionUniformBuffer, 0, ProjectionBlock.SIZE); glBindBuffer(GL_UNIFORM_BUFFER, 0); }
public Shader() { program = glCreateProgram(); uniforms = new HashMap<String, Integer>(); if (program == 0) { System.err.println( "Shader creation failed: Could not find valid memory location in constructor."); System.exit(1); } }
protected void addProgram(String text, int type) { int shader = glCreateShader(type); if (shader == 0) { System.err.println( "Shader creation failed: Could not find valid memory location when adding shader."); System.exit(1); } glShaderSource(shader, text); glCompileShader(shader); if (glGetShaderi(shader, GL_COMPILE_STATUS) == 0) { System.err.println(glGetShaderInfoLog(shader, 1024)); System.exit(1); } glAttachShader(program, shader); }
@Override protected void init() { initializePrograms(); try { realHallway = new Mesh("RealHallway.xml"); fauxHallway = new Mesh("FauxHallway.xml"); } catch (Exception exception) { exception.printStackTrace(); System.exit(-1); } }
private static void setUpDisplay() { try { Display.setDisplayMode(new DisplayMode(640, 480)); Display.setVSyncEnabled(true); Display.setTitle("Core Lighting Demo"); Display.create(); } catch (LWJGLException e) { System.err.println("The display wasn't initialized correctly. :("); Display.destroy(); System.exit(1); } }
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); } }
void renderLoop() { long startTime = System.currentTimeMillis() + 5000; long fps = 0; while (glfwWindowShouldClose(window.handle) == GLFW_FALSE) { Runnable event; while ((event = events.poll()) != null) event.run(); try { display(); } catch (Exception e) { e.printStackTrace(); break; } glfwSwapBuffers(window.handle); if (startTime > System.currentTimeMillis()) { fps++; } else { long timeUsed = 5000 + (startTime - System.currentTimeMillis()); startTime = System.currentTimeMillis() + 5000; log( String.format( "%s: %d frames in 5 seconds = %.2f", getPlatformInfoStringUTF8(platform, CL_PLATFORM_VENDOR), fps, fps / (timeUsed / 1000f))); fps = 0; } } cleanup(); window.signal.countDown(); }
public static void main(String[] args) { setUpDisplay(); setUpVBOs(); setUpCamera(); setUpShaders(); setUpLighting(); while (!Display.isCloseRequested()) { render(); checkInput(); Display.update(); Display.sync(60); } cleanUp(); System.exit(0); }
public static String LoadShader(String filename) { StringBuilder shaderSource = new StringBuilder(); BufferedReader shaderReader = null; try { shaderReader = new BufferedReader(new FileReader("./resource/shaders/" + filename)); String line; while ((line = shaderReader.readLine()) != null) { shaderSource.append(line).append("\n"); } shaderReader.close(); } catch (Exception exception) { exception.printStackTrace(); System.exit(1); } return shaderSource.toString(); }