VividGL 2D_Example 3

Miscellaneous Forums/Blitz Showcase/VividGL 2D_Example 3

Shall be releasing the first 3d demo tonight or tomorrow hopefully, however, in the meantime here is the 3rd 2d demo.

http://www.excess.eclipse.co.uk/2D_Example3.rar (2.7mb)

This one shows off a variety of things,

1. Pixel shader 2.0 fx again.(The logos shimmer.)

2.Vivid's (C++ wrote) particle system. Despite being 3d, it works fine in 2d(Has a seperate 2d renderer)..when using it in 2d, Z = the particles size. Used to render flaming stars with vapour trails.

3.Using direct (Not wrapped) openGL code natively within a vivid product. (Not that you ever have to, this is just an example of how easy it is to acctually write plugins for the 3d/2d engine.

The gl portion renders the starfield.



Also, there's a hidden 'cheat' that lets you specify how many stars to render. I'll give you a clue..it happens at start up, or not at all.

Also, since we last meet the Texture engine has been rewrote from the ground up in C++(Overdue.) and now much like b3d, uses freeimage to load media...so any problems in that area.

As always, please report any bugs, performance issues etc, and I'll do my best to fix them before release.



Here's the blitz source

Include "Includes\VividGL_Lite.bb"
Graphics_Init(640,480,32,2)
glSetbuffer Graphics_Back()

Global NumStars= 1100

Global starTex=Texture_Load("Media\smoke1.png")
Texture_Blend starTex,2
If starTex=0 End

Global StarParticle=CreateParticle( starTex) 
Particle_SetAlpha StarParticle,1,0.02
Particle_SetWeight starParticle,0

Const logos=2
Local Logo[logos+5]
For j=1 To logos
	logo[j]=Texture_Load("Media\logo"+j+".jpg")
	Texture_Blend logo[j],2
Next

blurSkin=Skin_BlurTexture()
Whoosh=LoadSound("Dat\move1.wav")
FadeIn=LoadSound("Dat\FadeIn1.Wav")
blurFactor#=0.3
SoundPitch(fadeIn),12000
PlaySound(FadeIn)
InitStars() ;-Demo function, not a part of vivid. See below.
cLogo=2
While Not KeyDown(1)
	glCls(False)
	
	If KeyDown(2) blurFactor=0.5
	skin_blurFactor(blurSkin,blurfactor)
	blurFactor#=blurFactor*0.975
	If blurFactor#<0.001 And slideOut=0
		Chan=PlaySound( Whoosh)
		SlideOut=True
	EndIf
	If SlideOut
		logoX=logoX+16
		blurFactor=blurFactor*1.01
		If logoX>1000
			logoX=0
			PlaySound(FadeIn)
			slideOut=0
			blurFactor=0.3
			cLogo=cLogo-1
			If cLogo<1 cLogo=2
		EndIf
	EndIf
	Particle_Update()
		lock2d()
			Render_Particle2D()
			demo_Stars()
		unlock2d()
		
            lock2D()
		      FxSkinOn(blurSkin)
 	  		Texture_Activate logo[clogo],0
				Cls_Z()
				Render_Begin()
						Render_QuadFast(320-160+LogoX-LogoAd,240-80-LogoAd,320+LogoAd*2,160+LogoAd*2)
				Render_End()
				FxSkinOff()
		Unlock2D()
	glText 1,1,"Move mouse Left/Right to change blur factor"
	glFlip(False)
Wend


;--[ Star Lib]-[ Demo Code Only.]

Const Star_X=1,Star_Y=2,Star_Z=3
Dim star#(NumStars+100,8)
Global starTo,starFrame

Function initStars()
	Dim star#(NumStars+100,7)
	For j=1 To numStars
		star(j,1)=Rnd(-0.5,1)
		star(j,2)=Rnd(0.5,1)
		If Rand(3)=1
			star(j,1)=-star(j,1)
		EndIf
		If Rand(3)=1
			star(j,2)=-star(j,2)
		EndIf 
		star(j,3)=Rnd(0,0.01)
		star(j,4)=320
		star(j,5)=240
		If Rand(400)=1
			star(j,6)=1
		EndIf
	Next
	starTo=numStars
	starFrame=4
End Function
Const zAmp# = 255*256
Global camp#,camt#,camr#
Function Demo_Stars() ;Demonstrates how you can blend pure native gl code with vivid seemlessly.
glPushMatrix()
glLoadIdentity()
Local starPos=CreateBank(128*4)
glBegin(GL_LINES)
		For j=1 To NumStars
				dx#=320+star(j,1)*star(j,3)
				dy#=(240+star(j,2)*star(j,3))
				cv#=star(j,3)/255
				cv=cv*0.2
				If cv<0 cv=0
				If cv>1 cv=1
					
				glColor4f cv,cv,cv,1
				If star(j,6)=0
				glVertex2f dx,dy
				glColor4f cv/3,cv/3,cv/3,1
				glVertex2f star(j,4)+(star(j,4)-dx)*8,star(j,5)+(star(j,5)-dy)*8
				Else
					emitParticle( starParticle,dx,dy,star(j,3)*0.15,Rnd(-0.4,0.4),Rnd(-0.4,0.4),Rnd(-1,1)) 
				EndIf
				star(j,4)=dx
				star(j,5)=dy
				star(j,3)=star(j,3)+8
				If dx<0 Or dx>640 Or dy<0 Or dy>480
	                  	star(j,1)=Rnd(-1,1)
		                  star(j,2)=Rnd(-1,1)
				      star(j,3)=0.01
					star(j,4)=320;star(j,1)
					star(j,5)=240;star(j,2)
				EndIf
		Next
glEnd()
glPopMatrix()
Return 
End Function