void shader_gentex (GLuint *tex) { glDeleteTextures(1, tex); glGenTextures(1, tex); glBindTexture(GL_TEXTURE_2D, *tex); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); int w = 256; int h = 256; BYTE *data = malloc(w*h*3); float r = rand()%1000; float g = rand()%1000; float b = rand()%1000; for(int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { int i = (x*h + y)*3; int s = 0, d = 10; data[i] = 255*perlin_noise(x, y, w, h, r, s, d); data[i+1] = 255*perlin_noise(x, y, w, h, g, s, d); data[i+2] = 255*perlin_noise(x, y, w, h, b, s, d); } } gluBuild2DMipmaps(GL_TEXTURE_2D, 3, w, h, GL_RGB, GL_UNSIGNED_BYTE, data); free(data); }
void Perlin3_next(Perlin3 *unit, int inNumSamples) { float *x = IN(0), *y = IN(1), *z = IN(2), *out = OUT(0); for (int i=0; i<inNumSamples; ++i) { out[i] = perlin_noise(x[i], y[i], z[i]); //printf("result @[%g, %g, %g] is %g\n", x[i], y[i], z[i], out[i]); } }
float * grass_texture(int width, int height) { float * noise = (float *) malloc(sizeof(float) * width * height); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { noise[x * width + y] = perlin_noise((x + 0.3)/63.2f, (y + 0.7)/63.8f, 0.8, 8); } } normalize_image(noise, width, height); return noise; }
//-------------------------------------------------------------- void ofApp::setup(){ srand(time(NULL)); vector<vector<double> > blank1; vector<double> blank2; vector<double> coordinate; coordinate.push_back(0); coordinate.push_back(0); vector<vector<vector<vector<double> > > > gradients; vector<int> perlin_noises; for(int f=0; f<4; f++) { } for(int a=0; a<pow(2,f); a++) { gradients.push_back(blank1); for(int b=0; b<pow(2,f); b++) { gradients[a].push_back(blank2); double theta=rand()*6.283/RAND_MAX; gradients[a][b].push_back(cos(theta)); gradients[a][b].push_back(sin(theta)); } } //initializes gradients for(double x=0; x<1000; x++) { shade.push_back(blank2); for(double y=0; y<1000; y++) { coordinate[0]=fmod(x,250)/250; coordinate[1]=fmod(y,250)/250; shade[x].push_back(perlin_noise(coordinate,gradients[x/250][y/250],gradients[x/250+1][y/250],gradients[x/250+1][y/250+1],gradients[x/250][y/250+1])); } } //calls perlin_noise at each point }