Jump to content
  • Advertisement
Sign in to follow this  
Zarathustra

OpenGL load exr file

This topic is 3909 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a 1024*1024 EXR file. Now I want to put that in Gluint thingy so I can pass it on to my cg shader. But I have no idea how to actually get the exr data in the texture. This is what I have atm.
GLuint dataTexture1;
GLuint dataTexture2;
GLuint envMapTexture;


	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+1.0;
	}
	//placeholder

	glGenTextures(1, &dataTexture1);
	glGenTextures(2, &dataTexture2);
	glGenTextures(3, &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);
The dataTexture stuff is not relevant here. I suppose I need to convert that _rawPixels 1D array to a 2D array? And I guess openGL can't put those RGBA structs in the texture?

Share this post


Link to post
Share on other sites
Advertisement
How is Rgba and Array<Rgba> defined ? As long as the data is continuously in memory, lets say:

struct Rgba {
float R,G,B,A;
};

struct Rgba pixels[1024*1024];


they yes, you can just pass the pointer to glTexImage2D.

Share this post


Link to post
Share on other sites
Well I think it is but it just won't work so I tried this


GLuint envMapTexture;

void initEnvData(){

Imf::Rgba * pixelBuffer;
try{
Imf::RgbaInputFile in("0_175.exr");
Imath::Box2i win = in.dataWindow();

Imath::V2i dim(win.max.x - win.min.x + 1, win.max.y - win.min.y + 1);
pixelBuffer = new Imf::Rgba[dim.x * dim.y];

int dx = win.min.x;
int dy = win.min.y;

in.setFrameBuffer(pixelBuffer - dx - dy * dim.x, 1, dim.x);
in.readPixels(win.min.y, win.max.y);
}catch(Iex::BaseExc & e){
std::cerr << e.what() << std::endl;
}

cout<<"Image loaded" <<endl;

glGenTextures(1, &envMapTexture);


glBindTexture (GL_TEXTURE_2D, envMapTexture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, 1024, 1024, 0, GL_RGBA, GL_HALF_FLOAT_ARB, pixelBuffer);
cout << pixelBuffer[546].r << " "<< pixelBuffer[546].g << " "<< pixelBuffer[546].b << endl;

setEnvmapParam(envMapTexture);
}


void setEnvmapParam(GLuint obj){
cgGLSetTextureParameter(cg_envmap, obj);
cgGLEnableTextureParameter(cg_envmap);
cout << "envmap loaded" << endl;
}


and then the shader


void FragmentProgram(
float4 position : TEXCOORD0,
float4 iPosition : TEXCOORD1,
float3 normal : TEXCOORD2,
float3 view : TEXCOORD3,
float3 reflect : TEXCOORD4,

out float4 color : COLOR,

uniform sampler2D envmap )
{


//Compute the angles based on the

float phiOut = atan2(view.y, view.x);
float thetaOut = acos(view.z/pow((pow(view.x,2)+pow(view.y,2)+pow(view.z,2)),1/2));


float2 coords = (0.5, 0.5);
float4 test = tex2D(envmap,coords);

if(test.x > 0){
color.x = 1;
color.y = 0;
color.z = 0;
}
if(test.y > 0 ){
color.x = 0;
color.y = 1;
color.z = 0;
}
if(test.z > 0 ){
color.x = 0;
color.y = 0;
color.z = 1;
}
}



so I did some tests on 'test', tried using it as the color. But it just gives 0 all the time. But in that pixelbuffer I do get the correct values. So or my texture doesn't get into the shader, or the data doesn't get into the texture.

If I test on test.z or y or x equal to 0 I get an object that flashes from green to blue which is completely weird cause it should be completely independent of how I turn the teapot.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!