I have created a texture with the dimensions 512x512x3 (GL_RGB) with the purpose to do motion blur. The ideea was to render the previous scene with a lower alpha onto the same texture + the actual scene. It actualy worked, but my implementation has limits : whem I am in full screen (under win32) the motion blur is not working, the alpha it’s not used, a scene is drawed over another one witha alpha 1.0f. Can anybody tell me why?
Here is a bit of my code (the motion blur rendering to a txture routine) :
void RenderToMotionBlurTexture(bool FirstRenderTexture, int SceneFunc()) {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
glViewport(0, 0, motionBlur_Texture_X, motionBlur_Texture_Y);
if(FirstRenderTexture)
SceneFunc();
// render the old texture
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glColor4f(motionBlur_Red_intensity,
motionBlur_Green_intensity,
motionBlur_Blue_intensity,
motionBlur_Alpha_intensity);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
// put the texture on the screen
glBindTexture(GL_TEXTURE_2D, motionBlur_Texture);
// go to orthogonal view
glLoadIdentity();
glOrtho( 0, motionBlur_Texture_X, motionBlur_Texture_Y, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glTexCoord2f(0.0, 1.0); glVertex2f(0, 0);
glTexCoord2f(0.0, 0.0); glVertex2f(0, motionBlur_Texture_Y);
glTexCoord2f(1.0, 0.0); glVertex2f(motionBlur_Texture_X, motionBlur_Texture_Y);
glTexCoord2f(1.0, 1.0); glVertex2f(motionBlur_Texture_X, 0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_DEPTH_TEST);
glDisable(GL_BLEND);
glPopMatrix();
if(!FirstRenderTexture)
SceneFunc();
glBindTexture(GL_TEXTURE_2D, motionBlur_Texture);
glCopyTexImage2D(GL_TEXTURE_2D, 0, motionBlur_Texture_type, 0, 0,
motionBlur_Texture_X, motionBlur_Texture_Y, 0);
glViewport(0, 0, windowX, windowY);
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
}
void ShowMotionBlurTexture() {
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity();
// put the texture on the screen
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, motionBlur_Texture);
// go to orthogonal view
glLoadIdentity();
glOrtho(0, windowX, windowY, 0, 0, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex2f(0, 0);
glTexCoord2f(0.0, 0.0); glVertex2f(0, windowY);
glTexCoord2f(1.0, 0.0); glVertex2f(windowX, windowY);
glTexCoord2f(1.0, 1.0); glVertex2f(windowX, 0);
glEnd();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
Am I doing something wrong? Its from my video card? Where is the problem?