本文整理汇总了C++中Perlin::PerlinNoise3D方法的典型用法代码示例。如果您正苦于以下问题:C++ Perlin::PerlinNoise3D方法的具体用法?C++ Perlin::PerlinNoise3D怎么用?C++ Perlin::PerlinNoise3D使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Perlin
的用法示例。
在下文中一共展示了Perlin::PerlinNoise3D方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: CreateNoiseTexture
unsigned int TextureLoader::CreateNoiseTexture(double alpha, double beta, int n, int side) {
Perlin perlin;
float* data = new float[side*side*side];
double step = 1.0/(side-1.0);
int index = 0;
for (double x = 0; x <= 1; x += step) {
for (double y = 0; y <= 1; y += step) {
for(double z = 0; z <= 1; z += step) {
float noise = static_cast<float>(perlin.PerlinNoise3D(x, y, z, alpha, beta, n));
data[index] = noise;
index++;
}
}
}
//create the OpenGL texture
unsigned int gl_texture_object;
glGenTextures(1, &gl_texture_object);
glBindTexture(GL_TEXTURE_3D, gl_texture_object);
//filtering
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_REPEAT);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
float maxAnisotropy;
glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnisotropy);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnisotropy);
//when we work with textures of sizes not divisible by 4 we have to use the line reader
//which loads the textures in OpenGL so as it can work with a 1 alligned memory (default is 4)
//glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
//Generates texture
glTexImage3D(GL_TEXTURE_3D, 0, GL_R32F, side, side, side, 0, GL_RED, GL_FLOAT, data);
//eliminates the array from the RAM
delete data;
//creates the mipmap hierarchy
glGenerateMipmap(GL_TEXTURE_3D);
//returns the texture object
return gl_texture_object;
}