Roi Atalla avatar Roi Atalla committed f16941c Merge

Comments (0)

Files changed (47)

 target/
 .idea/
 *.iml
+hs_err_*.log
+# README #
+
+## Quick Start ##
+
+### What you need ###
+
+* Java Development Kit for Java 7 ([get it here](http://www.oracle.com/technetwork/java/javase/downloads/index.html))
+
+* Apache Maven available in your PATH ([get it here](http://maven.apache.org/download.html))
+
+* An IDE like [Eclipse](http://eclipse.org), [IntelliJ](http://jetbrains.com/idea), or [NetBeans](http://netbeans.org)
+
+* Support for Maven in your IDE (Eclipse Juno and IntelliJ both come with maven support)
+
+* _Windows users:_ a version of the bash shell (either [Cygwin](http://cygwin.com)
+  or [Git Bash](https://openhatch.org/missions/windows-setup/install-git-bash) are fine)
+
+### How to run samples ###
+
+1. Ensure you have Java SDK 7 and maven installed and both are in your PATH
+2. Clone this repository: `hg clone https://bitbucket.org/ra4king/lwjgl-shader-tutorials`
+3. Open a bash window and cd to where you cloned this repository
+4. Start the launcher: `./launch`
+
+## Sections ##
+
+Every section is found in the source under `src/main/java/com/ra4king/opengl`.
+Under each section you can find another README file that gives more detail, and finally some of the samples themselves may have their own README.
+
+
+* **arcsynthesis:** Java ports of the excellent C tutorials from "Learning Modern 3d Graphics Programming"
+at [arcsynthesis.org](http://arcsynthesis.org/gltut)
+
+
+* **redbook:** A collection of examples from the [OpenGL Programming Guide](http://www.glprogramming.com/red/) first edition
+ (warning: uses _very_ obsolete OpenGL)
+
+
+* **superbible:** A collection of examples from the [OpenGL SuperBible](http://www.starstonesoftware.com/OpenGL/) fourth edition
+(Also old-fashioned in parts, but fifth edition examples are coming soon!)
+
+
+* **test:** Miscellaneous test programs.
     do
         printf "%3d) %s\n" $((++i)) $t
     done
+    if [[ $expr = . ]]; then
+        echo ""
+        echo "Hint: you can narrow down this list by passing part of the name"
+        echo "      as an argument next time you launch."
+        echo ""
+        echo "Example:  $0 arcsyn"
+        echo ""
+    fi
     echo -ne "\nSelect one: "
     )" selection
     selected="${targets[$((selection-1))]}"

src/main/java/com/ra4king/opengl/arcsynthesis/README.md

+# README #
+
+XXX TODO

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

 		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,
+		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);
 		

src/main/java/com/ra4king/opengl/redbook/README.md

+# README #
+
+XXX TODO

src/main/java/com/ra4king/opengl/superbible/README.md

+# README #
+
+XXX TODO

src/main/java/com/ra4king/opengl/superbible/chapter2/Example2_1.java

-package com.ra4king.opengl.superbible.chapter2;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example2_1 extends GLProgram {
-	public static void main(String[] args) {
-		new Example2_1().run();
-	}
-	
-	public Example2_1() {
-		super("SIMPLE",800,600,false);
-	}
-	
-	public void init() {
-		glClearColor(0,0,1,1);
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter2/Example2_2.java

-package com.ra4king.opengl.superbible.chapter2;
-
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example2_2 extends GLProgram {
-	public static void main(String[] args) {
-		new Example2_2().run();
-	}
-	
-	public Example2_2() {
-		super("GLRect",800,600,true);
-	}
-	
-	public void init() {
-		glClearColor(0,0,1,1);
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,1,-1);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,1,-1);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glColor3f(1,0,0);
-		glRectf(-25,25,25,-25);
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter2/Example2_3.java

-package com.ra4king.opengl.superbible.chapter2;
-
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example2_3 extends GLProgram {
-	public static void main(String[] args) {
-		new Example2_3().run();
-	}
-	
-	private float x, y, size = 25;
-	private float xstep = 1, ystep = 1;
-	
-	private float width = 100, height = 100;
-	
-	public Example2_3() {
-		super("BOUNCE",500,500,true);
-	}
-	
-	public void init() {
-		glClearColor(0,0,1,1);
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h) {
-			width = 100;
-			height = 100/aspect;
-		}
-		else {
-			width = 100*aspect;
-			height = 100;
-		}
-		
-		glOrtho(-width,width,-height,height,1,-1);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-	
-	public void update(long deltaTime) {
-		if(x > width-size || x < -width)
-			xstep = -xstep;
-		
-		if(y > height || y < -height+size)
-			ystep = -ystep;
-		
-		x += xstep;
-		y += ystep;
-		
-		if(x > width - size + xstep)
-			x = width-size-1;
-		else if(x < -width-xstep)
-			x = -width-1;
-		
-		if(y > height + ystep)
-			y = height-1;
-		else if(y < -height + size - ystep)
-			y = -height + size - 1;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glColor3f(1,0,0);
-		glRectf(x,y,x+size,y-size);
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_10.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import java.nio.ByteBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_10 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_10().run();
-	}
-	
-	public Example3_10() {
-		super("PSTIPPLE",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(1,0,0);
-		
-		glEnable(GL_POLYGON_STIPPLE);
-		
-		glPolygonStipple((ByteBuffer)BufferUtils.createByteBuffer(16*8).put(new byte[] {
-			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
-			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0xf0,
-			(byte)0x00, (byte)0x00, (byte)0x07, (byte)0xf0, (byte)0x0f, (byte)0x00, (byte)0x1f, (byte)0xe0,
-			(byte)0x1f, (byte)0x80, (byte)0x1f, (byte)0xc0, (byte)0x0f, (byte)0xc0, (byte)0x3f, (byte)0x80,
-			(byte)0x07, (byte)0xe0, (byte)0x7e, (byte)0x00, (byte)0x03, (byte)0xf0, (byte)0xff, (byte)0x80,
-			(byte)0x03, (byte)0xf5, (byte)0xff, (byte)0xe0, (byte)0x07, (byte)0xfd, (byte)0xff, (byte)0xf8,
-			(byte)0x1f, (byte)0xfc, (byte)0xff, (byte)0xe8, (byte)0xff, (byte)0xe3, (byte)0xbf, (byte)0x70,
-			(byte)0xde, (byte)0x80, (byte)0xb7, (byte)0x00, (byte)0x71, (byte)0x10, (byte)0x4a, (byte)0x80,
-			(byte)0x03, (byte)0x10, (byte)0x4e, (byte)0x40, (byte)0x02, (byte)0x88, (byte)0x8c, (byte)0x20,
-			(byte)0x05, (byte)0x05, (byte)0x04, (byte)0x40, (byte)0x02, (byte)0x82, (byte)0x14, (byte)0x40,
-			(byte)0x02, (byte)0x40, (byte)0x10, (byte)0x80, (byte)0x02, (byte)0x64, (byte)0x1a, (byte)0x80,
-			(byte)0x00, (byte)0x92, (byte)0x29, (byte)0x00, (byte)0x00, (byte)0xb0, (byte)0x48, (byte)0x00,
-			(byte)0x00, (byte)0xc8, (byte)0x90, (byte)0x00, (byte)0x00, (byte)0x85, (byte)0x10, (byte)0x00,
-			(byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00
-		}).flip());
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glBegin(GL_POLYGON);
-			glVertex2f(-20, 50);
-			glVertex2f( 20, 50);
-			glVertex2f( 50, 20);
-			glVertex2f( 50,-20);
-			glVertex2f( 20,-50);
-			glVertex2f(-20,-50);
-			glVertex2f(-50,-20);
-			glVertex2f(-50, 20);
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_11.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_11 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_11().run();
-	}
-	
-	public Example3_11() {
-		super("STAR",800,600,true);
-	}
-	
-	private boolean edgeFlag = false;
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(1,1,1);
-		
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glBegin(GL_TRIANGLES);
-			glEdgeFlag(edgeFlag);
-			glVertex2f(-20,0);
-			glEdgeFlag(true);
-			glVertex2f(20,0);
-			glVertex2f(0,40);
-			
-			glVertex2f(-20,0);
-			glVertex2f(-60,-20);
-			glEdgeFlag(edgeFlag);
-			glVertex2f(-20,-40);
-			
-			glEdgeFlag(true);
-			glVertex2f(-20,-40);
-			glVertex2f(0,-80);
-			glEdgeFlag(edgeFlag);
-			glVertex2f(20,-40);
-			
-			glEdgeFlag(true);
-			glVertex2f(20,-40);
-			glVertex2f(60,-20);
-			glEdgeFlag(edgeFlag);
-			glVertex2f(20,0);
-			
-			glVertex2f(-20,0);
-			glVertex2f(-20,-40);
-			glVertex2f(20,0);
-			
-			glVertex2f(-20,-40);
-			glVertex2f(20,-40);
-			glVertex2f(20,0);
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_13.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_13 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_13().run();
-	}
-	
-	public Example3_13() {
-		super("SCISSOR",800,600,true);
-	}
-	
-	public void init() {
-		glEnable(GL_SCISSOR_TEST);
-	}
-	
-	public void render() {
-		glScissor(0,0,800,600);
-		glClearColor(0,0,1,1);
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glScissor(100,100,600,400);
-		glClearColor(1,0,0,1);
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glScissor(200,200,400,200);
-		glClearColor(0,1,0,1);
-		glClear(GL_COLOR_BUFFER_BIT);
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_14.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_14 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_14().run();
-	}
-	
-	private float x, y, size = 50;
-	private float xstep = 1, ystep = 1;
-	
-	private float width = 100, height = 100;
-	
-	public Example3_14() {
-		super("STENCIL",800,600,true);
-	}
-	
-	public void init() {
-		glClearColor(0,0,1,1);
-		glClearStencil(0);
-		
-		glEnable(GL_STENCIL_TEST);
-	}
-	
-	public void update(long deltaTime) {
-		if(x > width-size || x < -width)
-			xstep = -xstep;
-		
-		if(y > height || y < -height+size)
-			ystep = -ystep;
-		
-		x += xstep;
-		y += ystep;
-		
-		if(x > width - size + xstep)
-			x = width-size-1;
-		else if(x < -width-xstep)
-			x = -width-1;
-		
-		if(y > height + ystep)
-			y = height-1;
-		else if(y < -height + size - ystep)
-			y = -height + size - 1;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
-		
-		glStencilFunc(GL_NEVER, 0, 0);
-		glStencilOp(GL_INCR,GL_INCR,GL_INCR);
-		
-		glColor3f(1,1,1);
-		glBegin(GL_LINE_STRIP);
-		for(double angle = 0, radius = 0.1; angle < 400; angle += 0.1, radius *= 1.002)
-			glVertex2d(radius * Math.cos(angle), radius * Math.sin(angle));
-		glEnd();
-		
-		glStencilFunc(GL_NOTEQUAL,1,1);
-		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-		
-		glColor3f(1,0,0);
-		glRectf(x,y,x+size,y-size);
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h) {
-			width = 100;
-			height = 100/aspect;
-		}
-		else {
-			width = 100*aspect;
-			height = 100;
-		}
-		
-		glOrtho(-width,width,-height,height,1,-1);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_2.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example3_2 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_2().run();
-	}
-	
-	public Example3_2() {
-		super("POINTS",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glPointSize(5);
-		
-		glBegin(GL_POINTS);
-		
-		for(float angle = 0, z = -50; angle <= 2*Math.PI*3; angle += 0.1f, z += 0.5f) {
-			glVertex3f(50 * (float)Math.cos(angle), 50 * (float)Math.sin(angle), z);
-		}
-		
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_3.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_3 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_3().run();
-	}
-	
-	public Example3_3() {
-		super("POINTSZ",800,600,true);
-	}
-	
-	FloatBuffer sizes = BufferUtils.createFloatBuffer(16);
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		float step = glGetFloat(GL_POINT_SIZE_GRANULARITY);
-		glGetFloat(GL_POINT_SIZE_RANGE,(FloatBuffer)sizes.clear());
-		
-		for(float angle = 0, z = -50, curSize = sizes.get(0); angle <= 2*Math.PI*3; angle += 0.1f, z += 0.5f, curSize = Math.min(curSize + step, sizes.get(1))) {
-			glPointSize(curSize);
-			glBegin(GL_POINTS);
-			glVertex3f(50 * (float)Math.cos(angle), 50 * (float)Math.sin(angle), z);
-			glEnd();
-		}
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_4.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example3_4 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_4().run();
-	}
-	
-	public Example3_4() {
-		super("LINES",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glPointSize(5);
-		
-		glBegin(GL_LINES);
-		
-		for(float angle = 0; angle <= Math.PI; angle += Math.PI/20) {
-			glVertex3f(50 * (float)Math.cos(angle), 50 * (float)Math.sin(angle), 0);
-			glVertex3f(50 * (float)Math.cos(angle + Math.PI), 50 * (float)Math.sin(angle + Math.PI), 0);
-		}
-		
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_5.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-import static org.lwjgl.opengl.GL11.*;
-
-public class Example3_5 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_5().run();
-	}
-	
-	public Example3_5() {
-		super("LSTRIPS",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glPointSize(5);
-		
-		glBegin(GL_LINE_STRIP);
-		
-		for(float angle = 0, z = -50; angle <= 2*Math.PI*3; angle += 0.1f, z += 0.5f) {
-			glVertex3f(50 * (float)Math.cos(angle), 50 * (float)Math.sin(angle), z);
-		}
-		
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_6.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import java.nio.FloatBuffer;
-
-import org.lwjgl.BufferUtils;
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_6 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_6().run();
-	}
-	
-	public Example3_6() {
-		super("LINESW",800,600,true);
-	}
-	
-	FloatBuffer sizes = BufferUtils.createFloatBuffer(16);
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glGetFloat(GL_LINE_WIDTH_RANGE,(FloatBuffer)sizes.clear());
-		
-		for(float y = -90, curSize = sizes.get(0); y <= 90; y += 20, curSize += 1) {
-			glLineWidth(curSize);
-			
-			glBegin(GL_LINES);
-				glVertex2f(-80,y);
-				glVertex2f(80,y);
-			glEnd();
-		}
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_7.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_7 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_7().run();
-	}
-	
-	public Example3_7() {
-		super("LSTIPPLE",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glColor3f(0,1,0);
-		
-		glEnable(GL_LINE_STIPPLE);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		for(int y = -90, factor = 0; y <= 90; y += 20, factor++) {
-			glLineStipple(factor,(short)0x5555);
-			
-			glBegin(GL_LINES);
-				glVertex2f(-80,y);
-				glVertex2f(80,y);
-			glEnd();
-		}
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/chapter3/Example3_8.java

-package com.ra4king.opengl.superbible.chapter3;
-
-import static org.lwjgl.opengl.GL11.*;
-
-import org.lwjgl.input.Keyboard;
-import org.lwjgl.opengl.Display;
-
-import com.ra4king.opengl.GLProgram;
-
-public class Example3_8 extends GLProgram {
-	public static void main(String[] args) {
-		new Example3_8().run();
-	}
-	
-	public Example3_8() {
-		super("TRIANGLE",800,600,true);
-	}
-	
-	private float xRot, yRot;
-	
-	public void init() {
-		glClearColor(0,0,0,1);
-		
-		glFrontFace(GL_CW);
-		
-		glShadeModel(GL_FLAT);
-		
-		glEnable(GL_DEPTH_TEST);
-		//glEnable(GL_CULL_FACE);
-		
-		glPolygonMode(GL_BACK,GL_LINE);
-	}
-	
-	public void update(long deltaTime) {
-		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
-			xRot += 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
-			xRot -= 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
-			yRot -= 5;
-		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
-			yRot += 5;
-		
-		if(Keyboard.isKeyDown(Keyboard.KEY_R))
-			xRot = yRot = 0;
-	}
-	
-	public void render() {
-		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-		
-		glPushMatrix();
-		
-		glRotatef(yRot, 1, 0, 0);
-		glRotatef(xRot, 0, 1, 0);
-		
-		glBegin(GL_TRIANGLE_FAN);
-		
-		glVertex3f(0,0,75);
-		int pivot = 1;
-		for(float angle = 0; angle <= 2 * Math.PI + 1; angle += Math.PI/8) {
-			if(pivot++ % 2 == 0)
-				glColor3f(0,1,.5f);
-			else
-				glColor3f(1,0,.5f);
-			
-			glVertex3f(50*(float)Math.cos(angle),50*(float)Math.sin(angle),0);
-		}
-		
-		glEnd();
-		
-		glBegin(GL_TRIANGLE_FAN);
-		
-		glVertex2f(0,0);
-		pivot = 1;
-		for(float angle = 0; angle <= 2.1 * Math.PI; angle += Math.PI/8) {
-			if(pivot++ % 2 == 0)
-				glColor3f(0,1,0);
-			else
-				glColor3f(1,0,0);
-			
-			glVertex2f(50*(float)Math.cos(angle),50*(float)Math.sin(angle));
-		}
-		
-		glEnd();
-		
-		glPopMatrix();
-	}
-	
-	public void resized() {
-		int w = Display.getWidth(), h = Display.getHeight();
-		
-		if(h == 0)
-			h = 1;
-		
-		glViewport(0,0,Display.getWidth(),Display.getHeight());
-		
-		glMatrixMode(GL_PROJECTION);
-		glLoadIdentity();
-		
-		float aspect = (float)w/h;
-		if(w <= h)
-			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
-		else
-			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
-		
-		glMatrixMode(GL_MODELVIEW);
-		glLoadIdentity();
-	}
-}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter2/Example2_1.java

+package com.ra4king.opengl.superbible.osb4.chapter2;
+
+import com.ra4king.opengl.GLProgram;
+
+import static org.lwjgl.opengl.GL11.*;
+
+public class Example2_1 extends GLProgram {
+	public static void main(String[] args) {
+		new Example2_1().run();
+	}
+	
+	public Example2_1() {
+		super("SIMPLE",800,600,false);
+	}
+	
+	public void init() {
+		glClearColor(0,0,1,1);
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT);
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter2/Example2_2.java

+package com.ra4king.opengl.superbible.osb4.chapter2;
+
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+import static org.lwjgl.opengl.GL11.*;
+
+public class Example2_2 extends GLProgram {
+	public static void main(String[] args) {
+		new Example2_2().run();
+	}
+	
+	public Example2_2() {
+		super("GLRect",800,600,true);
+	}
+	
+	public void init() {
+		glClearColor(0,0,1,1);
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h)
+			glOrtho(-100,100,-100/aspect,100/aspect,1,-1);
+		else
+			glOrtho(-100*aspect,100*aspect,-100,100,1,-1);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glColor3f(1,0,0);
+		glRectf(-25,25,25,-25);
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter2/Example2_3.java

+package com.ra4king.opengl.superbible.osb4.chapter2;
+
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+import static org.lwjgl.opengl.GL11.*;
+
+public class Example2_3 extends GLProgram {
+	public static void main(String[] args) {
+		new Example2_3().run();
+	}
+	
+	private float x, y, size = 25;
+	private float xstep = 1, ystep = 1;
+	
+	private float width = 100, height = 100;
+	
+	public Example2_3() {
+		super("BOUNCE",500,500,true);
+	}
+	
+	public void init() {
+		glClearColor(0,0,1,1);
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h) {
+			width = 100;
+			height = 100/aspect;
+		}
+		else {
+			width = 100*aspect;
+			height = 100;
+		}
+		
+		glOrtho(-width,width,-height,height,1,-1);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+	
+	public void update(long deltaTime) {
+		if(x > width-size || x < -width)
+			xstep = -xstep;
+		
+		if(y > height || y < -height+size)
+			ystep = -ystep;
+		
+		x += xstep;
+		y += ystep;
+		
+		if(x > width - size + xstep)
+			x = width-size-1;
+		else if(x < -width-xstep)
+			x = -width-1;
+		
+		if(y > height + ystep)
+			y = height-1;
+		else if(y < -height + size - ystep)
+			y = -height + size - 1;
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glColor3f(1,0,0);
+		glRectf(x,y,x+size,y-size);
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter3/Example3_10.java

+package com.ra4king.opengl.superbible.osb4.chapter3;
+
+import static org.lwjgl.opengl.GL11.*;
+
+import java.nio.ByteBuffer;
+
+import org.lwjgl.BufferUtils;
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+public class Example3_10 extends GLProgram {
+	public static void main(String[] args) {
+		new Example3_10().run();
+	}
+	
+	public Example3_10() {
+		super("PSTIPPLE",800,600,true);
+	}
+	
+	private float xRot, yRot;
+	
+	public void init() {
+		glClearColor(0,0,0,1);
+		
+		glColor3f(1,0,0);
+		
+		glEnable(GL_POLYGON_STIPPLE);
+		
+		glPolygonStipple((ByteBuffer)BufferUtils.createByteBuffer(16*8).put(new byte[] {
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+			(byte)0x00, (byte)0x00, (byte)0x00, (byte)0xc0, (byte)0x00, (byte)0x00, (byte)0x01, (byte)0xf0,
+			(byte)0x00, (byte)0x00, (byte)0x07, (byte)0xf0, (byte)0x0f, (byte)0x00, (byte)0x1f, (byte)0xe0,
+			(byte)0x1f, (byte)0x80, (byte)0x1f, (byte)0xc0, (byte)0x0f, (byte)0xc0, (byte)0x3f, (byte)0x80,
+			(byte)0x07, (byte)0xe0, (byte)0x7e, (byte)0x00, (byte)0x03, (byte)0xf0, (byte)0xff, (byte)0x80,
+			(byte)0x03, (byte)0xf5, (byte)0xff, (byte)0xe0, (byte)0x07, (byte)0xfd, (byte)0xff, (byte)0xf8,
+			(byte)0x1f, (byte)0xfc, (byte)0xff, (byte)0xe8, (byte)0xff, (byte)0xe3, (byte)0xbf, (byte)0x70,
+			(byte)0xde, (byte)0x80, (byte)0xb7, (byte)0x00, (byte)0x71, (byte)0x10, (byte)0x4a, (byte)0x80,
+			(byte)0x03, (byte)0x10, (byte)0x4e, (byte)0x40, (byte)0x02, (byte)0x88, (byte)0x8c, (byte)0x20,
+			(byte)0x05, (byte)0x05, (byte)0x04, (byte)0x40, (byte)0x02, (byte)0x82, (byte)0x14, (byte)0x40,
+			(byte)0x02, (byte)0x40, (byte)0x10, (byte)0x80, (byte)0x02, (byte)0x64, (byte)0x1a, (byte)0x80,
+			(byte)0x00, (byte)0x92, (byte)0x29, (byte)0x00, (byte)0x00, (byte)0xb0, (byte)0x48, (byte)0x00,
+			(byte)0x00, (byte)0xc8, (byte)0x90, (byte)0x00, (byte)0x00, (byte)0x85, (byte)0x10, (byte)0x00,
+			(byte)0x00, (byte)0x03, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x10, (byte)0x00
+		}).flip());
+	}
+	
+	public void update(long deltaTime) {
+		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
+			xRot += 5;
+		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
+			xRot -= 5;
+		
+		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
+			yRot -= 5;
+		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
+			yRot += 5;
+		
+		if(Keyboard.isKeyDown(Keyboard.KEY_R))
+			xRot = yRot = 0;
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glPushMatrix();
+		
+		glRotatef(yRot, 1, 0, 0);
+		glRotatef(xRot, 0, 1, 0);
+		
+		glBegin(GL_POLYGON);
+			glVertex2f(-20, 50);
+			glVertex2f( 20, 50);
+			glVertex2f( 50, 20);
+			glVertex2f( 50,-20);
+			glVertex2f( 20,-50);
+			glVertex2f(-20,-50);
+			glVertex2f(-50,-20);
+			glVertex2f(-50, 20);
+		glEnd();
+		
+		glPopMatrix();
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h)
+			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
+		else
+			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter3/Example3_11.java

+package com.ra4king.opengl.superbible.osb4.chapter3;
+
+import static org.lwjgl.opengl.GL11.*;
+
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+public class Example3_11 extends GLProgram {
+	public static void main(String[] args) {
+		new Example3_11().run();
+	}
+	
+	public Example3_11() {
+		super("STAR",800,600,true);
+	}
+	
+	private boolean edgeFlag = false;
+	
+	private float xRot, yRot;
+	
+	public void init() {
+		glClearColor(0,0,0,1);
+		
+		glColor3f(1,1,1);
+		
+		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+	}
+	
+	public void update(long deltaTime) {
+		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
+			xRot += 5;
+		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
+			xRot -= 5;
+		
+		if(Keyboard.isKeyDown(Keyboard.KEY_DOWN))
+			yRot -= 5;
+		if(Keyboard.isKeyDown(Keyboard.KEY_UP))
+			yRot += 5;
+		
+		if(Keyboard.isKeyDown(Keyboard.KEY_R))
+			xRot = yRot = 0;
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glPushMatrix();
+		
+		glRotatef(yRot, 1, 0, 0);
+		glRotatef(xRot, 0, 1, 0);
+		
+		glBegin(GL_TRIANGLES);
+			glEdgeFlag(edgeFlag);
+			glVertex2f(-20,0);
+			glEdgeFlag(true);
+			glVertex2f(20,0);
+			glVertex2f(0,40);
+			
+			glVertex2f(-20,0);
+			glVertex2f(-60,-20);
+			glEdgeFlag(edgeFlag);
+			glVertex2f(-20,-40);
+			
+			glEdgeFlag(true);
+			glVertex2f(-20,-40);
+			glVertex2f(0,-80);
+			glEdgeFlag(edgeFlag);
+			glVertex2f(20,-40);
+			
+			glEdgeFlag(true);
+			glVertex2f(20,-40);
+			glVertex2f(60,-20);
+			glEdgeFlag(edgeFlag);
+			glVertex2f(20,0);
+			
+			glVertex2f(-20,0);
+			glVertex2f(-20,-40);
+			glVertex2f(20,0);
+			
+			glVertex2f(-20,-40);
+			glVertex2f(20,-40);
+			glVertex2f(20,0);
+		glEnd();
+		
+		glPopMatrix();
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h)
+			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
+		else
+			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter3/Example3_13.java

+package com.ra4king.opengl.superbible.osb4.chapter3;
+
+import static org.lwjgl.opengl.GL11.*;
+
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+public class Example3_13 extends GLProgram {
+	public static void main(String[] args) {
+		new Example3_13().run();
+	}
+	
+	public Example3_13() {
+		super("SCISSOR",800,600,true);
+	}
+	
+	public void init() {
+		glEnable(GL_SCISSOR_TEST);
+	}
+	
+	public void render() {
+		glScissor(0,0,800,600);
+		glClearColor(0,0,1,1);
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glScissor(100,100,600,400);
+		glClearColor(1,0,0,1);
+		glClear(GL_COLOR_BUFFER_BIT);
+		
+		glScissor(200,200,400,200);
+		glClearColor(0,1,0,1);
+		glClear(GL_COLOR_BUFFER_BIT);
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h)
+			glOrtho(-100,100,-100/aspect,100/aspect,100,-100);
+		else
+			glOrtho(-100*aspect,100*aspect,-100,100,100,-100);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter3/Example3_14.java

+package com.ra4king.opengl.superbible.osb4.chapter3;
+
+import static org.lwjgl.opengl.GL11.*;
+
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+public class Example3_14 extends GLProgram {
+	public static void main(String[] args) {
+		new Example3_14().run();
+	}
+	
+	private float x, y, size = 50;
+	private float xstep = 1, ystep = 1;
+	
+	private float width = 100, height = 100;
+	
+	public Example3_14() {
+		super("STENCIL",800,600,true);
+	}
+	
+	public void init() {
+		glClearColor(0,0,1,1);
+		glClearStencil(0);
+		
+		glEnable(GL_STENCIL_TEST);
+	}
+	
+	public void update(long deltaTime) {
+		if(x > width-size || x < -width)
+			xstep = -xstep;
+		
+		if(y > height || y < -height+size)
+			ystep = -ystep;
+		
+		x += xstep;
+		y += ystep;
+		
+		if(x > width - size + xstep)
+			x = width-size-1;
+		else if(x < -width-xstep)
+			x = -width-1;
+		
+		if(y > height + ystep)
+			y = height-1;
+		else if(y < -height + size - ystep)
+			y = -height + size - 1;
+	}
+	
+	public void render() {
+		glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+		
+		glStencilFunc(GL_NEVER, 0, 0);
+		glStencilOp(GL_INCR,GL_INCR,GL_INCR);
+		
+		glColor3f(1,1,1);
+		glBegin(GL_LINE_STRIP);
+		for(double angle = 0, radius = 0.1; angle < 400; angle += 0.1, radius *= 1.002)
+			glVertex2d(radius * Math.cos(angle), radius * Math.sin(angle));
+		glEnd();
+		
+		glStencilFunc(GL_NOTEQUAL,1,1);
+		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+		
+		glColor3f(1,0,0);
+		glRectf(x,y,x+size,y-size);
+	}
+	
+	public void resized() {
+		int w = Display.getWidth(), h = Display.getHeight();
+		
+		if(h == 0)
+			h = 1;
+		
+		glViewport(0,0,Display.getWidth(),Display.getHeight());
+		
+		glMatrixMode(GL_PROJECTION);
+		glLoadIdentity();
+		
+		float aspect = (float)w/h;
+		if(w <= h) {
+			width = 100;
+			height = 100/aspect;
+		}
+		else {
+			width = 100*aspect;
+			height = 100;
+		}
+		
+		glOrtho(-width,width,-height,height,1,-1);
+		
+		glMatrixMode(GL_MODELVIEW);
+		glLoadIdentity();
+	}
+}

src/main/java/com/ra4king/opengl/superbible/osb4/chapter3/Example3_2.java

+package com.ra4king.opengl.superbible.osb4.chapter3;
+
+import org.lwjgl.input.Keyboard;
+import org.lwjgl.opengl.Display;
+
+import com.ra4king.opengl.GLProgram;
+
+import static org.lwjgl.opengl.GL11.*;
+
+public class Example3_2 extends GLProgram {
+	public static void main(String[] args) {
+		new Example3_2().run();
+	}
+	
+	public Example3_2() {
+		super("POINTS",800,600,true);
+	}
+	
+	private float xRot, yRot;
+	
+	public void init() {
+		glClearColor(0,0,0,1);
+		
+		glColor3f(0,1,0);
+	}
+	
+	public void update(long deltaTime) {
+		if(Keyboard.isKeyDown(Keyboard.KEY_LEFT))
+			xRot += 5;
+		if(Keyboard.isKeyDown(Keyboard.KEY_RIGHT))
+			xRot -= 5;