qvolray
diff src/volume.cc @ 18:3d05c261a2f4
demo metaballs crash & burn
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Wed, 11 Apr 2012 06:08:59 +0300 |
parents | 535762131d34 |
children | 450d4c50470f |
line diff
1.1 --- a/src/volume.cc Wed Apr 11 01:44:45 2012 +0200 1.2 +++ b/src/volume.cc Wed Apr 11 06:08:59 2012 +0300 1.3 @@ -26,6 +26,19 @@ 1.4 } 1.5 } 1.6 1.7 +bool Volume::create(int xsz, int ysz, int zsz, float *data) 1.8 +{ 1.9 + if(!tex) 1.10 + glGenTextures(1, &tex); 1.11 + glBindTexture(GL_TEXTURE_3D, tex); 1.12 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.13 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.14 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1.15 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1.16 + glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 1.17 + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F_ARB, xsz, ysz, zsz, 0, GL_RGBA, GL_FLOAT, data); 1.18 +} 1.19 + 1.20 bool Volume::load(const char *fname) 1.21 { 1.22 std::list<std::string> slist; 1.23 @@ -88,14 +101,7 @@ 1.24 calc_gradients(voxels, sz[0], sz[1], sz[2]); 1.25 1.26 /* create the volume texture */ 1.27 - glGenTextures(1, &tex); 1.28 - glBindTexture(GL_TEXTURE_3D, tex); 1.29 - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 1.30 - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 1.31 - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 1.32 - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 1.33 - glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); 1.34 - glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA32F_ARB, sz[0], sz[1], sz[2], 0, GL_RGBA, GL_FLOAT, voxels); 1.35 + create(sz[0], sz[1], sz[2], voxels); 1.36 1.37 /* ... and destroy our copy */ 1.38 delete [] voxels;