Post by davy on Aug 7, 2006 1:31:50 GMT -5
The concept behind this is simple.... You need to capture the screen with the graphics drawn... Then you impose that image over the scene. If all goes well, you should have the EXACT image in the scene, drawn over the scene itself!!! Now, the next time around, we capture the scene WITH the image imposed the last time around... The effect is recursive, like facing two mirrors towards eachother and sticking your head in the middle. Then, you just have to blend the imposed screen capture over it a little darker then the original image (otherwise it would just stay on the screen and never fade out). Anyway... Here's how its done:
Think about the potential in particle systems and things like lightsabers... Slowmotion scenes... Ect... This can even be applied to a 2d scene too, for some truly amazing 2d graphics.
dim Position#(2)
dim Angle#(1)
dim Texture
dim Texture2
'Load textures, the texture we load to "Texture"
'is just a dummy texture to set this variable as a texture
glBlendfunc(GL_ONE, GL_ONE)
glEnable(GL_TEXTURE_2D)
Texture=LoadTexture("Textures\t006.jpg")
Texture2=LoadTexture("Textures\Water.bmp")
'Clear the dummy texture by rendering an untouched screen
glBindTexture(GL_TEXTURE_2D, Texture)
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_Luminance, 0, 0, 128, 128, 0)
do
'PreRender scene to textute...
glViewPort(0,0, 128, 128)
Gosub RenderScene
glBindTexture(GL_TEXTURE_2D, Texture)
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 128, 128, 0)
'Render final, viewable scene...
glViewPort(0,0,WindowWidth(),WindowHeight())
Gosub RenderScene
SwapBuffers()
'Rotate cube...
if ScanKeyDown(VK_RIGHT) then Position#(0)=Position#(0)+.02 Endif
if ScanKeyDown(VK_LEFT) then Position#(0)=Position#(0)-.02 Endif
if ScanKeyDown(VK_UP) then Position#(1)=Position#(1)+.02 Endif
if ScanKeyDown(VK_DOWN) then Position#(1)=Position#(1)-.02 Endif
if ScanKeyDown(VK_SPACE) then Angle#(1)=Angle#(1)-1 Endif
if ScanKeyDown(VK_RETURN) then Angle#(0)=Angle#(0)-1 Endif
loop
RenderScene:
glClear(GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT)
glLoadIdentity()
glPushMatrix()
glDisable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glBindTexture(GL_TEXTURE_2D, Texture)
glBegin(GL_QUADS)
glColor3f(.4, .4, .4)
glTexCoord2f(0,0): glVertex3f(-WindowWidth()/830.0,-WindowHeight()/830.0, -1)
glTexCoord2f(1,0): glVertex3f( WindowWidth()/830.0,-WindowHeight()/830.0, -1)
glTexCoord2f(1,1): glVertex3f( WindowWidth()/830.0, WindowHeight()/830.0, -1)
glTexCoord2f(0,1): glVertex3f(-WindowWidth()/830.0, WindowHeight()/830.0, -1)
glEnd()
glDisable(GL_BLEND)
glEnable(GL_DEPTH_TEST)
glPopMatrix()
glPushMatrix()
glTranslatef(Position#(0),Position#(1),-3)
glRotatef(Angle#(0), 1, 0, 0)
glRotatef(Angle#(1), 0, 1, 0)
glBindTexture(GL_TEXTURE_2D, Texture2)
GlBegin(GL_QUADS)
glColor3f(1,1,1)
glTexCoord2f(0.0, 0.0): glVertex3f(-0.5, -0.5, 0.5)
glTexCoord2f(1.0, 0.0): glVertex3f( 0.5, -0.5, 0.5)
glTexCoord2f(1.0, 1.0): glVertex3f( 0.5, 0.5, 0.5)
glTexCoord2f(0.0, 1.0): glVertex3f(-0.5, 0.5, 0.5)
glTexCoord2f(1.0, 0.0): glVertex3f(-0.5, -0.5, -0.5)
glTexCoord2f(1.0, 1.0): glVertex3f(-0.5, 0.5, -0.5)
glTexCoord2f(0.0, 1.0): glVertex3f( 0.5, 0.5, -0.5)
glTexCoord2f(0.0, 0.0): glVertex3f( 0.5, -0.5, -0.5)
glTexCoord2f(0.0, 1.0): glVertex3f(-0.5, 0.5, -0.5)
glTexCoord2f(0.0, 0.0): glVertex3f(-0.5, 0.5, 0.5)
glTexCoord2f(1.0, 0.0): glVertex3f( 0.5, 0.5, 0.5)
glTexCoord2f(1.0, 1.0): glVertex3f( 0.5, 0.5, -0.5)
glTexCoord2f(1.0, 1.0): glVertex3f(-0.5, -0.5, -0.5)
glTexCoord2f(0.0, 1.0): glVertex3f( 0.5, -0.5, -0.5)
glTexCoord2f(0.0, 0.0): glVertex3f( 0.5, -0.5, 0.5)
glTexCoord2f(1.0, 0.0): glVertex3f(-0.5, -0.5, 0.5)
glTexCoord2f(1.0, 0.0): glVertex3f( 0.5, -0.5, -0.5)
glTexCoord2f(1.0, 1.0): glVertex3f( 0.5, 0.5, -0.5)
glTexCoord2f(0.0, 1.0): glVertex3f( 0.5, 0.5, 0.5)
glTexCoord2f(0.0, 0.0): glVertex3f( 0.5, -0.5, 0.5)
glTexCoord2f(0.0, 0.0): glVertex3f(-0.5, -0.5, -0.5)
glTexCoord2f(1.0, 0.0): glVertex3f(-0.5, -0.5, 0.5)
glTexCoord2f(1.0, 1.0): glVertex3f(-0.5, 0.5, 0.5)
glTexCoord2f(0.0, 1.0): glVertex3f(-0.5, 0.5, -0.5)
glEnd()
glPopMatrix()
glPushMatrix()
glDisable(GL_DEPTH_TEST)
glEnable(GL_BLEND)
glBindTexture(GL_TEXTURE_2D, Texture)
glBegin(GL_QUADS)
glColor3f(.5, .5, .5)
glTexCoord2f(0,0): glVertex3f(-WindowWidth()/830.0,-WindowHeight()/830.0, -1)
glTexCoord2f(1,0): glVertex3f( WindowWidth()/830.0,-WindowHeight()/830.0, -1)
glTexCoord2f(1,1): glVertex3f( WindowWidth()/830.0, WindowHeight()/830.0, -1)
glTexCoord2f(0,1): glVertex3f(-WindowWidth()/830.0, WindowHeight()/830.0, -1)
glEnd()
glDisable(GL_BLEND)
glEnable(GL_DEPTH_TEST)
glPopMatrix()
Return
Think about the potential in particle systems and things like lightsabers... Slowmotion scenes... Ect... This can even be applied to a 2d scene too, for some truly amazing 2d graphics.