Roi Atalla avatar Roi Atalla committed 0a5ba3b

Fixed some stuffs.

Comments (0)

Files changed (14)

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter1/Example1_1.java

-package com.ra4king.opengl.arcsynthesis.gl32.chapter1;
-
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example1_1 extends GLProgram {
-	public static void main(String[] args) {
-		new Example1_1().run(3,2);
-	}
-	
-	private int program, vbo;
-	
-	public Example1_1() {
-		super("Example 1.1", 500, 500, false);
-	}
-	
-	@Override
-	public void init() {
-		glClearColor(0, 0, 0, 0);
-		
-		int vs = glCreateShader(GL_VERTEX_SHADER);
-		glShaderSource(vs, readFromFile("example1.1.vert"));
-		
-		glCompileShader(vs);
-		
-		if(glGetShader(vs, GL_COMPILE_STATUS) == GL_FALSE) {
-			System.err.println("Failure in compiling vertex shader. Error log:\n" + glGetShaderInfoLog(vs, glGetShader(vs, GL_INFO_LOG_LENGTH)));
-			System.exit(0);
-		}
-		
-		int fs = glCreateShader(GL_FRAGMENT_SHADER);
-		glShaderSource(fs, readFromFile("example1.1.frag"));
-		
-		glCompileShader(fs);
-		
-		if(glGetShader(fs, GL_COMPILE_STATUS) == GL_FALSE) {
-			System.err.println("Failure in compiling fragment shader. Error log:\n" + glGetShaderInfoLog(fs, glGetShader(fs, GL_INFO_LOG_LENGTH)));
-			destroy();
-		}
-		
-		program = glCreateProgram();
-		glAttachShader(program, vs);
-		glAttachShader(program, fs);
-		
-		glBindAttribLocation(program, 0, "position");
-		
-		glLinkProgram(program);
-		
-		if(glGetProgram(program, GL_LINK_STATUS) == GL_FALSE) {
-			System.err.println("Failure in linking program. Error log:\n" + glGetProgramInfoLog(program, glGetProgram(program, GL_INFO_LOG_LENGTH)));
-			destroy();
-		}
-		
-		glDetachShader(program, vs);
-		glDetachShader(program, fs);
-		
-		glDeleteShader(vs);
-		glDeleteShader(fs);
-		
-		vbo = glGenBuffers();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(24).put(new float[] { 0.75f,  0.75f, 0.0f, 1.0f,
-																									   0.75f, -0.75f, 0.0f, 1.0f,
-																									  -0.75f, -0.75f, 0.0f, 1.0f}).flip(),GL_STATIC_DRAW);
-		
-		glBindVertexArray(glGenVertexArrays());
-		
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-	}
-	
-	@Override
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glUseProgram(program);
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glEnableVertexAttribArray(0);
-		glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
-		
-		glDrawArrays(GL_TRIANGLES, 0, 3);
-		
-		glDisableVertexAttribArray(0);
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-		
-		glUseProgram(0);
-	}
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter1/example1.1.frag

-#version 150
-
-out vec4 outputColor;
-
-void main()
-{
-	outputColor = vec4(1,1,1,1);
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter1/example1.1.vert

-#version 150
-
-in vec4 position;
-
-void main()
-{
-	gl_Position = position;
-}

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

-package com.ra4king.opengl.arcsynthesis.gl32.chapter2.example1;
-
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
-import java.nio.FloatBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.lwjgl.BufferUtils;
-
-import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.util.ShaderProgram;
-
-public class Example2_1 extends GLProgram {
-	public static void main(String[] args) {
-		new Example2_1().run(3,2);
-	}
-	
-	private ShaderProgram program;
-	private int vbo;
-	
-	public Example2_1() {
-		super("Example 2.1", 500, 500, false);
-	}
-	
-	@Override
-	public void init() {
-		glClearColor(0, 0, 0, 0);
-		
-		Map<Integer,String> attributes = new HashMap<Integer,String>();
-		attributes.put(0, "position");
-		program = new ShaderProgram(readFromFile("example2.1.vert"),readFromFile("example2.1.frag"),attributes);
-		
-		vbo = glGenBuffers();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.75f,  0.75f, 0.0f, 1.0f,
-																									   0.75f, -0.75f, 0.0f, 1.0f,
-																									  -0.75f, -0.75f, 0.0f, 1.0f}).flip(),GL_STATIC_DRAW);
-		
-		glBindVertexArray(glGenVertexArrays());
-		
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-	}
-	
-	@Override
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		program.begin();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glEnableVertexAttribArray(0);
-		glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
-		
-		glDrawArrays(GL_TRIANGLES, 0, 3);
-		
-		glDisableVertexAttribArray(0);
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-		
-		program.end();
-	}
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter2/example1/example2.1.frag

-#version 150
-
-out vec4 outputColor;
-
-void main()
-{
-    float lerpValue = gl_FragCoord.y / 600.0f;
-        
-    outputColor = mix(vec4(1.0f, 1.0f, 1.0f, 1.0f), vec4(0.2f, 0.2f, 0.2f, 1.0f), lerpValue);
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter2/example1/example2.1.vert

-#version 150
-
-in vec4 position;
-
-void main()
-{
-	gl_Position = position;
-}

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

-package com.ra4king.opengl.arcsynthesis.gl32.chapter2.example2;
-
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
-import java.nio.FloatBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.lwjgl.BufferUtils;
-
-import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.util.ShaderProgram;
-
-public class Example2_2 extends GLProgram {
-	public static void main(String[] args) {
-		new Example2_2().run(3,2);
-	}
-	
-	private ShaderProgram program;
-	private int vbo;
-	
-	public Example2_2() {
-		super("Example 2.2", 500, 500, false);
-	}
-	
-	@Override
-	public void init() {
-		glClearColor(0, 0, 0, 0);
-		
-		Map<Integer,String> attributes = new HashMap<Integer,String>();
-		attributes.put(0, "position");
-		attributes.put(1, "color");
-		program = new ShaderProgram(readFromFile("example2.2.vert"),readFromFile("example2.2.frag"),attributes);
-		
-		vbo = glGenBuffers();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glBufferData(GL_ARRAY_BUFFER, (FloatBuffer)BufferUtils.createFloatBuffer(24).put(new float[] { 0.0f,    0.5f, 0.0f, 1.0f,
-																									   0.5f, -0.366f, 0.0f, 1.0f,
-																									  -0.5f, -0.366f, 0.0f, 1.0f,
-																									   1.0f,    0.0f, 0.0f, 1.0f,
-																									   0.0f,    1.0f, 0.0f, 1.0f,
-																									   0.0f,    0.0f, 1.0f, 1.0f}).flip(),GL_STATIC_DRAW);
-		
-		glBindVertexArray(glGenVertexArrays());
-		
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-	}
-	
-	@Override
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		program.begin();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glEnableVertexAttribArray(0);
-		glEnableVertexAttribArray(1);
-		glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
-		glVertexAttribPointer(1, 4, GL_FLOAT, false, 0, 48);
-		
-		glDrawArrays(GL_TRIANGLES, 0, 3);
-		
-		glDisableVertexAttribArray(0);
-		glDisableVertexAttribArray(1);
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-		
-		program.end();
-	}
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter2/example2/example2.2.frag

-#version 150
-
-smooth in vec4 theColor;
-
-out vec4 outputColor;
-
-void main()
-{
-	outputColor = theColor;
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter2/example2/example2.2.vert

-#version 150
-
-in vec4 position;
-in vec4 color;
-
-smooth out vec4 theColor;
-
-void main()
-{
-	gl_Position = position;
-	theColor = color;
-}

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

-package com.ra4king.opengl.arcsynthesis.gl32.chapter3.example1;
-
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
-import java.nio.FloatBuffer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.lwjgl.BufferUtils;
-
-import com.ra4king.opengl.GLProgram;
-import com.ra4king.opengl.util.ShaderProgram;
-
-public class Example3_1 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_1().run(3,2);
-	}
-	
-	private ShaderProgram program;
-	
-	private FloatBuffer vertexData, newData;
-	private int vbo;
-	
-	private long elapsedTime;
-	
-	public Example3_1() {
-		super("Example 3.1", 500, 500, false);
-	}
-	
-	@Override
-	public void init() {
-		glClearColor(0, 0, 0, 0);
-		
-		Map<Integer,String> attributes = new HashMap<Integer,String>();
-		attributes.put(0, "position");
-		program = new ShaderProgram(readFromFile("example3.1.vert"),readFromFile("example3.1.frag"),attributes);
-		
-		vbo = glGenBuffers();
-		
-		vertexData = (FloatBuffer)BufferUtils.createFloatBuffer(12).put(new float[] { 0.25f,  0.25f, 0.0f, 1.0f,
-																					  0.25f, -0.25f, 0.0f, 1.0f,
-																					 -0.25f, -0.25f, 0.0f, 1.0f}).flip();
-		newData = BufferUtils.createFloatBuffer(12);
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glBufferData(GL_ARRAY_BUFFER, vertexData, GL_STREAM_DRAW);
-		
-		glBindVertexArray(glGenVertexArrays());
-		
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-	}
-	
-	@Override
-	public void update(long deltaTime) {
-		elapsedTime += deltaTime;
-		
-		float loopDuration = 5;
-		float scale = (float)Math.PI * 2 / loopDuration;
-		float currentTimeThroughLoop = (elapsedTime/(float)1e9) % loopDuration;
-		
-		float xOffset = (float)Math.cos(currentTimeThroughLoop * scale) * 0.5f;
-		float yOffset = (float)Math.sin(currentTimeThroughLoop * scale) * 0.5f;
-		
-		newData.clear();
-		
-		for(int a = 0; a < 12; a += 4) {
-			newData.put(vertexData.get(a) + xOffset);
-			newData.put(vertexData.get(a+1) + yOffset);
-			newData.put(0);
-			newData.put(1);
-		}
-		
-		newData.flip();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glBufferSubData(GL_ARRAY_BUFFER, 0, newData);
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-	}
-	
-	@Override
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		program.begin();
-		
-		glBindBuffer(GL_ARRAY_BUFFER, vbo);
-		glEnableVertexAttribArray(0);
-		glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, 0);
-		
-		glDrawArrays(GL_TRIANGLES, 0, 3);
-		
-		glDisableVertexAttribArray(0);
-		glBindBuffer(GL_ARRAY_BUFFER, 0);
-		
-		program.end();
-	}
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter3/example1/example3.1.frag

-#version 150
-
-out vec4 outputColor;
-
-void main()
-{
-	outputColor = vec4(1, 1, 1, 1);
-}

src/main/java/com/ra4king/opengl/arcsynthesis/gl32/chapter3/example1/example3.1.vert

-#version 150
-
-in vec4 position;
-
-void main()
-{
-	gl_Position = position;
-}

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

 package com.ra4king.opengl.arcsynthesis.gl32.chapter4.example1;
 
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.GL20.*;
+import static org.lwjgl.opengl.GL30.*;
+
 import java.nio.FloatBuffer;
 import java.util.HashMap;
 import java.util.Map;
 import com.ra4king.opengl.GLProgram;
 import com.ra4king.opengl.util.ShaderProgram;
 
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
 public class Example4_1 extends GLProgram {
 	public static void main(String[] args) {
 		new Example4_1().run(3,2);

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

 package com.ra4king.opengl.arcsynthesis.gl33.chapter4.example1;
 
+import static org.lwjgl.opengl.GL11.*;
+import static org.lwjgl.opengl.GL15.*;
+import static org.lwjgl.opengl.GL20.*;
+import static org.lwjgl.opengl.GL30.*;
+
 import java.nio.FloatBuffer;
 
 import org.lwjgl.BufferUtils;
 import com.ra4king.opengl.GLProgram;
 import com.ra4king.opengl.util.ShaderProgram;
 
-import static org.lwjgl.opengl.GL11.*;
-import static org.lwjgl.opengl.GL15.*;
-import static org.lwjgl.opengl.GL20.*;
-import static org.lwjgl.opengl.GL30.*;
-
 public class Example4_1 extends GLProgram {
 	public static void main(String[] args) {
 		new Example4_1().run(true);
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.