void ofApp::setup() {
	ofSetVerticalSync(true);
	ofImage img;
	img.loadImage("linzer.png");
	
	mesh.setMode(OF_PRIMITIVE_TRIANGLES);
	int skip = 4;	
	int width = img.getWidth();
	int height = img.getHeight();
	ofVec3f zero(0, 0, 0);
	for(int y = 0; y < height - skip; y += skip) {
		for(int x = 0; x < width - skip; x += skip) {
			ofVec3f nw = getVertexFromImg(img, x, y);
			ofVec3f ne = getVertexFromImg(img, x + skip, y);
			ofVec3f sw = getVertexFromImg(img, x, y + skip);
			ofVec3f se = getVertexFromImg(img, x + skip, y + skip);
			if(nw != zero && ne != zero && sw != zero && se != zero) {
				addFace(mesh, nw, ne, se, sw);
			}
		}
	}
	
	light.enable();
	light.setPosition(500, 0, 0);
	
	glEnable(GL_DEPTH_TEST);
}
Пример #2
0
//--------------------------------------------------------------
void ofApp::setup() {

    #ifdef TARGET_OPENGLES
    // While this will will work on normal OpenGL as well, it is 
    // required for OpenGL ES because ARB textures are not supported.
    // If this IS set, then we conditionally normalize our 
    // texture coordinates below.
    ofEnableNormalizedTexCoords();
    #endif

	img.load("linzer.png");
	
	// OF_PRIMITIVE_TRIANGLES means every three vertices create a triangle
	mesh.setMode(OF_PRIMITIVE_TRIANGLES);
	int skip = 10;	// this controls the resolution of the mesh
	
	int width = img.getWidth();
	int height = img.getHeight();

	ofVec2f imageSize(width,height);

	ofVec3f zero(0, 0, 0);
	for(int y = 0; y < height - skip; y += skip) {
		for(int x = 0; x < width - skip; x += skip) {
			/*
			 To construct a mesh, we have to build a collection of quads made up of
			 the current pixel, the one to the right, to the bottom right, and
			 beneath. These are called nw, ne, se and sw. To get the texture coords
			 we need to use the actual image indices.
			 */
			ofVec3f nw = getVertexFromImg(img, x, y);
			ofVec3f ne = getVertexFromImg(img, x + skip, y);
			ofVec3f sw = getVertexFromImg(img, x, y + skip);
			ofVec3f se = getVertexFromImg(img, x + skip, y + skip);
			ofVec2f nwi(x, y);
			ofVec2f nei(x + skip, y);
			ofVec2f swi(x, y + skip);
			ofVec2f sei(x + skip, y + skip);
			
			// ignore any zero-data (where there is no depth info)
			if(nw != zero && ne != zero && sw != zero && se != zero) {
				addFace(mesh, nw, ne, se, sw);

				// Normalize our texture coordinates if normalized 
				// texture coordinates are currently enabled.
				if(ofGetUsingNormalizedTexCoords()) {
					nwi /= imageSize;
					nei /= imageSize;
					sei /= imageSize;
					swi /= imageSize;
				}

				addTexCoords(mesh, nwi, nei, sei, swi);
			}
		}
	}
	
	vboMesh = mesh;
}
void testApp::setup(){
	
	//set up img mesh
	ofSetVerticalSync(true);  //?????
	ofImage img;
	img.loadImage("out8.png");
	meshImg.setMode(OF_PRIMITIVE_TRIANGLES);
	
	int skip = 3;	
	int width = img.getWidth();
	int height = img.getHeight();
	ofVec3f zero(0, 0, 0);
	for(int y = 0; y < height - skip; y += skip) {
		for(int x = 0; x < width - skip; x += skip) {
			ofVec3f nw = getVertexFromImg(img, x, y);
			ofVec3f ne = getVertexFromImg(img, x + skip, y);
			ofVec3f sw = getVertexFromImg(img, x, y + skip);
			ofVec3f se = getVertexFromImg(img, x + skip, y + skip);
			if(nw != zero && ne != zero && sw != zero && se != zero) {
				addFace(meshImg, nw, ne, se, sw);
			}
		}
	}	
	// even points can overlap with each other, let's avoid that
	glEnable(GL_DEPTH_TEST);
	
	
	//------------------------------------------------------------------
	//set up network mesh
	meshNetwork.setMode(OF_PRIMITIVE_POINTS);
	numPoints=100;
	numLoops = 100;
	counter=0;
	phase = PI*2;
	
	points.resize(numPoints);  //do this to initiate the vector array
	
	//initiate the points 
	for (int i=0; i< numPoints; i++) {		
		points[i] = getVertexFromImg(img, ofRandom(width), ofRandom(height));
	}
	//cout << ofToString(points) << endl;
}
void ofxShadowedTerrain::loadMapFromImage(string _filename){
    heightmapimg.loadImage(_filename);
	
    mesh.setMode(OF_PRIMITIVE_TRIANGLES);

	gridw = heightmapimg.getWidth();
	gridh = heightmapimg.getHeight();
	
    int rawindex=0;
    
    heightmapdataobj.ncols=heightmapimg.getWidth();
    heightmapdataobj.nrows=heightmapimg.getHeight();
    
    
    for(int y = 0; y < gridh; y += 1) {
		for(int x = 0; x < gridw ; x += 1) {
            rawindex=x+y*gridw;
            heightmapdataobj.mydata.push_back(getValueFromImagePos(heightmapimg, x, y));
        }
    }
    
    
    triangles.clear();
    
    for(int y = 0; y < gridh - skipy; y += skipy) {
		for(int x = 0; x < gridw - skipx; x += skipx) {
			ofVec3f nw = getVertexFromImg(heightmapimg, x, y);
			ofVec3f ne = getVertexFromImg(heightmapimg, x + skipx, y);
			ofVec3f sw = getVertexFromImg(heightmapimg, x, y + skipy);
			ofVec3f se = getVertexFromImg(heightmapimg, x + skipx, y + skipy);
			
            addFace(mesh, nw, ne, se, sw);
		}
	}
    mesh.setFromTriangles(triangles);

    prepareForShadows();
}