PDA

View Full Version : loading exr files to a texture



Zarathustra
03-31-2008, 12:41 PM
I'm going to implement a paper about env. mapping and I have prefiltered env maps. they are in a power of 2 format (1024*1024). the X-axis is the phi and the Y-axis is my theta from spherical coordinates.

Now, my problem is: what's the best way to load those .exr files? Atm I have this code. (nvm the 'data' stuff)



void initEnvData(){

Header header;
Array<Rgba> pixels;
const Imf::Rgba * _rawPixels;
loadImage("0_175.exr", header, pixels);
_rawPixels = pixels;
cout<<"Image loaded" <<endl;

float* data1 = (float*)malloc(48*sizeof(float));
float* data2 = (float*)malloc(48*sizeof(float));

//insert loop to read data from file
//placeholder
for (int i=0; i<96; i++){
data1[i] = i+1.0;
}
//placeholder

glGenTextures(1, &amp;dataTexture1);
glGenTextures(2, &amp;dataTexture2);
glGenTextures(3, &amp;envMapTexture);

glBindTexture( GL_TEXTURE_2D, dataTexture1);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F_ARB, 4, 4 ,0,GL_RGB16F_ARB,GL_FLOAT,data1);

glBindTexture( GL_TEXTURE_2D, dataTexture2);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB16F_ARB, 4, 4 ,0,GL_RGB16F_ARB,GL_FLOAT,data2);

glBindTexture (GL_TEXTURE_2D, envMapTexture);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA16F_ARB, 1024, 1024, 0, GL_RGBA, GL_FLOAT, _rawPixels);
}


But _rawpixels is a 1D array of RGBA stucts, so I'm guessing that won't work right? Do I need to convert to a 1024*1024*4 array thing or something like that ?

RenderBuffer
03-31-2008, 02:17 PM
I've never tried to load an EXR by hand but you might want to use a library.... http://www.openexr.com/downloads.html

Zarathustra
03-31-2008, 02:48 PM
Yep, I use that library but that makes a 1D array of RGBA structs.

So now I'm wondering how I should manipulate it to make it fit in GL_TEXTURE_2D and which other params I should use.