Roi Atalla avatar Roi Atalla committed ece800c

Moved ShaderProgram to 'util' and created a new method in GLProgram called "shouldStop" which returns true if the game loop should stop.

Comments (0)

Files changed (21)

src/main/java/com/ra4king/opengl/GLProgram.java

 		lastTime = lastFPS = System.nanoTime();
 		int frames = 0;
 		
-		while(!Display.isCloseRequested() && !Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
+		while(!Display.isCloseRequested() && !shouldStop()) {
 			long deltaTime = System.nanoTime() - lastTime;
 			lastTime += deltaTime;
 			
 		glViewport(0,0,getWidth(),getHeight());
 	}
 	
+	public boolean shouldStop() {
+		return Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
+	}
+	
 	public void update(long deltaTime) {}
 	
 	public abstract void render();

src/main/java/com/ra4king/opengl/ShaderProgram.java

-package com.ra4king.opengl;
-
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL20.*;
-
-public class ShaderProgram {
-	private int program;
-	
-	public ShaderProgram(String vertexShader, String fragmentShader) {
-		int vs = glCreateShader(GL_VERTEX_SHADER);
-		glShaderSource(vs, vertexShader);
-		
-		glCompileShader(vs);
-		
-		if(glGetShader(vs, GL_COMPILE_STATUS) == GL_FALSE)
-			throw new RuntimeException("Failure in compiling vertex shader. Error log:\n" + glGetShaderInfoLog(vs, glGetShader(vs, GL_INFO_LOG_LENGTH)));
-		
-		int fs = glCreateShader(GL_FRAGMENT_SHADER);
-		glShaderSource(fs, fragmentShader);
-		
-		glCompileShader(fs);
-		
-		if(glGetShader(fs, GL_COMPILE_STATUS) == GL_FALSE)
-			throw new RuntimeException("Failure in compiling fragment shader. Error log:\n" + glGetShaderInfoLog(fs, glGetShader(fs, GL_INFO_LOG_LENGTH)));
-		
-		program = glCreateProgram();
-		glAttachShader(program, vs);
-		glAttachShader(program, fs);
-		
-		glLinkProgram(program);
-		
-		if(glGetProgram(program, GL_LINK_STATUS) == GL_FALSE)
-			throw new RuntimeException("Failure in linking program. Error log:\n" + glGetProgramInfoLog(program, glGetProgram(program, GL_INFO_LOG_LENGTH)));
-		
-		glDetachShader(program, vs);
-		glDetachShader(program, fs);
-		
-		glDeleteShader(vs);
-		glDeleteShader(fs);
-	}
-	
-	public int getProgram() {
-		return program;
-	}
-	
-	public void begin() {
-		glUseProgram(program);
-	}
-	
-	public void end() {
-		glUseProgram(0);
-	}
-	
-	public void destroy() {
-		glDeleteProgram(program);
-	}
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter2/example1/Example2_1.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example2_1 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter2/example2/Example2_2.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example2_2 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter3/example1/Example3_1.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example3_1 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter3/example2/Example3_2.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example3_2 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter3/example3/Example3_3.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example3_3 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter3/example4/Example3_4.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example3_4 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter4/example1/Example4_1.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 import static org.lwjgl.opengl.GL11.*;
 import static org.lwjgl.opengl.GL15.*;

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter4/example2/Example4_2.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example4_2 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter4/example3/Example4_3.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example4_3 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter4/example4/Example4_4.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example4_4 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter5/example1/Example5_1.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example5_1 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter5/example2/Example5_2.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example5_2 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter5/example3/Example5_3.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example5_3 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter5/example4/Example5_4.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example5_4 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter5/example5/Example5_5.java

 import org.lwjgl.input.Keyboard;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 
 public class Example5_5 extends GLProgram {
 	public static void main(String[] args) {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter6/example1/Example6_1.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Matrix4;
 
 public class Example6_1 extends GLProgram {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter6/example2/Example6_2.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Matrix4;
 
 public class Example6_2 extends GLProgram {

src/main/java/com/ra4king/opengl/arcsynthesis/gl33/chapter6/example3/Example6_3.java

 import org.lwjgl.BufferUtils;
 
 import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.ShaderProgram;
+import com.ra4king.opengl.util.ShaderProgram;
 import com.ra4king.opengl.util.math.Matrix4;
 import com.ra4king.opengl.util.math.Vector3;
 

src/main/java/com/ra4king/opengl/util/ShaderProgram.java

+package com.ra4king.opengl.util;
+
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL20.*;
+
+public class ShaderProgram {
+	private int program;
+	
+	public ShaderProgram(String vertexShader, String fragmentShader) {
+		int vs = glCreateShader(GL_VERTEX_SHADER);
+		glShaderSource(vs, vertexShader);
+		
+		glCompileShader(vs);
+		
+		if(glGetShader(vs, GL_COMPILE_STATUS) == GL_FALSE)
+			throw new RuntimeException("Failure in compiling vertex shader. Error log:\n" + glGetShaderInfoLog(vs, glGetShader(vs, GL_INFO_LOG_LENGTH)));
+		
+		int fs = glCreateShader(GL_FRAGMENT_SHADER);
+		glShaderSource(fs, fragmentShader);
+		
+		glCompileShader(fs);
+		
+		if(glGetShader(fs, GL_COMPILE_STATUS) == GL_FALSE)
+			throw new RuntimeException("Failure in compiling fragment shader. Error log:\n" + glGetShaderInfoLog(fs, glGetShader(fs, GL_INFO_LOG_LENGTH)));
+		
+		program = glCreateProgram();
+		glAttachShader(program, vs);
+		glAttachShader(program, fs);
+		
+		glLinkProgram(program);
+		
+		if(glGetProgram(program, GL_LINK_STATUS) == GL_FALSE)
+			throw new RuntimeException("Failure in linking program. Error log:\n" + glGetProgramInfoLog(program, glGetProgram(program, GL_INFO_LOG_LENGTH)));
+		
+		glDetachShader(program, vs);
+		glDetachShader(program, fs);
+		
+		glDeleteShader(vs);
+		glDeleteShader(fs);
+	}
+	
+	public int getProgram() {
+		return program;
+	}
+	
+	public void begin() {
+		glUseProgram(program);
+	}
+	
+	public void end() {
+		glUseProgram(0);
+	}
+	
+	public void destroy() {
+		glDeleteProgram(program);
+	}
+}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.