Skip to content

Commit 1e55435

Browse files
committed
Testing LWJGL renderer
1 parent 358ebae commit 1e55435

51 files changed

Lines changed: 19491 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

java/libraries/lwjgl/.classpath

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
5+
<classpathentry combineaccessrules="false" kind="src" path="/processing-core"/>
6+
<classpathentry kind="lib" path="library/lwjgl.jar" sourcepath="/Users/andres/Coding/OpenGL/lwjgl-source-2.8.3.zip"/>
7+
<classpathentry kind="lib" path="library/lwjgl_util.jar"/>
8+
<classpathentry kind="lib" path="library/lwjgl_util_applet.jar"/>
9+
<classpathentry kind="output" path="bin"/>
10+
</classpath>

java/libraries/lwjgl/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>processing-lwjgl</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

java/libraries/lwjgl/.settings/org.eclipse.jdt.core.prefs

Lines changed: 273 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#Fri Feb 19 16:20:47 EST 2010
2+
eclipse.preferences.version=1
3+
formatter_profile=_processing
4+
formatter_settings_version=11

java/libraries/lwjgl/build.xml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?xml version="1.0"?>
2+
<project name="Processing LWJGL Library" default="build">
3+
4+
<target name="clean" description="Clean the build directories">
5+
<delete dir="bin" />
6+
<delete file="library/lwopengl.jar" />
7+
</target>
8+
9+
<target name="compile" description="Compile sources">
10+
<condition property="core-built">
11+
<available file="../../../core/core.jar" />
12+
</condition>
13+
<fail unless="core-built" message="Please build the core library first and make sure it sits in ../../../core/core.jar" />
14+
15+
<mkdir dir="bin" />
16+
<javac target="1.5"
17+
srcdir="src" destdir="bin"
18+
encoding="UTF-8"
19+
includeAntRuntime="false"
20+
classpath="../../../core/core.jar; library/lwjgl.jar; library/lwjgl_util.jar; library/lwjgl_applet.jar" />
21+
22+
<!-- Copy the shaders to the bin folder.
23+
Eclipse does this automatically. -->
24+
<copy todir="bin">
25+
<fileset dir="src">
26+
<include name="processing/lwopengl/*.glsl" />
27+
</fileset>
28+
</copy>
29+
</target>
30+
31+
<target name="build" depends="compile" description="Build LWJGL library">
32+
<jar basedir="bin" destfile="library/lwopengl.jar" />
33+
</target>
34+
</project>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* Brick Tower
3+
* by Ira Greenberg.
4+
*
5+
* 3D castle tower constructed out of individual bricks.
6+
* Uses the PVector and Cube classes.
7+
*/
8+
9+
import processing.lwjgl.*;
10+
11+
float bricksPerLayer = 16.0;
12+
float brickLayers = 18.0;
13+
Cube brick;
14+
float brickWidth = 60, brickHeight = 25, brickDepth = 25;
15+
float radius = 175.0;
16+
float angle = 0;
17+
18+
void setup(){
19+
size(640, 360, LWJGL);
20+
brick = new Cube(brickWidth, brickHeight, brickDepth);
21+
}
22+
23+
void draw(){
24+
background(0);
25+
float tempX = 0, tempY = 0, tempZ = 0;
26+
fill(182, 62, 29);
27+
noStroke();
28+
// Add basic light setup
29+
lights();
30+
translate(width/2, height*1.2, -380);
31+
// Tip tower to see inside
32+
rotateX(radians(-45));
33+
// Slowly rotate tower
34+
rotateY(frameCount * PI/600);
35+
for (int i = 0; i < brickLayers; i++){
36+
// Increment rows
37+
tempY-=brickHeight;
38+
// Alternate brick seams
39+
angle = 360.0 / bricksPerLayer * i/2;
40+
for (int j = 0; j < bricksPerLayer; j++){
41+
tempZ = cos(radians(angle))*radius;
42+
tempX = sin(radians(angle))*radius;
43+
pushMatrix();
44+
translate(tempX, tempY, tempZ);
45+
rotateY(radians(angle));
46+
// Add crenelation
47+
if (i==brickLayers-1){
48+
if (j%2 == 0){
49+
brick.create();
50+
}
51+
}
52+
// Create main tower
53+
else {
54+
brick.create();
55+
}
56+
popMatrix();
57+
angle += 360.0/bricksPerLayer;
58+
}
59+
}
60+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
class Cube {
2+
3+
PVector[] vertices = new PVector[24];
4+
PVector[] normals = new PVector[6];
5+
float w, h, d;
6+
7+
Cube(){ }
8+
9+
Cube(float w, float h, float d){
10+
this.w = w;
11+
this.h = h;
12+
this.d = d;
13+
14+
// Cube composed of 6 quads
15+
// Front
16+
normals[0] = new PVector(0, 0, 1);
17+
vertices[0] = new PVector(-w/2, -h/2, d/2);
18+
vertices[1] = new PVector(w/2, -h/2, d/2);
19+
vertices[2] = new PVector(w/2, h/2, d/2);
20+
vertices[3] = new PVector(-w/2, h/2, d/2);
21+
22+
// Left
23+
normals[1] = new PVector(-1, 0, 0);
24+
vertices[4] = new PVector(-w/2, -h/2, d/2);
25+
vertices[5] = new PVector(-w/2, -h/2, -d/2);
26+
vertices[6] = new PVector(-w/2, h/2, -d/2);
27+
vertices[7] = new PVector(-w/2, h/2, d/2);
28+
29+
// Right
30+
normals[2] = new PVector(1, 0, 0);
31+
vertices[8] = new PVector(w/2, -h/2, d/2);
32+
vertices[9] = new PVector(w/2, -h/2, -d/2);
33+
vertices[10] = new PVector(w/2, h/2, -d/2);
34+
vertices[11] = new PVector(w/2, h/2, d/2);
35+
36+
// Back
37+
normals[3] = new PVector(0, 0, -1);
38+
vertices[12] = new PVector(-w/2, -h/2, -d/2);
39+
vertices[13] = new PVector(w/2, -h/2, -d/2);
40+
vertices[14] = new PVector(w/2, h/2, -d/2);
41+
vertices[15] = new PVector(-w/2, h/2, -d/2);
42+
43+
// Top
44+
normals[4] = new PVector(0, 1, 0);
45+
vertices[16] = new PVector(-w/2, -h/2, d/2);
46+
vertices[17] = new PVector(-w/2, -h/2, -d/2);
47+
vertices[18] = new PVector(w/2, -h/2, -d/2);
48+
vertices[19] = new PVector(w/2, -h/2, d/2);
49+
50+
// Bottom
51+
normals[5] = new PVector(0, 1, 0);
52+
vertices[20] = new PVector(-w/2, h/2, d/2);
53+
vertices[21] = new PVector(-w/2, h/2, -d/2);
54+
vertices[22] = new PVector(w/2, h/2, -d/2);
55+
vertices[23] = new PVector(w/2, h/2, d/2);
56+
}
57+
58+
void create(){
59+
for (int i=0; i<6; i++){
60+
beginShape(QUADS);
61+
normal(normals[i].x, normals[i].y, normals[i].z);
62+
for (int j = 0; j < 4; j++){
63+
vertex(vertices[j+4*i].x, vertices[j+4*i].y, vertices[j+4*i].z);
64+
}
65+
endShape();
66+
}
67+
}
68+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* Cubic Grid
3+
* by Ira Greenberg.
4+
*
5+
* 3D translucent colored grid uses nested pushMatrix()
6+
* and popMatrix() functions.
7+
*/
8+
9+
import processing.lwjgl.*;
10+
11+
float boxSize = 40;
12+
float margin = boxSize*2;
13+
float depth = 400;
14+
color boxFill;
15+
16+
void setup() {
17+
size(640, 360, LWJGL);
18+
noStroke();
19+
hint(DISABLE_DEPTH_TEST);
20+
}
21+
22+
void draw() {
23+
background(255);
24+
25+
// Center and spin grid
26+
translate(width/2, height/2, -depth);
27+
rotateY(frameCount * 0.01);
28+
rotateX(frameCount * 0.01);
29+
30+
// Build grid using multiple translations
31+
for (float i =- depth/2+margin; i <= depth/2-margin; i += boxSize){
32+
pushMatrix();
33+
for (float j =- height+margin; j <= height-margin; j += boxSize){
34+
pushMatrix();
35+
for (float k =- width+margin; k <= width-margin; k += boxSize){
36+
// Base fill color on counter values, abs function
37+
// ensures values stay within legal range
38+
boxFill = color(abs(i), abs(j), abs(k), 50);
39+
pushMatrix();
40+
translate(k, j, i);
41+
fill(boxFill);
42+
box(boxSize, boxSize, boxSize);
43+
popMatrix();
44+
}
45+
popMatrix();
46+
}
47+
popMatrix();
48+
}
49+
}
50+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/**
2+
* LightsGL.
3+
* Modified from an example by Simon Greenwold.
4+
*
5+
* Display a box with three different kinds of lights.
6+
*/
7+
8+
import processing.lwjgl.*;
9+
10+
void setup()
11+
{
12+
size(1024, 768, LWJGL);
13+
noStroke();
14+
}
15+
16+
void draw()
17+
{
18+
defineLights();
19+
background(0);
20+
21+
for (int x = 0; x <= width; x += 100) {
22+
for (int y = 0; y <= height; y += 100) {
23+
pushMatrix();
24+
translate(x, y);
25+
rotateY(map(mouseX, 0, width, 0, PI));
26+
rotateX(map(mouseY, 0, height, 0, PI));
27+
box(90);
28+
popMatrix();
29+
}
30+
}
31+
}
32+
33+
void defineLights() {
34+
// Orange point light on the right
35+
pointLight(150, 100, 0, // Color
36+
200, -150, 0); // Position
37+
38+
// Blue directional light from the left
39+
directionalLight(0, 102, 255, // Color
40+
1, 0, 0); // The x-, y-, z-axis direction
41+
42+
// Yellow spotlight from the front
43+
spotLight(255, 255, 109, // Color
44+
0, 40, 200, // Position
45+
0, -0.5, -0.5, // Direction
46+
PI / 2, 2); // Angle, concentration
47+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* Reflection
3+
* by Simon Greenwold.
4+
*
5+
* Vary the specular reflection component of a material
6+
* with the horizontal position of the mouse.
7+
*/
8+
9+
import processing.lwjgl.*;
10+
11+
void setup() {
12+
size(640, 360, LWJGL);
13+
noStroke();
14+
colorMode(RGB, 1);
15+
fill(0.4);
16+
}
17+
18+
void draw() {
19+
background(0);
20+
translate(width / 2, height / 2);
21+
// Set the specular color of lights that follow
22+
lightSpecular(1, 1, 1);
23+
directionalLight(0.8, 0.8, 0.8, 0, 0, -1);
24+
float s = mouseX / float(width);
25+
specular(s, s, s);
26+
sphere(120);
27+
}

0 commit comments

Comments
 (0)