Disappearing displayed image from screen

I try to implement real time transfunction operation; in that,
whenever user modifies transfer curve on screen, according to the modification, the displayed image is modified at the same time.

Firstly, I tested my program using small color image under not real time condition; in that, only if user release its mouse movement, this function is executed. At this time, this is working very well.

However, in the real time operation, it gives wrong value and even the image is disappeared at some point even though RGB values are not all zero(black).

I know I might make a really trivial but very important mistake. Can anybody give me any advice or suggestion? I attach part of my code.


void DisplayWindow::TransEdit()
{
	//backupToFBO();

	//0. setting parameter
	float ColorFlag[4] = {0.0, 0.0, 0.0, 0.0};
	if( selectedColor == 'r' ) ColorFlag[0] = 1.0;
	else if( selectedColor == 'g' ) ColorFlag[1] = 1.0;
	else if( selectedColor == 'b' ) ColorFlag[2] = 1.0;

	//copy data to texture.
	int num;
	for(int i = 0; i < 256; i++) {
		num = transFunc[0][i];
		*(imgpixTrans + i) = (GLubyte) num;
	}

	//1. display on the frame buffer
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);

	//one-to-one mapping from array index to texture coordinates
	glMatrixMode(GL_PROJECTION); 
    glLoadIdentity(); 
    gluOrtho2D(0.0, imgx, 0.0, imgy); 
    glMatrixMode(GL_MODELVIEW); 
    glLoadIdentity(); 
    glViewport(0, 0, imgx, imgy); 

	//2. setting input texture(s)
	cgGLSetTextureParameter(originalParam, inputID);
	cgGLEnableTextureParameter(originalParam);

	glBindTexture(GL_TEXTURE_1D, transID);
	glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 256, GL_ALPHA, GL_UNSIGNED_BYTE, imgpixTrans); 
	cgGLSetTextureParameter(transcurve, transID);
	cgGLEnableTextureParameter(transcurve);

	//3. setting output texture(s)
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_NV, tempID, 0);
	glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
	
	//4. Bind fragment program: ready to use
	cgGLBindProgram(TransProgram);
	
	//5. give the argument to the fragment program 
	cgSetParameter4f(flag, ColorFlag[0], ColorFlag[1], ColorFlag[2], ColorFlag[3]); 

	//6. enable fragment program
	cgGLEnableProfile(fProfile);
	checkForCgError();
	
	//7. render geometry
	renderFBO();

	//8. finish
	cgGLDisableProfile(fProfile);

	//9. GPU texture -> CPU arrays
   	glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
	glReadPixels(0, 0, imgx, imgy, GL_RGBA, GL_UNSIGNED_BYTE, imgpixTemp);

	//10. discard alpha in the array
	Discard(imgpix, imgpixTemp);

	//11. CPU array -> GPU texture
	glBindTexture(GL_TEXTURE_RECTANGLE_NV, inputID);
	glTexSubImage2D(GL_TEXTURE_RECTANGLE_NV, 0, 0, 0, imgx, imgy, GL_RGB, GL_UNSIGNED_BYTE, imgpix);

	//12. unbind frame buffer
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
	
	//13. update histogram and image
	rgb2hsv();
	gui->app->updateHistogramRGB(imgpix);
	gui->app->updateHistogramHSV(imgpixHSV);
	gui->app->Normalizing();
	
	gui->displayWindow->redraw();
	//gui->transFuncEditor->redraw();
}