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);
      //read the volume data file
      GLubyte* pData = new GLubyte[XDIM*YDIM*ZDIM];<char*>(pData), XDIM*YDIM*ZDIM*sizeof(GLubyte));
      //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);
      //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)		
      //generate mipmaps
      //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 ?


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 ?


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