Hi!
A tried to make a motion blur-like effect and i decided to do this by drawing the scene to the color buffer then copying the content of the color buffer to a texture and finally switching to ortho mode and draw a quad that is textured with the texture and has a blending effect. But I have a problem: whenever i try to copy the content of the color buffer to the texture it does nothing, the texture stays completely black. I tried to play with the pixel storing modes and etc… but nothing helped.
Here are quotes form da source code (Delphi):
initializing gl:
ZeroMemory(@pfd, sizeof(pfd));
pfd.nSize := sizeof(pfd);
pfd.nVersion := 1;
pfd.dwFlags := PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
or PFD_GENERIC_ACCELERATED;
pfd.iPixelType := PFD_TYPE_RGBA;
pfd.cColorBits := 32;
pfd.cDepthBits := 16;
pfd.iLayerType := PFD_MAIN_PLANE;
iFormat := ChoosePixelFormat(dc, @pfd);
SetPixelFormat(dc, iFormat, @pfd);
rc := wglCreateContext( dc );
wglMakeCurrent(dc,rc);
glShadeModel(GL_SMOOTH);
glClearColor(0.0, 0.0, 0.0, 1.0);
glClearDepth(1.0); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_TEXTURE_2D);
CreateBlurTexture;
The createblurtexture procedure makes the texture where the color buffer is copied @ everyframe to.
procedure CreateBlurTexture;
var pData: Pointer;
begin
GetMem(pData, 256*256*3);
glGenTextures(1, g_game.BlurTex);
glPixelstorei(GL_UNPACK_ALIGNMENT,3);
glBindTexture(GL_TEXTURE_2D, g_game.BlurTex);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, pData);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
FreeMem(pData);
end;
and here is the rendering procedure:
begin
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
frm_game.FormResize(frm_game);
glTranslatef(0.0,0.0,-8.0);
glBegin(GL_QUADS);
glColor3f(1.0,0.0,0.0);
glNormal3f( 0.0, 0.0, 1.0);
glVertex2f(labda.x-labda.w/2,labda.y+labda.h/2);
glVertex2f(labda.x+labda.w/2,labda.y+labda.h/2);
glVertex2f(labda.x+labda.w/2,labda.y-labda.h/2);
glVertex2f(labda.x-labda.w/2,labda.y-labda.h/2);
glColor3f(1.0,1.0,1.0);
glNormal3f( 0.0, 0.0, 1.0);
glVertex2f(uto1.x-uto1.w/2,uto1.y+uto1.h/2);
glVertex2f(uto1.x+uto1.w/2,uto1.y+uto1.h/2);
glVertex2f(uto1.x+uto1.w/2,uto1.y-uto1.h/2);
glVertex2f(uto1.x-uto1.w/2,uto1.y-uto1.h/2);
glNormal3f( 0.0, 0.0, 1.0);
glVertex2f(uto2.x-uto1.w/2,uto2.y+uto2.h/2);
glVertex2f(uto2.x+uto1.w/2,uto2.y+uto2.h/2);
glVertex2f(uto2.x+uto1.w/2,uto2.y-uto2.h/2);
glVertex2f(uto2.x-uto1.w/2,uto2.y-uto2.h/2);
glEnd;
glBindTexture(GL_TEXTURE_2D,BlurTex);
glCopyTexSubImage2D(GL_TEXTURE_2D,0,0,0,0,0,255,255);
// Motion Blur code
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,1.0,0,1.0,-1,1);
// glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_DEPTH_TEST);
// glEnable(GL_BLEND);
glBindTexture(GL_TEXTURE_2D,BlurTex);
glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);
glTexCoord2f(1,0);
glVertex2f(0.5,0);
glTexCoord2f(1,1);
glVertex2f(0.5,0.5);
glTexCoord2f(0,1);
glVertex2f(0,0.5);
glEnd();
{ }
SwapBuffers(dc);
// glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
end;
And sorry for my english. I’m looking forward to reading your replies!