Author Topic: EasyAmosDemo / OgreMagic  (Read 4432 times)

0 Members and 1 Guest are viewing this topic.

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
EasyAmosDemo / OgreMagic
« on: February 22, 2007 »
Hi all

Here is an other old Amiga demo that was wetting with Amos the creator Basic , but I have not finished it yet.

Here is the link
http://bcxdx.spoilerspace.com/FreeBasic/EasyAmosDemo_fb.zip

Here is the code

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  EasyAmosDemo
''        Date    :  22/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           = NULL
dim shared as LPDIRECT3D9          g_pD3D           = NULL
dim shared as LPDIRECT3DDEVICE9 g_pd3dDevice   = NULL

dim shared as SpriteData      ptr  titel
dim shared as SpriteData      ptr  Ranbow
dim shared as SpriteData      ptr  hotdogs
dim shared as TimeLineData   ptr  Timer1
dim shared as TimeLineData   ptr  Timer2
dim shared as SoundData       ptr   song

' /// add function from Amos basic for Amiga
 #define add(a,val,min,max)  a+=val : if(a>max)then a=min : if(a<min)then a=max


''-----------------------------------------------------------------------------
'' 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)
    FmodInit()

    ML_SetMediaDirectory("../MagicMedia/")
   
    song = ML_LoadSoundData("mod/sanct.mod",SongType)
    ML_SetSoundVolume(song,250)
    ML_SetSoundFreq(song,10)
       
    titel = ML_LoadStaticSprite("TITLEPAGE.bmp")
    ML_SetSpriteColorKeyFromPoint(titel,0,0)

    Ranbow = ML_CreateStaticSprite(1,128)
    ML_StartDrawingToSprite(Ranbow)
    ML_ClearDrawingArea(&Hff000000)
    clr = 0
    for h=0 to 127-1
          ML_WriteBlueChannel(0,h,clr)
          if(h<63) then
                   clr+=&H4
          else     
                   clr-=&H4
          end if
    next   
    ML_StopDrawingToSprite(Ranbow)

    hotdogs = ML_LoadStaticSprite("hotdogsprites.bmp")
    ML_SetSpriteColorKeyFromPoint(hotdogs,0,0)

    ML_SetBaseTimeNow() '// Must be call just before setting your timres
    Timer1 = ML_CreateNewTimeLine(0,8000)
    Timer2 = ML_CreateNewTimeLine(15000,30000)

   
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)
       
                    static as integer  RunOneTime = true
                    if(RunOneTime) then
                       ML_ResetBaseTime(Timer1)
                       ML_ResetBaseTime(Timer2)
                       ML_SetFadeFactor(1.0,0)
                       ML_SetAlpha(1.0)
                       RunOneTime = false
                     end if

                    ' Important:
                    ' 2d drawing Mode
                    ' tell Magic that you will
                    ' do some 2D stuff
                    ML_UseOrthogonalView()
                    ML_SetColor(255,255,255)

                    ' Set Blending System
                    ML_SetBlendMode(ALPHABLEND)

                    static as single lop=30, lop1=0, b=0, y=-240

                    if(ML_MouseLeftKeyClicked()) then
                        ML_ResetBaseTime(Timer1)
                        ML_ResetBaseTime(Timer2)
                        lop=30 : lop1=0 : b=0 : y=-240
                        ML_SetFadeFactor(1.0,0)
                        ML_SetAlpha(1.0)
                    end if


                    if(ML_CheckFireTime(Timer1)) then
                          if( ML_GetDurationFromStart(Timer1) > 4000 ) then ML_FadeOut(2000,0)

                          ML_SetScale(640,1)
                          ML_SetSpriteTexture(Ranbow)
                          ML_DrawSprite(Ranbow,320,240-128)
                          ML_DrawSprite(Ranbow,320,240)
                          ML_DrawSprite(Ranbow,320,240+128)
                          y+=10
                          if(y>=240) then
                             y = 240
                             if(lop>0) then
                                 b=30-abs(sin(lop1*1.2)*lop*2.2)
                                 lop1+=0.3
                                 if(lop1>6.28) then lop-=8 : lop1=0
                             end if
                          end if
                          ML_SetSpriteTexture(titel)
                          ML_SetScale(2,2)
                          ML_DrawSprite(titel,320,y+b)
                          ML_SetScale(1,1)
                    end if

                    if(ML_CheckEndFireTime(Timer1)) then
                          ML_PlaySound(song)
                          ML_FadeSoundIn(song,0.005)
                          dim as single ptr sepc
                          sepc = ML_GetSpectrum()
                          ML_SetAlpha(1.0)
                          ML_SetSpriteTexture(titel)
                          ML_SetScale(2,5*sepc[0])
                          ML_DrawPartOfSprite(titel,320,450-250*sepc[0],0,80,320,100)
                          if(ML_CheckFireTime(Timer2)) then
                              if( ML_GetDurationFromStart(Timer2) > 26000 ) then
                                ML_FadeOut(2000,0)
                              else
                                ML_FadeIn(2000,0)
                              end if

                              ML_SetScale(2,1.5)
                              ML_SetSpriteTexture(hotdogs)
                              ML_DrawPartOfSprite(hotdogs,320,150,0,196,320,200)
                              if( ML_GetDurationFromStart(Timer2) > 4000 ) then
                                  static as single x=640
                                 '// add(x,-0.5,-520,640)
                                  x -= 0.5
                                  if(x>640) then x = -520
                                  if(x<-520) then x = 640
                                  ML_SetScale(2,2)
                                  ML_DrawPartOfSprite(hotdogs,x*4-300,130,0,115,55,45)
                                  ML_SetScale(1,1)
                                  ML_DrawPartOfSprite(hotdogs,50+x*1.5,90,0,0,320,115)
                                  ML_DrawPartOfSprite(hotdogs,200+x,20,0,115,320,45)
                                  ML_SetHorizontalFlip(true)
                                  ML_SetScale(2,2)
                                  ML_DrawPartOfSprite(hotdogs,(640-x-200)*3,160,0,115,55,45)
                                  ML_SetScale(1,1)
                                  ML_DrawPartOfSprite(hotdogs,(640-x-100)*2,20,0,115,55,45)
                                  ML_DrawPartOfSprite(hotdogs,(640-x-100)*1.6,170,0,0,320,115)
                                  ML_DrawPartOfSprite(hotdogs,(640-x)-200,280,0,115,320,45)
                                  ML_SetHorizontalFlip(false)
                               end if
                           end if
                     end if
       

        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 )


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: EasyAmosDemo / OgreMagic
« Reply #1 on: February 22, 2007 »
Looks almost like an original :)

Are you going to be releasing some sort of doc file / manual to doccument the commands and how they work?

Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: EasyAmosDemo / OgreMagic
« Reply #2 on: February 22, 2007 »
Surely , I will make a help file that demonstrate all the functions and how to use them , but I am not native English writer , so may I need some support. :'(

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: EasyAmosDemo / OgreMagic
« Reply #3 on: February 22, 2007 »
We'll help you translate it.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: EasyAmosDemo / OgreMagic
« Reply #4 on: February 22, 2007 »
ok

here is my first try , let me know your opinion.

http://bcxdx.spoilerspace.com/FreeBasic/OgreMagicHelp.zip

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: EasyAmosDemo / OgreMagic
« Reply #5 on: February 22, 2007 »
The presenation of it is fantastic. If it was my project I'd keep the same sort of presentation but add some things to it, for example a menu;

GETTING STARTED (Details of how to install in each supported language)
COMMAND REFERENCE (An index of the command names)

For example ;
InitialMagicLibrary
Initialises the screen format;

InitialMagicLibrary( PARAMETER 1, PARAMETER 2, PARAMETER 3)

Code example;

code
code
...

Related commands;




Getting the index right will make the lib intuitive to use, once you have finalised your ideas for it I will be more than happy to proof read it and correct any grammatical errors. It's not much of a problem, your English is pretty good.  :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: EasyAmosDemo / OgreMagic
« Reply #6 on: February 22, 2007 »
Thanks Mr.  Shockwave

Yes all the menus and each function will has it’s own demonstration , all that will be in the final to produce one help file.

 

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: EasyAmosDemo / OgreMagic
« Reply #7 on: February 23, 2007 »
Hi Mr. Shockwave

i have update the OgerMagic Help , so please redownload it again and let me kow your opinion.

it is still far from finishing.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: EasyAmosDemo / OgreMagic
« Reply #8 on: February 24, 2007 »
I like the format of it now, especially as you include examples for all the supported languages. It needs to have an index to make it easier to go through the topics.
You work really fast Emil, fair play to you. Sorry I didn't get a chance to look at these last night. Once it has the index it will be a lot eassier to navigate.

Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: EasyAmosDemo / OgreMagic
« Reply #9 on: February 25, 2007 »
I have created a help file,  redownload it from the same location.

It is still not finish , I will add discretions and examples in next few days.

I really hard work to create a help file.