I am trying to read floating point numbers from a CSV file that contains a pre-computed texture, stores it in a 1-dimensional array and then puts this data in a 2-dimensional texture. I need to make sure the following code does this because I have problems accessing the data and I cannot figure out where the error is:
// Allocate memory float * image = new float [width * height * 3 ]; for( int i = 0; i < height; i++) { for( int j = 0; j < width-1; j++) { fscanf( fDataFile, "%f,", &fData ); image[ 4 * i * j + 0 ] = fData; image[ 4 * i * j + 1 ] = fData; image[ 4 * i * j + 2 ] = fData; } fscanf( fDataFile, "%f", &fData ); image[ 4 * i * width-1 + 0 ] = fData; image[ 4 * i * width-1 + 1 ] = fData; image[ 4 * i * width-1 + 2 ] = fData; }
There shouldn't be a problem here, but the following worries me:
Is it possible to simply point the glTexImage2D pointer to my one-dimensional array?
the array size is width * height * 3, and the texture format should be width * height with 3 channels ... so the size should be fine, I think! However, my program will not work as expected, and this is one of the potential sources of errors.
source share