Generate 3D mipmap texture

Hi forum,

I want to create a 3D mipmap texture and i am looking for some reference to it . The corresponding opengl code for this is as follows:

  std::ifstream infile(volume_file.c_str(), std::ios_base::binary);
  
  if(infile.good()) 
    {
      //read the volume data file
      GLubyte* pData = new GLubyte[XDIM*YDIM*ZDIM];
      infile.read(reinterpret_cast<char*>(pData), XDIM*YDIM*ZDIM*sizeof(GLubyte));
      infile.close();
      
      //generate OpenGL texture
      glGenTextures(1, &textureID);
      glBindTexture(GL_TEXTURE_3D, textureID);
      
      // set the texture parameters
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
      
      //set the mipmap levels (base and max)
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_BASE_LEVEL, 0);
      glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAX_LEVEL, 4);
      
      //allocate data with internal format and foramt as (GL_RED)		
      glTexImage3D(GL_TEXTURE_3D,0,GL_RED,XDIM,YDIM,ZDIM,0,GL_RED,GL_UNSIGNED_BYTE,pData);
      GL_CHECK_ERRORS;
	
      //generate mipmaps
      glGenerateMipmap(GL_TEXTURE_3D);
      
      //delete the volume data allocated on heap
      delete [] pData;
      return true;

I want to create the same scenario with OF.

The data type that i am dealing with is GLubute. I have checked the loadData(…) from ofTexture and all its version does not deal with the data type that i am looking for.

Any hint/example ?

Thanks

I’m not sure I understand the context in which you need to use GLUbyte. The code you’ve posted defines the texture data as a GLubyte initially, but then in glTexImage3D, refers to the data type as GL_UNSIGNED_BYTE. You could just as easily use an unsigned char:

unsigned char* pData = new unsigned char[XDIMYDIMZDIM];

This is how of generally works with 8bit/channel integer pixel data.

Also, if all you need is a 3dTexture class, I’ve made one for ofxVolumetrics:

It doesn’t support mip maps currently but I have experimented with that before and it wasn’t too hard to implement, I just never committed the code.

@TimS Thanks for the hint!

I have not tried it though, have you implemented the transfer function and gui to interact with the transfer function and visualize the volume of interest ?

Thanks

I’m not sure what you mean by transfer function, but ofxVolumetrics does allow you to upload volume data and visualize it, yes.