Sign in to follow this  

Updating the screen + reading a mipmap level

This topic is 3658 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

So I have 2 problems a) This is my display code
void display()
{
//Basic rendering to FBO 1
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	gluLookAt(d*sqrt3,d*sqrt3,d*sqrt3,
		0.0,0.0,0.0,
		0.0,1.0,0.0);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[0].fbobj);

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	glEnable(GL_DEPTH_TEST);

	bindCgPrograms();

	glPushMatrix();
	glRotatef(angle,0.0,1.0,0.0);
	glutSolidTeapot(1.0);
	glPopMatrix();

	unBindCgPrograms();

	glDisable(GL_DEPTH);

//Postprocessing
	std::cout<<"START POSTPROCESSING"<<std::endl;
	glColor3f(1, 1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glActiveTexture(GL_TEXTURE0);
	glEnable(GL_TEXTURE_2D);

	//Calculate average Luminance
		float* data = (float*)malloc(fbo_width*fbo_height*sizeof(float));
		//glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
		glReadPixels(0,0,fbo_width,fbo_height,GL_LUMINANCE,GL_FLOAT,data);
		int j =0;
		std::cout<<j<<std::endl;
		float subtotal = 0;
		float delta = 0.001;
		int t = 0;
		for(int i=0; i<fbo_height*fbo_width; i++){
			if(data[i] >= 0){
				subtotal += log(delta + data[i]);
			}
		}
		avg_luminance = exp(subtotal/(fbo_width*fbo_height));
		std::cout<<"subtotal "<<subtotal<<std::endl;
		std::cout<<"avg luminance"<<avg_luminance<<std::endl;

	//Render to FBO 2
	glBindTexture(GL_TEXTURE_2D,fb[0].texobj);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb[1].fbobj);
	setTonemapParam(fb[0].texobj, avg_luminance);
	bindTonemapCgPrograms();
	DrawFullScreenQuad(fbo_width, fbo_height);

	//Render to screen
	glBindTexture(GL_TEXTURE_2D, fb[1].texobj);
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	DrawFullScreenQuad(fbo_width, fbo_height);

	glDisable(GL_TEXTURE_2D);
	glPopMatrix();

	std::cout<<"angle "<<angle<<std::endl;
	glutSwapBuffers();
}

I've tried glFinish and glFlush, alone or combined with swapbuffers but in thoese cases it doesn't draw to the screen at all and in the code above it updates at least into FBO 1 when I use my keyinputs which change the angle variable. (I see that the luminance changes and all that) But it doesn't update on the screen. I'm guessing I have to set some buffer to active or so but I have no idea how. Second question, I autogenerated mipmap levels for my texture and now I want to give the 1x1 map to my shader. How can I adress that level in the cgSetParameter command?

Share this post


Link to post
Share on other sites
I guess you are rendering to the FBO and then using glReadPixels to readback.
No need for glFlush, glFinish and FBO are single buffer so don't call SwapBuffers.

Maybe you just need to call glViewport since your FBO might be different in size. Not sure.

Share this post


Link to post
Share on other sites
no, no

I render to FBO 1, then read back from it (which can be done better I know) and then use that info to render to FBO 2 after which I render to the screen.

edit : I added the glViewport stuff like in the FBO 101 tutorial on this site. No result. Only with glutSwapBuffers I actually get something on the screen :/

[Edited by - Zarathustra on December 6, 2007 5:52:52 PM]

Share this post


Link to post
Share on other sites

This topic is 3658 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this