Skip to content

Commit

Permalink
Turn off bottoms for very short buildings to avoid z-fighting issue.
Browse files Browse the repository at this point in the history
Load 4 grass textures and allow user to flip between them with keys 1-4
for testing.
  • Loading branch information
fadookie committed Jul 8, 2012
1 parent 150ddd0 commit 547ee1d
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 22 deletions.
11 changes: 7 additions & 4 deletions Building.pde
Expand Up @@ -59,10 +59,13 @@ class Building implements Comparable<Building> {
vertex(0, scaleWorkVector.y, scaleWorkVector.z, 0, 1);

//BOTTOM
vertex(0, 0, 0, 0, 0);
vertex(scaleWorkVector.x, 0, 0, windowTextureScale.x, 0);
vertex(scaleWorkVector.x, 0, scaleWorkVector.z, windowTextureScale.x, windowTextureScale.z);
vertex(0, 0, scaleWorkVector.z, 0, windowTextureScale.z);
if(scaleWorkVector.y < -0.05) {
//Only draw bottom if building is not super short as it was causing z-fighting
vertex(0, 0, 0, 0, 0);
vertex(scaleWorkVector.x, 0, 0, windowTextureScale.x, 0);
vertex(scaleWorkVector.x, 0, scaleWorkVector.z, windowTextureScale.x, windowTextureScale.z);
vertex(0, 0, scaleWorkVector.z, 0, windowTextureScale.z);
}

//BACK
vertex(0, 0, 0, 0, windowTextureScale.y);
Expand Down
59 changes: 41 additions & 18 deletions Twities.pde
Expand Up @@ -29,7 +29,9 @@ PVector citySize;
PVector maxCityBounds = new PVector();
PVector minCityBounds = new PVector();

PImage grassImage;
PImage roadImage;
PImage[] grassImages;
int currentGrassImage = 0;

int maxFollowers; //How many followers the most popular user has
String messageString = null;
Expand Down Expand Up @@ -314,15 +316,12 @@ void setup() {

//Load additional assets

// Creating texture with linear filtering and the
// size of the image that will be loaded into it:
grassImage = loadImage("grass1.png");
//Texture.Parameters params = new Texture.Parameters();
//params.sampling = Texture.LINEAR;
//grassTexture = new Texture(this, 83, 83, params);

//// Loading image.
//grassTexture.set(grassImage);
//grassImage = loadImage("grass"+round(random(1, 4))+".png");
grassImages = new PImage[4];
for (int i = 0; i < grassImages.length; i++) {
grassImages[i] = loadImage("grass"+(i+1)+".png");
}
roadImage = loadImage("road.png");
}


Expand All @@ -336,26 +335,39 @@ void draw() {
//Draw ground
hint(DISABLE_DEPTH_TEST); //Was getting some weird interlacing stuff, so i'm now drawing the ground in it's own depth buffer underneath the buildings at all times
pushStyle();
pushMatrix();
noStroke();
fill(0);

pushMatrix();

//Just make the ground plane really large
scale(1000, 0, 1000);

beginShape(QUADS);
pgl.textureSampling(Texture.LINEAR);
pgl.textureWrap(Texture.REPEAT); //Set texture wrap mode to GL_REPEAT. See http://code.google.com/p/processing/issues/detail?id=94
textureMode(NORMAL);
texture(grassImage);
float textureScale = 10000;
texture(grassImages[currentGrassImage]);
float textureScale = 90000;
vertex(minCityBounds.x, 0, minCityBounds.z, 0, 0);
vertex(maxCityBounds.x, 0, minCityBounds.z, textureScale, 0);
vertex(maxCityBounds.x, 0, maxCityBounds.z, textureScale, textureScale);
vertex(minCityBounds.x, 0, maxCityBounds.z, 0, textureScale);
endShape();

popMatrix();

//Draw roads
/*
beginShape(QUADS);
texture(roadImage);
vertex(minCityBounds.x, 0, minCityBounds.z, 0, 0);
vertex(1, 0, minCityBounds.z, 1, 0);
vertex(1, 0, maxCityBounds.z, 1, 1);
vertex(minCityBounds.x, 0, maxCityBounds.z, 0, 1);
endShape();
*/

popStyle();
hint(ENABLE_DEPTH_TEST);

Expand Down Expand Up @@ -438,12 +450,23 @@ void keyPressed() {
if (!searchUsernameTextfield.isActive()) {
if (CODED == key) {
} else {
if ('/' == key) {
switch(key) {
case '/':
toggleSearchMode();
} else if ('d' == key) {
DEBUG = !DEBUG;
} else if ('s' == key) {
saveNextFrame = true;
break;
case 'd':
DEBUG = !DEBUG;
break;
case 's':
saveNextFrame = true;
break;
case '1':
case '2':
case '3':
case '4':
//Switch grass texture to texture 1-4 (stored in array items 0-3)
currentGrassImage = Integer.parseInt(Character.toString(key)) - 1;
break;
}
}
}
Expand Down
Binary file modified data/grass1.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/grass2.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/grass3.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/grass4.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 547ee1d

Please sign in to comment.