Skip to content

Commit

Permalink
make examples work in windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
philogb committed Jul 25, 2012
1 parent 1e8d1ef commit 489768b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
38 changes: 19 additions & 19 deletions PhiloGL/examples/lessons/16/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ function webGLStart() {

//unpack modules
PhiloGL.unpack();

//create all models
var models = {};
//Create moon
Expand Down Expand Up @@ -34,7 +34,7 @@ function webGLStart() {
}
});
models.box.scale.set(2, 2, 2);

//Load macbook
models.macbookscreen = new O3D.Model({
normals: [
Expand Down Expand Up @@ -132,7 +132,7 @@ function webGLStart() {
alert("There was an error creating the app.");
},
onLoad: function(app) {
var screenWidth = 512,
var screenWidth = 512,
screenHeight = 512,
screenRatio = 1.66,
gl = app.gl,
Expand Down Expand Up @@ -174,19 +174,19 @@ function webGLStart() {
program.setFrameBuffer('monitor', {
width: screenWidth,
height: screenHeight,
bindToTexture: {
bindToTexture: {
parameters: [{
name: 'TEXTURE_MAG_FILTER',
value: 'LINEAR'
}, {
name: 'TEXTURE_MIN_FILTER',
value: 'LINEAR_MIPMAP_NEAREST',
value: 'LINEAR',
generateMipmap: false
}]
},
bindToRenderBuffer: true
});

//Basic gl setup
gl.clearColor(0.0, 0.0, 0.0, 1.0);
gl.clearDepth(1.0);
Expand All @@ -196,45 +196,45 @@ function webGLStart() {
//Add objects to different scenes
outerScene.add(macbook, macbookscreen);
innerScene.add(moon, box);

outerCamera.update();
innerCamera.update();

outerCamera.view.$translate(0, -0.5, 0);

function drawInnerScene() {
program.setFrameBuffer('monitor', true);

gl.viewport(0, 0, screenWidth, screenHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

theta += 0.01;

moon.position = {
x: rho * Math.cos(theta),
y: 0,
z: rho * Math.sin(theta)
};
moon.update();

box.position = {
x: rho * Math.cos(Math.PI + theta),
y: 0,
z: rho * Math.sin(Math.PI + theta)
};
box.update();

innerScene.renderToTexture('monitor');

program.setFrameBuffer('monitor', false);
}

function drawOuterScene() {
gl.viewport(0, 0, screenWidth, screenHeight);
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

laptopTheta += 0.005;

macbook.rotation.set(-Math.PI /2, laptopTheta, 0);
macbook.update();

Expand All @@ -249,7 +249,7 @@ function webGLStart() {
drawOuterScene();
PhiloGL.Fx.requestAnimationFrame(draw);
}

//Animate
draw();
}
Expand Down
12 changes: 6 additions & 6 deletions PhiloGL/shaders/spec-map.fs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
precision highp float;
#endif

#define LIGHT_MAX 50
#define LIGHT_MAX 5

varying vec2 vTexCoord1;
varying vec2 vTexCoord2;
Expand Down Expand Up @@ -47,10 +47,10 @@ void main(void) {
float diffuseLightWeighting = 0.0;
vec3 specularLight = vec3(0.0, 0.0, 0.0);
vec3 diffuseLight = vec3(0.0, 0.0, 0.0);

vec3 transformedPointLocation;
vec3 normal = vTransformedNormal.xyz;

vec3 eyeDirection = normalize(-vPosition.xyz);
vec3 reflectionDirection;

Expand All @@ -62,12 +62,12 @@ void main(void) {
if (shininessVal > 255.0) {
shininessVal = shininess;
}

for (int i = 0; i < LIGHT_MAX; i++) {
if (i < numberPoints) {
transformedPointLocation = (viewMatrix * vec4(pointLocation[i], 1.0)).xyz;
lightDirection = normalize(transformedPointLocation - vPosition.xyz);

if (enableSpecular[i] > 0.0) {
reflectionDirection = reflect(-lightDirection, normal);
specularLightWeighting = pow(max(dot(reflectionDirection, eyeDirection), 0.0), shininessVal);
Expand All @@ -80,7 +80,7 @@ void main(void) {
break;
}
}

lightWeighting = ambientColor + diffuseLight + specularLight;
}

Expand Down

0 comments on commit 489768b

Please sign in to comment.