Dark Bit Factory & Gravity
PROGRAMMING => Freebasic => Topic started by: Emil_halim on February 20, 2007
-
Hi all
I have rewritten My entire library without the class and also with a C link, for allowing FreeBasic to use it , I will upload it to my website as soon as possible.
Here is a red scrolling Rainbow source code .
''------------------------------------------------------------------------------
''
'' Magic Library For Ogre
'' beta version 0.40
'' by Emil Halim
''
'' Name : ScrollingRaibowDemo
'' Date : 20/02/2007
'' Purpose : Teaching you that how to
'' use Magic Library With
'' FreeBasic.
''------------------------------------------------------------------------------
#include once "windows.bi"
#include once "win/mmsystem.bi"
#include once "win/d3d9.bi"
#include once "win/d3dx9.bi"
#include once "crt.bi"
#include once "MagicLibrary.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 Ranbow
''-----------------------------------------------------------------------------
'' 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)
'' Initial Magic Library here
InitialMagicLibrary(g_pd3dDevice,640, 480)
Ranbow = ML_CreateStaticSprite(1,128)
ML_StartDrawingToSprite(Ranbow)
ML_ClearDrawingArea(0)
clr=&HFFff0000-(30*&H80000)
for h=1 to 30
ML_WriteRGBAChannels(0,h,clr)
clr+=&H80000
next
for h=30 to 59
ML_WriteRGBAChannels(0,h,clr)
clr-=&H80000
next
for h=60 to 90
ML_WriteRGBAChannels(0,h,clr)
clr+=&H70000
next
for h=90 to 120
ML_WriteRGBAChannels(0,h,clr)
clr-=&H60000
next
ML_StopDrawingToSprite(Ranbow)
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_UseOrthogonalView
ML_SetAlpha(1)
ML_SetColor(255,255,255)
ML_SetBlendMode(ALPHABLEND)
ML_SetSpriteTexture(Ranbow)
ML_SetScale(640,1)
static as single y =0
y += 0.5
if(y>128) then y=0
for i=0 to 7
ML_DrawPartOfSprite(Ranbow,320,70.0*i,0,y,1,127)
next
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()
sleep 10
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 )
so what is your opinion ?
download demo here http://bcxdx.spoilerspace.com/FreeBasic/ScrollingRaibow_fb.zip (http://bcxdx.spoilerspace.com/FreeBasic/ScrollingRaibow_fb.zip)
-
Nice simple effect. It'd be great to see what more the library is capable of.
But you can definitely have some Karma for posting our first freebasic sample code using Direct3D9!
Jim
-
Yes indeed! Looks just like an effect using Amos on the Amiga. Good one, have some Karma from me too :)
-
Thank you guys very much .
Actually there is no limit of idea that you can do with it.
If you want to see some of them so visit my Ogre Showcase page.
I will port the Amiga Zowee Demo to let you see that you can make some effects that was done with Amiga computer.
BTW , some of my demo uses high level Shader Language , so that I want to know if your VGA card supports it or not.
See you.
-
Very cool and :hi: aboard dude :)
Cheers and all the best,
Clyde.
-
I don't have shader support but lots off people do so don't let that stop you :)