0 Members and 1 Guest are viewing this topic.
''------------------------------------------------------------------------------'''' Magic Library For Ogre'' beta version 0.40'' by Emil Halim'''' Name : MirrorFontDemo'' Date : 26/02/2007'' Purpose : Teaching you that how to '' use Magic Library With'' FreeBasic.'''' website : http://www.freewebs.com/ogremagic/index.htm''''------------------------------------------------------------------------------#include once "windows.bi"#include once "win/d3d9.bi"#include once "MagicLibrary.bi"''-----------------------------------------------------------------------------'' GLOBALS''-----------------------------------------------------------------------------dim shared as HWND g_hWnd = NULLdim shared as LPDIRECT3D9 g_pD3D = NULLdim shared as LPDIRECT3DDEVICE9 g_pd3dDevice = NULLdim shared as SpriteData ptr RainbowSpritedim shared as BitmapFontData ptr Amigafontdim shared as zstring ptr Msgdim shared as single MsgLenth''-----------------------------------------------------------------------------'' PROTOTYPES''-----------------------------------------------------------------------------declare function WindowProc( byval hWnd as HWND, byval msg as UINT, byval wParam as WPARAM, byval lParam as LPARAM ) as LRESULTdeclare 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 ) '' Initial Magic Library here InitialMagicLibrary(g_pd3dDevice,640, 480) ML_SetMediaDirectory("../MagicMedia/") '/// creating Rainbow Image goto SkipData RianColor: data &H11,&H22,&H33,&H44,&H55,&H66 data &H77,&H88,&H99,&Haa,&Hbb,&Hcc data &Hdd,&Hee,&Hff,&H11ff,&H22ff,&H33ff data &H44ff,&H55ff,&H66ff,&H77ff,&H88ff data &H11aa,&H1199,&H1188,&H1177 data &H66,&H55,&H44,&H33,&H22,&H11 SkipData: RainbowSprite = ML_CreateStaticSprite(1,32) ML_StartDrawingToSprite(RainbowSprite) ML_ClearDrawingArea(0) dim as integer height= ML_GetDrawingHeight() dim as integer rain restore RianColor for h=0 to height-1 read rain ML_WriteRGBAChannels(0,h,&HFF000000 or rain) next ML_StopDrawingToSprite(RainbowSprite) Amigafont = ML_LoadBitmapFont("font/mrfont.bmp",39,45,40,65) ML_SetSpriteColorKeyFromPoint(Amigafont,0,0) ML_SetActiveBitmapFont(Amigafont) '// the small letter f represntes a space char because image has no space char Msg = Callocate(1024) *Msg = "HAYfDOfYOUfBELIVEfTHATffTHISfSCROLLINGfFONTfDEMOfHADfBEENfWRITTENfMOREfTHANfTENfYEARSfAGOfBYfAMOSfBASICfLANGUAGEfFORfAMIGAfCOMPUTER" ML_SetScale(2,2) MsgLenth = ML_GetTextLength(Msg,Amigafont) ML_SaveClipDrawinAreaState() 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) const as single baseY=268 ML_SetScale(640,4) ML_SetSpriteTexture(RainbowSprite) ML_DrawSprite(RainbowSprite,320,baseY-10) ML_SetClipDrawingAreaCorners(0,0,640,480) static as single X=640,Y=0,sx=0 Y = 20+sin(sx)*40 : sx+=0.01*2 X-=0.5*4 if(X < -MsgLenth) then X=640 ML_SetClipDrawingAreaCorners(40,0,600-40,baseY) ML_SetScale(2,2) ML_SetColor(255,0,0) ML_SetSpriteTexture(Amigafont) ML_DrawString(Msg,X,baseY-Y) ML_SetClipDrawingAreaCorners(40,baseY,600-40,60) ML_SetAlpha(0.25f) ML_SetScale(2,1.5) ML_SetVerticalFlip(true) ML_DrawString(Msg,X,baseY+Y) ML_SetVerticalFlip(false) ML_RestoreClipDrawinAreaState() 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.wParamend 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 0end 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 ifend sub '' '' '' end WinMain( GetModuleHandle( null ), null, Command( ), SW_NORMAL )
X-=0.5*4