Post by Motionblur TutorialDemo on May 9, 2004 20:18:15 GMT -5
Hey guys, this is my first program in Basic4GL. It's not really a tutorial, but every line of code is annotated.
Hope you enjoy it, again this is my *first* Basic4GL program, and the first time i have ever used OpenGL, so it's not optimised at all. I get about 30-45 fps on my Centrino 1.3Ghz with an Intel 855GM onboard 64 meg card.
-[glow=red,2,300]Redshift[/glow]
dim x#,y#,cloop,rot#,blur#,speed#,i,a$,b$,texture : a$ = "Motionblur Tut#1":b$ = "By Redshift":i = 100:cloop = 5
glBlendFunc(GL_SRC_ALPHA,GL_ONE) 'Set the blending function for translucency
glEnable (GL_BLEND) 'Enable blending
TextMode (TEXT_OVERLAID) 'This text mode required for motion blur and OpenGL.
texture = LoadTexture ("data\charset2.png") 'Load the font image.
Font (texture) 'Set the image to be used.
while i >= 8 'Beginning of the intro.
ResizeText (i * 2 + 1, i + 1) 'Change the font size on the fly.
Locate (TextCols() - Len(a$)) / 2, TextRows() / 2 'Keep the text centered.
Color(255-cloop,0,cloop) 'Change color from blue to red on the fly.
Print a$ 'Print text to memory.
Locate (TextCols() - Len(a$)) / 2, (TextRows() / 2)+1 'Keep the text centered.
Color(cloop,0,255-cloop) 'Change color from blue to red on the fly.
Print b$ 'Print text to memory.
Drawtext() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
Sleep (25) '25 millisecond delay to slow text down.
cloop = cloop + 4 'Increment "cloop" for color cycling.
i = i - 2 'Increment "i" for text resizing.
wend 'End of moving text loop.
glclear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT):cls 'Clear the screen.
Locate (TextCols() - Len(a$)) / 2, TextRows() / 2 'Keep the text centered.
Print a$ 'Print text to memory.
Locate (TextCols() - Len(a$)) / 2, (TextRows() / 2)+1 'Keep the text centered.
Color(255-cloop,0,cloop) 'Use the same color as at the end of the moving text loop.
Print b$ 'Print text to memory.
Drawtext() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
sleep (1500) 'Wait 1.5 seconds.
ResizeText (40,25) 'Size the text to a usable size.
speed# = 70 'Set the initial speed value.
blur# = 0.30 'Set the initial "blur"value.
while true 'Main demo loop.
glclear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT):cls 'Clear text and graphics.
TextMode (TEXT_OVERLAID) 'Required to use OpenGL and text at the same time.
Color(255,255,255) 'White text.
locate 0,0: printr "_/]|[\_Motionblur Tut By:Redshift_/]|[\_": printr "Up / Down = Blur length":printr "Left / Right = Rotation speed"
locate 0,4: print "ESC to quit": 'Above line and next 2 lines: Text overlay.
locate 0,23:printr "Blur: "+(blur#*100)+"%": print "Speed:"+((speed#-100)*-1)
rot# = rot#- (blur#*speed#) 'This line is used to keep the blur sensible for the speed.
for x# = 1 to 100 'Draw 100 "samples" for motion blur.
glLoadIdentity() 'the blur amount is changed.
glTranslatef(0,0,-4): glRotatef(rot#,0,0,1) 'Move the pointer back 4 and begin rotation.
glbegin(GL_QUADS) 'Prepare for a square.
y# = x#*.08 'This whole loop draws 100 quads, slighty
glColor4ub(255,255,255,y#): glvertex2f(-1, 1) 'rotated apart. The alpha starts at transparent
glColor4ub( 0, 0,255,y#): glvertex2f( 1, 1) 'and gradually fades to the opaque color set by
glColor4ub( 0,255, 0,y#): glvertex2f( 1,-1) 'the glColor command for each vertex.
glColor4ub(255, 0, 0,y#): glvertex2f(-1,-1) 'This makes up one motion blurred "frame".
glEnd() 'End of square.
rot# = rot# + blur# 'Scale the rotation to match the blur amount.
next 'Draw the next "sample" for the motion blur.
if ScanKeyDown (VK_LEFT) then speed# = speed# - 2 : endif :if speed# < 0 then speed# = 0 endif
if ScanKeyDown (VK_RIGHT) then speed# = speed# + 2 : endif :if speed# > 100 then speed# = 100 endif
if ScanKeyDown (VK_DOWN) then blur# = blur# - 0.02: endif :if blur# < 0.05 then blur# = 0.05 endif
if ScanKeyDown (VK_UP) then blur# = blur# + 0.02: endif :if blur# > 1 then blur# = 1 endif
DrawText() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
wend 'Do the next frame of the animation.
Hope you enjoy it, again this is my *first* Basic4GL program, and the first time i have ever used OpenGL, so it's not optimised at all. I get about 30-45 fps on my Centrino 1.3Ghz with an Intel 855GM onboard 64 meg card.
-[glow=red,2,300]Redshift[/glow]
dim x#,y#,cloop,rot#,blur#,speed#,i,a$,b$,texture : a$ = "Motionblur Tut#1":b$ = "By Redshift":i = 100:cloop = 5
glBlendFunc(GL_SRC_ALPHA,GL_ONE) 'Set the blending function for translucency
glEnable (GL_BLEND) 'Enable blending
TextMode (TEXT_OVERLAID) 'This text mode required for motion blur and OpenGL.
texture = LoadTexture ("data\charset2.png") 'Load the font image.
Font (texture) 'Set the image to be used.
while i >= 8 'Beginning of the intro.
ResizeText (i * 2 + 1, i + 1) 'Change the font size on the fly.
Locate (TextCols() - Len(a$)) / 2, TextRows() / 2 'Keep the text centered.
Color(255-cloop,0,cloop) 'Change color from blue to red on the fly.
Print a$ 'Print text to memory.
Locate (TextCols() - Len(a$)) / 2, (TextRows() / 2)+1 'Keep the text centered.
Color(cloop,0,255-cloop) 'Change color from blue to red on the fly.
Print b$ 'Print text to memory.
Drawtext() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
Sleep (25) '25 millisecond delay to slow text down.
cloop = cloop + 4 'Increment "cloop" for color cycling.
i = i - 2 'Increment "i" for text resizing.
wend 'End of moving text loop.
glclear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT):cls 'Clear the screen.
Locate (TextCols() - Len(a$)) / 2, TextRows() / 2 'Keep the text centered.
Print a$ 'Print text to memory.
Locate (TextCols() - Len(a$)) / 2, (TextRows() / 2)+1 'Keep the text centered.
Color(255-cloop,0,cloop) 'Use the same color as at the end of the moving text loop.
Print b$ 'Print text to memory.
Drawtext() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
sleep (1500) 'Wait 1.5 seconds.
ResizeText (40,25) 'Size the text to a usable size.
speed# = 70 'Set the initial speed value.
blur# = 0.30 'Set the initial "blur"value.
while true 'Main demo loop.
glclear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT):cls 'Clear text and graphics.
TextMode (TEXT_OVERLAID) 'Required to use OpenGL and text at the same time.
Color(255,255,255) 'White text.
locate 0,0: printr "_/]|[\_Motionblur Tut By:Redshift_/]|[\_": printr "Up / Down = Blur length":printr "Left / Right = Rotation speed"
locate 0,4: print "ESC to quit": 'Above line and next 2 lines: Text overlay.
locate 0,23:printr "Blur: "+(blur#*100)+"%": print "Speed:"+((speed#-100)*-1)
rot# = rot#- (blur#*speed#) 'This line is used to keep the blur sensible for the speed.
for x# = 1 to 100 'Draw 100 "samples" for motion blur.
glLoadIdentity() 'the blur amount is changed.
glTranslatef(0,0,-4): glRotatef(rot#,0,0,1) 'Move the pointer back 4 and begin rotation.
glbegin(GL_QUADS) 'Prepare for a square.
y# = x#*.08 'This whole loop draws 100 quads, slighty
glColor4ub(255,255,255,y#): glvertex2f(-1, 1) 'rotated apart. The alpha starts at transparent
glColor4ub( 0, 0,255,y#): glvertex2f( 1, 1) 'and gradually fades to the opaque color set by
glColor4ub( 0,255, 0,y#): glvertex2f( 1,-1) 'the glColor command for each vertex.
glColor4ub(255, 0, 0,y#): glvertex2f(-1,-1) 'This makes up one motion blurred "frame".
glEnd() 'End of square.
rot# = rot# + blur# 'Scale the rotation to match the blur amount.
next 'Draw the next "sample" for the motion blur.
if ScanKeyDown (VK_LEFT) then speed# = speed# - 2 : endif :if speed# < 0 then speed# = 0 endif
if ScanKeyDown (VK_RIGHT) then speed# = speed# + 2 : endif :if speed# > 100 then speed# = 100 endif
if ScanKeyDown (VK_DOWN) then blur# = blur# - 0.02: endif :if blur# < 0.05 then blur# = 0.05 endif
if ScanKeyDown (VK_UP) then blur# = blur# + 0.02: endif :if blur# > 1 then blur# = 1 endif
DrawText() 'Draw the text to the OpenGL buffer.
SwapBuffers() 'Draw the OpenGL buffer to the screen.
wend 'Do the next frame of the animation.