Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Emil_halim on March 05, 2007
-
Hi all
After i have seen the Deviance.exe of alpha one , shocky was posting it in this forum , i liked the 3D text scrolling.
so i have changed the prophecy to be a 3D spiral text scrolling. this is the first step to port his demo.
download it here
prophecy2.zip (http://bcxdx.spoilerspace.com/FreeBasic/prophecy2.zip)
here is the screen shot
(http://bcxdx.spoilerspace.com/FreeBasic/prophecy2.gif)
here is the source code
''----------------------------------------------------------------------------------
''
'' Magic Library For Ogre
'' beta version 0.40
'' by Emil Halim
''
'' Name : prophecy2Demo
'' Date : 20/02/2007
'' Purpose : ported from Amiga demos
'' to FreeBasic by Emil Halim.
''
'' website : http://www.freewebs.com/ogremagic/index.htm
''
'' Amiga : http://www.flashtro.com/list.php?c=art&s=title&w=asc&o=&p=&d=250
''
''-----------------------------------------------------------------------------------
OPTION EXPLICIT
#include once "windows.bi"
#include once "win/d3d9.bi"
#include once "win/d3dx9.bi"
#include once "staticMagicLibrary.bi"
''-----------------------------------------------------------------------------
'' GLOBALS
''-----------------------------------------------------------------------------
dim shared as HWND g_hWnd = NULL
dim shared as LPDIRECT3D9 g_pD3D = NULL
dim shared as LPDIRECT3DDEVICE9 g_pd3dDevice = NULL
dim shared as SpriteData ptr Prophecy
dim shared as SpriteData ptr bob
dim shared as SpriteData ptr Copper
dim shared as SpriteData ptr CLine
dim shared as HLSLProgramData ptr LineProgram
dim shared as HLSLProgramData ptr CopperProgram
dim shared as ScreenSurfaceData ptr Scren
dim shared as BitmapFontData ptr font
'/ star field
#define StarCount 700
#define SCREEN_WIDTH 640
#define SCREEN_HEIGHT 420
#define Speed 0.3
#define NoOfLayers 3
type STAR
as single x
as single y
end type
dim shared as STAR Stars(0 to StarCount)
dim shared as string Msg
dim shared as integer MsgLen
dim shared as MusicSoundData ptr song
''-----------------------------------------------------------------------------
'' PROTOTYPES
''-----------------------------------------------------------------------------
declare function WindowProc( byval hWnd as HWND, byval msg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULT
declare sub init()
declare sub shutDown()
declare sub render()
''-----------------------------------------------------------------------------
'' Name: init()
'' Desc: Initializes Direct3D under DirectX 9.0
''-----------------------------------------------------------------------------
sub init( )
g_pD3D = Direct3DCreate9( D3D_SDK_VERSION )
dim as D3DDISPLAYMODE d3ddm
IDirect3D9_GetAdapterDisplayMode( g_pD3D, D3DADAPTER_DEFAULT, @d3ddm )
dim as D3DPRESENT_PARAMETERS d3dpp
clear( d3dpp, 0, len(d3dpp) )
d3dpp.Windowed = TRUE
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD
d3dpp.BackBufferFormat = d3ddm.Format
d3dpp.EnableAutoDepthStencil = TRUE
d3dpp.AutoDepthStencilFormat = D3DFMT_D16
d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE
IDirect3D9_CreateDevice( g_pD3D, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, g_hWnd, _
D3DCREATE_SOFTWARE_VERTEXPROCESSING, _
@d3dpp, @g_pd3dDevice )
IDirect3DDevice9_SetRenderState(g_pd3dDevice,D3DRS_LIGHTING, FALSE)
IDirect3DDevice9_SetRenderState(g_pd3dDevice,D3DRS_CULLMODE, D3DCULL_NONE)
dim as D3DXMATRIX mProjection
D3DXMatrixPerspectiveFovLH( @mProjection, D3DXToRadian( 45.0f ), 1.0f, 1.0f, 1000.0f )
IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_PROJECTION, @mProjection )
'' Initial Magic Library here
InitialMagicLibrary(g_pd3dDevice,640, 480)
FmodInit()
ML_SetMediaDirectory("../CracktroMedia/")
song = ML_LoadMusicSound("1.mp3")
ML_SetMusicSoundVolume(song,250)
'L_SetSoundFreq(song,10)
Prophecy = ML_LoadStaticSprite("prophecy.bmp")
bob = ML_LoadStaticSprite("bob.bmp")
ML_SetSpriteColorKeyFromPoint(bob,0,0)
Copper = ML_CreateStaticSprite(1,300)
ML_StartDrawingToSprite(Copper)
ML_ClearDrawingArea(&HFF000000)
dim h
for h=0 to 150
ML_WriteRedChannel( 0,h,120+119*sin((300-h)/133.0))
ML_WriteGreenChannel(0,h,120+119*sin((300-h)/73.0 ))
ML_WriteBlueChannel( 0,h,120+119*sin((300-h)/53.0 ))
ML_WriteRedChannel( 0,h+150,120+119*sin((h+150)/133.0))
ML_WriteGreenChannel(0,h+150,120+119*sin((h+150)/73.0 ))
ML_WriteBlueChannel( 0,h+150,120+119*sin((h+150)/53.0 ))
next
ML_StopDrawingToSprite(Copper)
CLine = ML_CreateStaticSprite(640,1)
LineProgram = ML_CreateHLSLProgram()
ML_EditPixelProgram(LineProgram)
ML_AddToProgram("sampler2D tex0; ")
ML_AddToProgram("float S1,S2,S3; ")
ML_AddToProgram("float4 main( float2 TexCoord : TEXCOORD0) : COLOR0 ")
ML_AddToProgram("{ ")
ML_AddToProgram(" float red,grn,blu; ")
ML_AddToProgram(" red = 0.392+ 0.388 * sin(S1+TexCoord.x*4.848484); ")
ML_AddToProgram(" grn = 0.392+ 0.388 * sin(S2+TexCoord.x*3.475524); ")
ML_AddToProgram(" blu = 0.392+ 0.388 * sin(S3+TexCoord.x*5.444444); ")
ML_AddToProgram(" return float4(red,grn,blu,1); ")
ML_AddToProgram("} ")
ML_CompilePixelProgram(LineProgram,"main")
CopperProgram = ML_CreateHLSLProgram()
ML_EditPixelProgram(CopperProgram)
ML_AddToProgram("sampler2D tex0; ")
ML_AddToProgram("sampler2D tex1; ")
ML_AddToProgram("float4 main( float2 TexCoord : TEXCOORD0) : COLOR0 ")
ML_AddToProgram("{ ")
ML_AddToProgram(" float4 col0 = tex2D( tex0, TexCoord); ")
ML_AddToProgram(" float4 col1 = tex2D( tex1, TexCoord); ")
ML_AddToProgram(" return float4(col1.rgb,col0.a); ")
ML_AddToProgram("} ")
ML_CompilePixelProgram(CopperProgram,"main")
Scren = ML_CreateScreenSurface(640, 480)
ML_SetScreenClearColor(0,0,0,0)
ML_SetMediaDirectory("../MagicMedia/")
font = ML_LoadBitmapFont("font/Amigafont.bmp",24,24,22)
ML_SetSpriteColorKeyFromPoint(font,0,0)
ML_SetActiveBitmapFont(font)
randomize (GetTickCount()/1000)
dim i
for i=0 to StarCount-1
reRndX:
Stars(i).x = rnd*(SCREEN_WIDTH)
if(Stars(i).x > SCREEN_WIDTH or Stars(i).x < 0) goto reRndX
reRndY:
Stars(i).y = rnd*(SCREEN_HEIGHT)+150
if(Stars(i).y > SCREEN_HEIGHT or Stars(i).y < 0) goto reRndY
next
Msg = "Welcome Here.... this is a new 2D programming world so you will find that "
Msg += "there are more impressive work that you could produce with this Library..."
Msg += "you could mix 2D with 3D world... playing GIF animation... playing animated Image... "
Msg += "Fading in and out... doing wave Effects... doing 3D star field Effect... scrolling text... "
Msg += "using many fonts... !! please if you found the library is useful for you "
Msg += "so let me know.. see you later.. by..........."
MsgLen = 440
end sub
''-----------------------------------------------------------------------------
'' Name: render()
'' Desc: Render or draw our scene to the monitor.
''-----------------------------------------------------------------------------
sub render( )
IDirect3DDevice9_Clear( g_pd3dDevice, 0, NULL, D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER, _
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f), 1.0f, 0 )
''
'' begin drawing
''
IDirect3DDevice9_BeginScene(g_pd3dDevice)
'' Magic Stuff
''
ML_PlayMusicSound(song)
ML_UseOrthogonalView
ML_SetAlpha(1)
ML_SetColor(255,255,255)
ML_SetBlendMode(ALPHABLEND)
ML_SetScale(2,1.5)
ML_SetSpriteTexture(Prophecy)
ML_DrawSprite(Prophecy,320,60)
ML_SetScale(1,1)
ML_SetSpriteTexture(bob)
dim k,i,c
for k=0 to NoOfLayers-1
c = k*70+50
ML_SetColor(c,c,c)
for i=0 to StarCount/NoOfLayers step NoOfLayers
Stars(i+k).x += Speed * (k+1)
if(Stars(i+k).x >SCREEN_WIDTH) then Stars(i+k).x=0
ML_DrawSprite(bob,Stars(i+k).x,Stars(i+k).y)
next
next
ML_SetColor(255,255,255)
static as single S1=0,S2=0,S3=0
S1=ML_GetDurationFromBaseTime()/80
S2=ML_GetDurationFromBaseTime()/245
S3=ML_GetDurationFromBaseTime()/415
ML_SetScale(1,2)
ML_StartShaderProgram(LineProgram)
ML_SetPixelVariable(0,@S1,1)
ML_SetPixelVariable(1,@S2,1)
ML_SetPixelVariable(2,@S3,1)
ML_SetSpriteTexture(CLine)
ML_DrawSprite(CLine,320,140)
ML_SetHorizontalFlip(true)
ML_DrawSprite(CLine,320,140+300)
ML_SetHorizontalFlip(false)
ML_StopShaderProgram()
ML_UsePerspectiveView
ML_Use3DWorld(false,true)
ML_SetScale(0.5,0.7)
ML_StartRenderingTo(Scren)
ML_SetSpriteTexture(font)
static as single a,sy(25),MsgX=70
MsgX -= 0.05
if(MsgX < -730) then MsgX=70
static as single zz(25),yy(25),aa,kk
kk = 60
aa -= 0.01
'if aa<-3.14*2 then aa=0
for k=0 to 24
zz(k) = cos(aa+(k*15*3.14159265/180))*kk
yy(k) = sin(aa+(k*15*3.14159265/180))*kk
next
for i=0 to MsgLen
ML_SetAlpha(0.8-0.5*zz(i mod 24)/kk)
ML_SetHorizontalRotation(3.14-aa)
ML_Draw3DChar(Msg[i],MsgX+1.5*i,yy(i mod 24),200+zz(i mod 24))
next
ML_SetHorizontalRotation(0)
ML_SetAlpha(1)
ML_StopUsing3DWorld()
ML_RenderToOriginalScreen()
ML_UseOrthogonalView
ML_SetScale(1,280/480)
ML_StartShaderProgram(CopperProgram)
ML_SetScreenSurfaceAsTexture(Scren)
ML_SetSpriteTexture(Copper,1)
ML_DarwScreenSurface(Scren,320,290)
ML_StopShaderProgram()
ML_UsePerspectiveView
''
'' end drawing
''
IDirect3DDevice9_EndScene(g_pd3dDevice)
IDirect3DDevice9_Present(g_pd3dDevice, NULL, NULL, NULL, NULL )
end sub
''-----------------------------------------------------------------------------
'' Name: WinMain()
'' Desc: The application's entry point
''-----------------------------------------------------------------------------
function WinMain(byval hInstance as HINSTANCE, _
byval hPrevInstance as HINSTANCE, _
byval lpCmdLine as string, _
byval nCmdShow as integer _
) as integer
dim as WNDCLASSEX winClass
dim as MSG uMsg
with winClass
.lpszClassName = @"MY_WINDOWS_CLASS"
.cbSize = len(WNDCLASSEX)
.style = CS_HREDRAW or CS_VREDRAW
.lpfnWndProc = @WindowProc
.hInstance = hInstance
.hIcon = LoadIcon(hInstance, cast(LPCTSTR,IDI_APPLICATION))
.hIconSm = LoadIcon(hInstance, cast(LPCTSTR,IDI_APPLICATION))
.hCursor = LoadCursor(NULL, IDC_ARROW)
.hbrBackground = cast(HBRUSH,GetStockObject(BLACK_BRUSH))
.lpszMenuName = NULL
.cbClsExtra = 0
.cbWndExtra = 0
end with
if( RegisterClassEx( @winClass ) = FALSE ) then
return E_FAIL
end if
g_hWnd = CreateWindowEx( NULL, "MY_WINDOWS_CLASS", _
"Direct3D (DX9) - Primitive Types", _
WS_OVERLAPPEDWINDOW or WS_VISIBLE, _
0, 0, 640, 480, NULL, NULL, hInstance, NULL )
if( g_hWnd = NULL ) then
return E_FAIL
end if
ShowWindow( g_hWnd, nCmdShow )
UpdateWindow( g_hWnd )
init()
do while( uMsg.message <> WM_QUIT )
if( PeekMessage( @uMsg, NULL, 0, 0, PM_REMOVE ) ) then
TranslateMessage( @uMsg )
DispatchMessage( @uMsg )
else
render()
end if
loop
shutDown()
UnregisterClass( "MY_WINDOWS_CLASS", winClass.hInstance )
return uMsg.wParam
end function
''-----------------------------------------------------------------------------
'' Name: WindowProc()
'' Desc: The window's message handler
''-----------------------------------------------------------------------------
function WindowProc( byval hWnd as HWND, _
byval msg as UINT, _
byval wParam as WPARAM, _
byval lParam as LPARAM _
) as LRESULT
select case ( msg )
case WM_KEYDOWN
select case( wParam )
case VK_ESCAPE
PostQuitMessage(0)
end select
case WM_CLOSE
PostQuitMessage(0)
case WM_DESTROY
PostQuitMessage(0)
case else
return DefWindowProc( hWnd, msg, wParam, lParam )
end select
return 0
end function
''-----------------------------------------------------------------------------
'' Name: shutDown()
'' Desc: Release all Direct3D resources.
''-----------------------------------------------------------------------------
sub shutDown( )
if( g_pd3dDevice <> NULL ) then
IDirect3DDevice9_Release(g_pd3dDevice)
end if
if( g_pD3D <> NULL ) then
IDirect3D9_Release( g_pD3D )
end if
end sub
''
''
''
end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
-
There's something wrong with your zip dude; can't wait to see it as it looks awesome and welldone Emil dude :)
-
thanks Clyde
i have tried it and download correctlly , please try it again.
-
Welldone Emil; thats very clever :)