Commits

Philipp Tiefenbacher committed 930bc07 Draft

fixed problem with non power of 2 textures, optimized cells for my laptop resolution

Comments (0)

Files changed (2)

src/game/CellSpace.js

 require(["jquery", "Utils", "CellSpaceResources", "EvoCell"], function($, utils, resources, EC) {
 	var keyboard = utils.keyboard;
 	var gameW = 256, gameH = 256;
-	gameW = 512, gameH = 512;
-	var zoom = 1;
+	gameW = 430, gameH = 230;
+	var zoom = 3;
 	
 	var fpsMonotor = new utils.FPSMonitor("fpsMonitor");
 
 			}
 
 			// ENEMIES //////////////////////////////////////
-			if (cnt % 3 == 0)
+			if (cnt % 2 == 0)
 				reactor.step(enemyRule, enemyDish);
 			if (cnt % 6 == 0)
 				reactor.step(enemy2Rule, enemy2Dish);
 			reactor.step(shipRule, shipDish);
 
 			// "DRAW" SHIP
-			reactor.mixDish(drawRectShader, shipDish, {rectPos: [shipX+1, shipY+1], rectSize: [8, 8], state: (shipRule.nrStates-1)/255});
-			reactor.mixDish(drawRectShader, enemyDish, {rectPos: [shipX+1, shipY+1], rectSize: [3, 3], state: 0});
+			reactor.mixDish(drawRectShader, shipDish, {rectPos: [shipX+1, shipY+1], rectSize: [6, 6], state: (shipRule.nrStates-1)/255});
+			//reactor.mixDish(drawRectShader, enemyDish, {rectPos: [shipX+1, shipY+1], rectSize: [3, 3], state: 0});
 
 			// Dish INTERACTION ///////////////////////////////////
 			reactor.mixDish(intersectSpawnShader, shipExplosionDish, {tex1: shipDish, tex2: enemyDish, state: (shipExplosionRule.nrStates-1)/255.});
-			reactor.mixDish(intersectSpawnShader, enemyDish, {tex1: enemyDish, tex2: shipExplosionDish, state: 1./255.});
+			reactor.mixDish(intersectSpawnShader, enemyDish, {tex1: enemyDish, tex2: shipExplosionDish, state: 0./255.});
 			reactor.mixDish(intersectSpawnShader, shipDish, {tex1: shipDish, tex2: shipExplosionDish, state: 3./255.});	
 
 			// COMPOSE ////////////////////////////////////////////

src/game/gl/GLHelper.js

 		gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
 		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
 		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST);
-		//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
-		//gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
-		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
-		gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+		if (isPOT(width) && isPOT(height)) {
+			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
+			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
+		}
+		else {		
+			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
+			gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
+		}
+		
 		return texture;
 	}
 
+	function isPOT(nr) {
+		var p = 1;
+		while (p < nr) {
+			p *= 2;
+		}
+		return p == nr;
+	}
+
 	// used by the ruletable 
 	// ALPHA only to save memory
 	function createAlphaTexture(gl, width, height, pixels)