Roi Atalla avatar Roi Atalla committed 6b5909e

Ayup.

Comments (0)

Files changed (6)

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;
+}
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.