Roi Atalla avatar Roi Atalla committed 2ab89a8

Now you can pause/unpause the rotation! :D

Comments (0)

Files changed (2)

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

 				if(Display.wasResized())
 					resized();
 				
+				while(Keyboard.next()) {
+					if(Keyboard.getEventKeyState())
+						keyPressed(Keyboard.getEventKey(),Keyboard.getEventCharacter(),Keyboard.getEventNanoseconds());
+					else
+						keyReleased(Keyboard.getEventKey(),Keyboard.getEventCharacter(),Keyboard.getEventNanoseconds());
+				}
+				
 				update(deltaTime);
 				render();
 				
 		return Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
 	}
 	
+	public void keyPressed(int key, char c, long nanos) {}
+	
+	public void keyReleased(int key, char c, long nanos) {}
+	
 	public void update(long deltaTime) {}
 	
 	public abstract void render();

src/main/java/com/ra4king/opengl/test/Test.java

 import java.nio.ShortBuffer;
 
 import org.lwjgl.BufferUtils;
+import org.lwjgl.input.Keyboard;
 
 import com.ra4king.opengl.GLProgram;
 import com.ra4king.opengl.util.ShaderProgram;
 		glClearColor(0,0,0,0);
 		glClearDepth(1);
 		
-		glEnable(GL_LINE_SMOOTH);
-		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST);
-		
 		program = new ShaderProgram(readFromFile("test.vert"),readFromFile("test.frag"));
 		
 		perspectiveMatrixUniform = glGetUniformLocation(program.getProgram(), "perspectiveMatrix");
 		program.end();
 		
 		float[] vertices = {
-			 5,  5,  5,
-			 5, -5,  5,
-			-5, -5,  5,
-			-5,  5,  5,
-			
-			 5,  5, -5,
-			 5, -5, -5,
-			-5, -5, -5,
-			-5,  5, -5,
-			
-			0, 0, 0,
-			0, 1, 0,
-			1, 1, 0,
-			1, 0, 0,
-			
-			0, 0, 1,
-			0, 1, 1,
-			1, 1, 1,
-			1, 0, 1,
+				 5,  5,  5,
+				 5, -5,  5,
+				-5, -5,  5,
+				-5,  5,  5,
+				
+				 5,  5, -5,
+				 5, -5, -5,
+				-5, -5, -5,
+				-5,  5, -5,
+				
+				0, 0, 0,
+				0, 1, 0,
+				1, 1, 0,
+				1, 0, 0,
+				
+				0, 0, 1,
+				0, 1, 1,
+				1, 1, 1,
+				1, 0, 1,
 		};
 		
 		short[] indicies = {
 				7, 4, 3,
 				
 				1, 5, 6,
-				2, 1, 6
+				2, 1, 6,
 		};
 		
 		int vbo1 = glGenBuffers();
 	}
 	
 	private long elapsedTime;
+	private boolean rotate = true;
 	
 	@Override
 	public void update(long deltaTime) {
-		elapsedTime += deltaTime;
-		
-		float loopDuration = 3;
-		float angle = ((elapsedTime/(float)1e9)%loopDuration) * (2*(float)Math.PI/loopDuration);
-		modelViewMatrix.clearToIdentity().translate(0, -7, -20).rotate(20*(float)Math.PI/180, 1, 0, 0).rotate(angle, 0, 1, 0);
+		if(rotate) {
+			elapsedTime += deltaTime;
+			
+			float loopDuration = 3;
+			float angle = ((elapsedTime/(float)1e9)%loopDuration) * (2*(float)Math.PI/loopDuration);
+			modelViewMatrix.clearToIdentity().translate(0, -7, -20).rotate(20*(float)Math.PI/180, 1, 0, 0).rotate(angle, 0, 1, 0);
+		}
+	}
+	
+	@Override
+	public void keyPressed(int key, char c, long nanos) {
+		if(key == Keyboard.KEY_P)
+			rotate = !rotate;
 	}
 	
 	@Override
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.