Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Loading a volumetric data set to a 3D texture

  1. #1
    Junior Member Newbie
    Join Date
    Feb 2012
    Posts
    3

    Question Loading a volumetric data set to a 3D texture

    Hi,

    I'm trying to load a volume data to 3D texture using the code bellow in order to implement a GPU based raycasting render:

    #define XDIM 128

    #define YDIM 128
    #define ZDIM 128



    LoadVolumeFromFile(const char* fileName) {


    const int size = XDIM*YDIM*ZDIM;
    FILE *pFile = fopen(fileName,"rb");
    if(NULL == pFile) {
    return false;
    }
    GLubyte* pVolume=new GLubyte[size];
    fread(pVolume,sizeof(GLubyte),size,pFile);
    fclose(pFile);
    glPixelStorei(GL_UNPACK_ALIGNMENT,1);
    glGenTextures(1, &volume_texture);
    glBindTexture(GL_TEXTURE_3D, volume_texture);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_BORDER);
    glTexImage3D(GL_TEXTURE_3D, 0,GL_INTENSITY, XDIM, YDIM,ZDIM,0, GL_LUMINANCE,GL_UNSIGNED_BYTE,pVolume);



    delete []pVolume;
    cout << "volume texture created" << endl;


    }

    it works well but when I substitute
    glTexImage3D(GL_TEXTURE_3D, 0,GL_INTENSITY, XDIM, YDIM,ZDIM,0, GL_LUMINANCE,GL_UNSIGNED_BYTE,pVolume);

    to this
    glTexImage3D(GL_TEXTURE_3D, 0,GL_RGBA, XDIM, YDIM,ZDIM,0, GL_RGBA,GL_UNSIGNED_BYTE,pVolume);

    I get runtime error!

    I would really appreciate if someone helps solve this problem.

    Thanks in advance

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,101
    RBGA expects 4 times the data XDIM*YDIM*ZDIM*4

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •