PDA

View Full Version : 3D texture not loading correctly



jordanrs
04-08-2012, 08:28 AM
I am attempting to replicate this guys 3D rendering example 3D volume example and slicing (http://www.bobdanani.net/tutorials/13-graphics-and-user-interface/4-3d-volume-texturing-and-slicing/), it required a few tweeks to get running but it compiles fine.

My problem comes when loading in the 3D texture with this code


//Create Texture
glGenTextures(1, &textureName);
glBindTexture(GL_TEXTURE_3D, textureName);

glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameterf(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY, volumedata1->sizeX ,
volumedata1->sizeY, volumedata1->sizeZ, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, volumedata1->data);

using this file loader


int VolumeLoad(char *filename, VolumeData *volumedata) {
FILE *file;
unsigned long size; // size of the image
// make sure the file is there.
if ((file = fopen(filename, "rb"))==NULL) {
printf("File Not Found : %s\n",filename);
return 0;
}
// read the sizeX, sizeY, and sizeZ
volumedata->sizeX = getshort (file);
volumedata->sizeY = getshort (file);
volumedata->sizeZ = getshort (file);

printf("Size x: %iu , Size y : %iu , Size z = %iu\n", volumedata->sizeX, volumedata->sizeY, volumedata->sizeZ);

// calculate the total volume size
size = (volumedata->sizeX) * (volumedata->sizeY) * (volumedata->sizeZ);
//allocate size for the volume data
volumedata->data = (unsigned short *) malloc(size * sizeof( unsigned short));

if (volumedata->data == NULL) {
printf("Error allocating memory for volume");
return 0;
}

//Read the data in the volume file

for (int z = 0; z < volumedata->sizeZ; z++) {
for (int y = 0; y< volumedata->sizeY; y++) {
for (int x = 0; x < volumedata->sizeX; x++) {
volumedata->data[ x + y* volumedata->sizeX + z* volumedata->sizeX *
volumedata->sizeY ]= (getshort(file));
}
}
}

//delete[](volumedata->data);
// we are done, return 1
return 1;
}

with this data set Data set of sixe (size: x=184 y=256 z=170) (http://www.cg.tuwien.ac.at/courses/Visualisierung/data/skewed_head.zip )

When the program loads the texture is shifted and overlapping, upon looking into it with the gDEBugger for VS2012 every other row and column is empty or filled with random low numbers. Attached is a screenshots of the output from the debugger. Any help would be greatly appreciated.

http://i235.photobucket.com/albums/ee248/outlawtorm/3dtexture1.jpg