Hey, so I’m fairly new to oF and C++ and have the following code, my aim is to generate some simple terrain and render it.
For some reason, when I look at a small section of the mesh, it renders lightning fast, but if I try to look at the entire thing it becomes really slow…
What’s going on ?
#include "ofApp.h"
void ofApp::generateTerrain() {
mesh.clearVertices();
xoff -= ((t_w - 1)*off_increment);
int numTris = 0;
for (int x = 0; x < t_w; x++) {
for (int y = 0; y < t_w; y++) {
float z = ofNoise(xoff, yoff)*zheight;
mesh.addVertex(ofVec3f(ofPoint(x*seperation, y*seperation, z)));
z = ofNoise(xoff, yoff + off_increment)*zheight;
mesh.addVertex(ofVec3f(ofPoint(x*seperation, (y + 1)*seperation, z)));
z = ofNoise(xoff + off_increment, yoff) * zheight;
mesh.addVertex(ofVec3f(ofPoint((x + 1)*seperation, y*seperation, z)));
mesh.addTriangle(numTris * 3, numTris * 3 + 1, numTris * 3 + 2);
numTris++;
mesh.addVertex(ofVec3f(ofPoint((x + 1)*seperation, y*seperation, z)));
z = ofNoise(xoff + off_increment, yoff + off_increment) * zheight;
mesh.addVertex(ofVec3f(ofPoint((x + 1)*seperation, (y + 1)*seperation, z)));
z = ofNoise(xoff, yoff + off_increment) * zheight;
mesh.addVertex(ofVec3f(ofPoint(x*seperation, (y + 1)*seperation, z)));
mesh.addTriangle(numTris * 3, numTris * 3 + 1, numTris * 3 + 2);
numTris++;
yoff += off_increment;
}
yoff -= (t_h*off_increment);
xoff += off_increment;
}
}
//--------------------------------------------------------------
void ofApp::setup() {
mesh.setMode(OF_PRIMITIVE_TRIANGLES);
t_w = 50;
t_h = 50;
seperation = 100;
xoff = 0.0f;
yoff = 0.0f;
off_increment = 0.1f;
zheight = 200;
generateTerrain();
}
//--------------------------------------------------------------
void ofApp::update(){
generateTerrain();
}
//--------------------------------------------------------------
void ofApp::draw(){
cam.begin();
mesh.draw();
cam.end();
}