Author Topic: Source Code for Intro Inferno Promo.  (Read 8466 times)

0 Members and 1 Guest are viewing this topic.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Source Code for Intro Inferno Promo.
« on: February 26, 2007 »
Hi, Emil Halim requested to have a look at the source code for;
THIS PRODUCTION
so that he could try and make a conversion using his Ogremagic library. As his lib is a 2D lib and this intro took about 1 month to make with all the little tweaks I am very, very interested in this project and how the conversion comes out.

Rather than just give the source to Emil, I have attached it to this post so that everyone can have a look at what a nightmare task he's given himself!! ( I can't even bear to look at this code myself any more! ).

Good luck Emil!
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #1 on: February 26, 2007 »
oh , thank you very much Mr. Shockwave for posting the source code. :)

i have ported 2 demos of OgreMagic to FreeBasic , i will post them sooner.

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #2 on: February 26, 2007 »
You're welcome :)

About the Mr. Shockwave name, it's simple why my name was Mr.Shockwave. Years ago I registered on a community that did Yabasic programming, I tried to register my account as "shockwave" however something went wrong with the registration and i could not use that name so I re-registered my account and had to call it something else so I called it "Mr. Shockwave". I think you must have picked that name up from the Yabasic forums?

Carry on using it if you like, though most people just call me shock, shocky, shockwave , nick , or whatever random swear word comes into your head :)

Good luck with porting this demo, it won't be easy.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #3 on: February 26, 2007 »
Ok i liked shocky name.

after I have sow the source code of the demo I realized that why you said it is a
nightmare task.

Any way , I will try to port the animation it self as possible as I can.
I will try it with shader language , so it may not work in your system , so I just wonder if you can test it in an other system or not? , I will post very simple test with shader to test it in your system.

There is some thing that I want to tell you, although OgerMagic can make 2D drawing stuff , it has a 3D world functions that allow to put your sprites and font in real 3D world , also it is uses the 3D hardware to achieve the 2D stuff   

   

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #4 on: February 26, 2007 »
I don't have shaders at all here emil, however there are another 260 people on this forum so I'm sure that they will be able to test it. You know, I feel lousy about this PC, it has no graphics card, as it is only a cheap laptop, the computer upstairs is not much better but simple shaders might at least work on that one.

I'dlove to see some Glenz vectors in Ogermagic :) Using shaders for an effect that was done in the 1980's is as overkill as me coding something oldschool on a 2ghz pc so I say bring it on :)  :clap:
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #5 on: February 26, 2007 »
ok , here is a demo that i want you to test in your system , it uses sgader language.

it is a PolarPlasmaDemo that was writtin by Optimus/Dirty Minds.

i have port it to OgreMagic

download it from here
PolarPlasmaDemo_fp

here is the source code

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  PolarPlasmaDemo
''        Date    :  26/02/2007
''        Purpose :  wrettin by Optimus/Dirty Minds
''                   ported to OgreMagic and uesing             
''                   shader Laguage By Emil Halim
''
''       website  :  http://www.freewebs.com/ogremagic/index.htm
''
''------------------------------------------------------------------------------

'
'  i have emultae the Palette feature by
'  Pixle shadre program , so emulating
'  Old stuff by most moddern hardwar
'  is easy task
'

#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  RASprite
dim shared as SpriteData       ptr  RGBSprite
dim shared as SpriteData       ptr  SinSprite
dim shared as HLSLProgramData  ptr  RGBProgram

''-----------------------------------------------------------------------------
'' 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 )
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    ML_SetMediaDirectory("../MagicMedia/")

    RGBSprite = ML_CreateStaticSprite(256,1)
    ML_StartDrawingToSprite(RGBSprite)
    ML_ClearDrawingArea(0)
    for i=0 to 63
        ML_WriteRGBAChannels(    i,0,(i*2) shl 16 or i*4 or &HFF000000)
        ML_WriteRGBAChannels( 64+i,0,(128+i*2) shl 16 or (i*4) shl 8 or (63-i)*4 or &HFF000000)
        ML_WriteRGBAChannels(128+i,0, 255 shl 16 or ((63-i)*4) shl 8 or &HFF000000)
        ML_WriteRGBAChannels(192+i,0,((63-i)*4) shl 16 or &HFF000000)
next
    ML_StopDrawingToSprite(RGBSprite)

    const wWIDTH=640
    const HEIGHT=480
    const cx=wWIDTH/2
    const cy=HEIGHT/2
    const rang=512
    const pi=3.14151693
    const d2r=180.0/pi
    const d2b = (rang * d2r) / 360.0
    RASprite = ML_CreateStaticSprite(wWIDTH,HEIGHT)
    ML_StartDrawingToSprite(RASprite)
    ML_ClearDrawingArea(0)
    i=0
    for y=0 to HEIGHT-1
        for x=0 to wWIDTH-1
            ML_WriteRedChannel(x,y,sqr((cx-x)^2+(cy-y)^2))
           
            if x=cx then
                if y<cy then
                      ML_WriteAlphaChannel(x,y,rang SHR 2)
                 else
                      ML_WriteAlphaChannel(x,y,(rang SHR 1) + (rang SHR 2))
                end if
            end if
           
            if y=cy then
                if x>cx then
                   ML_WriteAlphaChannel(x,y,0)
                else
                   ML_WriteAlphaChannel(x,y,rang SHR 1)
                end if
            end if

            if x<>cx AND y<>cy then
                if x>cx AND y<cy then ML_WriteAlphaChannel(x,y,atn((cy%-y%)/(x%-cx%))*d2b)
                if x<cx AND y<cy then ML_WriteAlphaChannel(x,y,atn((cx%-x%)/(cy%-y%))*d2b+(rang% SHR 2))
                if x<cx AND y>cy then ML_WriteAlphaChannel(x,y,atn((y%-cy%)/(cx%-x%))*d2b+(rang% SHR 1))
                if x>cx AND y>cy then ML_WriteAlphaChannel(x,y,atn((x%-cx%)/(y%-cy%))*d2b+(rang% SHR 1)+(rang% SHR 2))
            end if
        next
    next
    ML_StopDrawingToSprite(RASprite)

    SinSprite = ML_CreateStaticSprite(2048,1)
    ML_StartDrawingToSprite(SinSprite)
    ML_ClearDrawingArea(0)
    dim as single L=0.25
    for i=0 to 2047-1
    ML_WriteRedChannel(i,0,sin(i/(L*d2b))*48+64)
    next
    ML_StopDrawingToSprite(SinSprite)

    RGBProgram  = ML_CreateHLSLProgram()
    ML_EditPixelProgram(RGBProgram)
    ML_AddToProgram("sampler2D tex0;                                          ")
    ML_AddToProgram("sampler2D tex1;                                          ")
    ML_AddToProgram("sampler2D tex2;                                          ")
    ML_AddToProgram("float k;                                                 ")
    ML_AddToProgram("float4  main(  float2 TexCoord : TEXCOORD0) : COLOR0     ")
    ML_AddToProgram("{                                                        ")
    ML_AddToProgram("       float4 Color;                                     ")
    ML_AddToProgram("       float4 ndx  = tex2D( tex0, TexCoord);             ")
    ML_AddToProgram("       float4 fsin = tex2D( tex2, float2(ndx.a,0));      ")
    ML_AddToProgram("       float  i    = ndx.r + fsin.r - k;                 ")
    ML_AddToProgram("       Color       = tex2D( tex1, float2(i,0));          ")
    ML_AddToProgram("       return Color;                                     ")
    ML_AddToProgram("}                                                        ")
    ML_CompilePixelProgram(RGBProgram,"main")

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 single k = 0
        k+=0.01
        ML_SetPixelVariable(0,@k,1)
        ML_StartShaderProgram(RGBProgram)
        ML_SetSpriteTexture(RASprite)
        ML_SetSpriteTexture(RGBSprite,1)
        ML_SetSpriteTexture(SinSprite,2)
        ML_DrawSprite(RASprite,320,240)
        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 )


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #6 on: February 26, 2007 »
It works here Emil, it does have a bug, there is a single pixel circle artifact on the screen, apart from that it looks fine.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #7 on: February 26, 2007 »
this is great news , but to be sure , does it look like this or not?

please ignore the Ogra logo and green Fps rectangle.




Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #8 on: February 26, 2007 »
Hi shocky

I have decided that I will port the SIP Demo step by step.

So here is the first step , it is the splash.

Download it here
SipDemo_fp

Here is the source code

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  SIPDemo
''        Date    :  27/02/2007
''        Purpose :  wrettin by Shockwave for FreeBasic.
''                   ported to OgreMagic by Emil Halim.
''
''       website  :  http://www.freewebs.com/ogremagic/index.htm
''
''       link     :  http://dbfinteractive.com/index.php?topic=1422.0
''
''------------------------------------------------------------------------------
OPTION EXPLICIT

#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  SplashImage
''-----------------------------------------------------------------------------
'' 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 )
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    ML_SetMediaDirectory("../SipMedia/")

    SplashImage = ML_LoadStaticSprite("intro.bmp")
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)
       
        '
        '   Splash stuff
        '
        ML_SetSpriteTexture(SplashImage)
        dim as single stepwidth  = SplashImage->fullWidth/16
        dim as single stepHeight = SplashImage->fullHeight/16
        dim as integer y , x
        dim as single SCL
        for y = 0 to 15
           SCL = ML_GetDurationFromBaseTime/1000 +y*0.05
           if (SCL > 1.0) then SCL = 1.0
           ML_SetScale(SCL,SCL)
           for x = 0 to 15
               ML_DrawPartOfSprite(SplashImage,20+stepwidth*x,15+stepHeight*y,_
                             stepwidth*x,stepHeight*y,stepwidth,stepHeight)
           next
        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()
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: Source Code for Intro Inferno Promo.
« Reply #9 on: February 27, 2007 »
The circle is the same as the one in the picture you posted so it is working fine :) You have the splash screen bang on too, it looks the same as in my demo, nice job so far :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #10 on: February 27, 2007 »

ok , that is great. :updance:

i have added a scrolling chess board effect just like your demo by using 3D world and shader program.

download it from the same url.

here is the updated sinppet

Code: [Select]

OPTION EXPLICIT

#include once "windows.bi"
#include once "win/d3d9.bi"
#include once "win/d3dx9.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 TimeLineData    ptr  SplasTimer
dim shared as SpriteData      ptr  SplashImage
dim shared as SpriteData      ptr  ChessImage
dim shared as SpriteData      ptr  AlphaChess
dim shared as HLSLProgramData ptr  ChessProgram

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

    '' create camera
    dim as D3DXMATRIXA16 mView , Projection
    dim as D3DXVECTOR3 Eye , LookAt , Up
     Eye->x = 0.0
     Eye->y = 0.0
     Eye->Z =-1.0
     LookAt->x = 0.0
     LookAt->y = 0.0
     LookAt->Z = 0.0
     Up->x = 0.0
     Up->y = 1.0
     Up->Z = 0.0
       
    D3DXMatrixLookAtLH(@mView, @Eye, @LookAt, @Up)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_VIEW, @mView)
    D3DXMatrixPerspectiveFovLH(@Projection, 1.0f, 480/640, 0.0f, 500.0f)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_PROJECTION, @Projection)
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    ML_SetMediaDirectory("../SipMedia/")

    SplashImage = ML_LoadStaticSprite("intro.bmp")

    ChessImage = ML_CreateStaticSprite(32,256)
    ML_StartDrawingToSprite(ChessImage)
    ML_ClearDrawingArea(0)
    dim as integer white , blue
    dim as integer i ,j , w
    for j=0 to 15 step 2
      for i=0 to 15
        for w = 0 to 15
           white = rgb(111,111,223)
           blue  = rgb(13,13,111)
           ML_WriteRGBAChannels(w   ,(j*16)+ i    ,white)
           ML_WriteRGBAChannels(w   ,(j*16)+(i+16),blue )
           ML_WriteRGBAChannels(w+16,(j*16)+ i    ,blue )
           ML_WriteRGBAChannels(w+16,(j*16)+(i+16),white)
         next
      next
    next
    ML_StopDrawingToSprite(ChessImage)

    AlphaChess = ML_CreateStaticSprite(1,256)
    ML_StartDrawingToSprite(AlphaChess)
    for j=0 to 255
        ML_WriteAlphaChannel(0,j,j)
    next
    ML_StopDrawingToSprite(AlphaChess)
     
    ChessProgram = ML_CreateHLSLProgram()
    ML_EditPixelProgram(ChessProgram)
    ML_AddToProgram("sampler2D tex0;                                          ")
    ML_AddToProgram("sampler2D tex1;                                          ")
    ML_AddToProgram("float k;                                                 ")
    ML_AddToProgram("float4  main(  float2 TexCoord : TEXCOORD0) : COLOR0     ")
    ML_AddToProgram("{                                                        ")
    ML_AddToProgram("       float4 Color;                                     ")
    ML_AddToProgram("       float2 coord = float2(TexCoord.x,TexCoord.y+k);   ")
    ML_AddToProgram("       float4 col   = tex2D( tex0, coord);               ")
    ML_AddToProgram("       float4 alpha = tex2D( tex1, TexCoord);            ")
    ML_AddToProgram("       Color        = float4( col.rgb,alpha.a);          ")
    ML_AddToProgram("       return Color;                                     ")
    ML_AddToProgram("}                                                        ")
    ML_CompilePixelProgram(ChessProgram,"main")
       
    ML_SetBaseTimeNow()
    SplasTimer = ML_CreateNewTimeLine(0,2000)  ' give the splash 2 seconds to finish
    'ML_DisableCheckFireTime(SplasTimer)

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)
       
        ''
        ''   Splash stuff
        ''
        if(ML_CheckFireTime(SplasTimer)) then
            ML_SetSpriteTexture(SplashImage)
            dim as single stepwidth  = SplashImage->fullWidth/16
            dim as single stepHeight = SplashImage->fullHeight/16
            dim as integer y , x
            dim as single SCL
            for y = 0 to 15
                SCL = ML_GetDurationFromStart(SplasTimer)/1000 + y*0.03
                if (SCL > 1.0) then SCL = 1.0
                ML_SetScale(SCL,SCL)
                for x = 0 to 15
                    ML_DrawPartOfSprite(SplashImage,stepwidth*(x+0.5),stepHeight*(y+0.5),_
                             stepwidth*x,stepHeight*y,stepwidth,stepHeight)
                next
            next
        end if

        ML_UsePerspectiveView

        ''
        '' using 3D world and shader to scrol chess
        ''
        if(ML_CheckEndFireTime(SplasTimer)) then
            ML_Use3DWorld()
            ML_SetHorizontalRotation(1.5)
            const Scl = 1.5
            ML_SetScale(Scl,Scl*2 )
            ML_StartShaderProgram(ChessProgram)
            dim as single k =1.0-ML_GetDurationFromBaseTime()/3000.0
            ML_SetPixelVariable(0,@k,1)
            ML_SetSpriteTexture(ChessImage)
            ML_SetSpriteTexture(AlphaChess,1)
            dim as integer x
            for x = -3 to 3
            ML_Draw3DSprite(ChessImage,x*32*Scl,-60,200)
            next
            ML_StopShaderProgram()
            ML_StopUsing3DWorld()
        end if

       
       
''
'' end drawing
''
IDirect3DDevice9_EndScene(g_pd3dDevice)
    IDirect3DDevice9_Present(g_pd3dDevice, NULL, NULL, NULL, NULL )
   
end sub
   

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #11 on: February 27, 2007 »
Hi Emil, it's looking for;

win/d3dx9d.dll

and can't find it.

I have a suggestion that maybe people won't be able to run these programs because they need the ogermagic libraries and the examples that you're kindly giving us need them. Your library is very good and it deserves more comments, maybe putting all the resources needed into on e zip file and just updating that one zip file would be the solution.

Most people just tend to download a zip and then expect everything to run, unless they've been following the topic they wouldn't necessarily know how to get it working.

I really want to see that chess board :)
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #12 on: February 27, 2007 »
Ok I have did it as you suggested.

Download here

OgreMagic_fb

Yes , my library need to be more comments, I did not have a talent of writing a good help file , it will be my pleasure if some one helped me, but just comment each part of code is not a big deal.

About the demo , I will add a touch of mine, so I will fade out the splash after it finished.

edited

ok ,here is the sinppet with comments
Code: [Select]
''-----------------------------------------------------------------------------
'' 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 TimeLineData    ptr  SplasTimer     ' we want splash to stay only 2 seconds   
dim shared as SpriteData      ptr  SplashImage    ' holds pointer to splash Sprite structure
dim shared as SpriteData      ptr  ChessImage     ' holds pointer to chess Sprite structure
dim shared as SpriteData      ptr  AlphaChess     ' holds the alpha value
dim shared as HLSLProgramData ptr  ChessProgram   ' shader program to scroll the chess

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

    '' create camera
    dim as D3DXMATRIXA16 mView , Projection
    dim as D3DXVECTOR3 Eye , LookAt , Up
     Eye->x = 0.0
     Eye->y = 0.0
     Eye->Z =-1.0
     LookAt->x = 0.0
     LookAt->y = 0.0
     LookAt->Z = 0.0
     Up->x = 0.0
     Up->y = 1.0
     Up->Z = 0.0
       
    D3DXMatrixLookAtLH(@mView, @Eye, @LookAt, @Up)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_VIEW, @mView)
    D3DXMatrixPerspectiveFovLH(@Projection, 1.0f, 480/640, 0.0f, 500.0f)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_PROJECTION, @Projection)
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    '' tells OgreMagic that from where it will load resources 
    ML_SetMediaDirectory("../SipMedia/")

    '' load splash sprite
    SplashImage = ML_LoadStaticSprite("intro.bmp")

    '' create an empty sprite , we will edit it
    ChessImage = ML_CreateStaticSprite(32,256)
    '' lock the Sprite texture intrnally for editing
    '' and save a pointer to the buffer that uesed with editing function
    ML_StartDrawingToSprite(ChessImage)
    '' fill the sprite buffer with 0 value
    ML_ClearDrawingArea(0)
    dim as integer white , blue
    dim as integer i ,j , w
    for j=0 to 15 step 2
      for i=0 to 15
        for w = 0 to 15
           white = rgb(111,111,223)
           blue  = rgb(13,13,111)
           ML_WriteRGBAChannels(w   ,(j*16)+ i    ,white)
           ML_WriteRGBAChannels(w   ,(j*16)+(i+16),blue )
           ML_WriteRGBAChannels(w+16,(j*16)+ i    ,blue )
           ML_WriteRGBAChannels(w+16,(j*16)+(i+16),white)
         next
      next
    next
    '' unlock the Sprite texture
    ML_StopDrawingToSprite(ChessImage)

    '' creating alpha sprite
    AlphaChess = ML_CreateStaticSprite(1,256)
    ML_StartDrawingToSprite(AlphaChess)
    for j=0 to 255
        ML_WriteAlphaChannel(0,j,j)
    next
    ML_StopDrawingToSprite(AlphaChess)
     
    '' creating pixel shader program
    ChessProgram = ML_CreateHLSLProgram()
    ML_EditPixelProgram(ChessProgram)
    ML_AddToProgram("sampler2D tex0;                                          ")
    ML_AddToProgram("sampler2D tex1;                                          ")
    ML_AddToProgram("float k;                                                 ")
    ML_AddToProgram("float4  main(  float2 TexCoord : TEXCOORD0) : COLOR0     ")
    ML_AddToProgram("{                                                        ")
    ML_AddToProgram("       float4 Color;                                     ")
    ML_AddToProgram("       float2 coord = float2(TexCoord.x,TexCoord.y+k);   ")
    ML_AddToProgram("       float4 col   = tex2D( tex0, coord);               ")
    ML_AddToProgram("       float4 alpha = tex2D( tex1, TexCoord);            ")
    ML_AddToProgram("       Color        = float4( col.rgb,alpha.a);          ")
    ML_AddToProgram("       return Color;                                     ")
    ML_AddToProgram("}                                                        ")
    ML_CompilePixelProgram(ChessProgram,"main")
       
    '' creating line time to control animatiom timing
    ML_SetBaseTimeNow() '' must be called before creating time
    SplasTimer = ML_CreateNewTimeLine(0,2000)  ' give the splash 2 seconds to finish
    'ML_DisableCheckFireTime(SplasTimer)

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
    ''
        '' starting 2D drawing
        ML_UseOrthogonalView
        '' set the alpha blending factor
        ML_SetAlpha(1)
        '' srt the a white color
        ML_SetColor(255,255,255)
       
        ML_SetBlendMode(ALPHABLEND)
       
        ''
        ''   Splash stuff
        ''
        if(ML_CheckFireTime(SplasTimer)) then ' check if we inside the period
            '' before we draw the sprite we must set it's texture
            ML_SetSpriteTexture(SplashImage)
            '' we divide our splash into small section
            dim as single stepwidth  = SplashImage->fullWidth/16
            dim as single stepHeight = SplashImage->fullHeight/16
            dim as integer y , x
            dim as single SCL
            for y = 0 to 15
                '' control the
                SCL = ML_GetDurationFromStart(SplasTimer)/1000 + y*0.03
                if (SCL > 1.0) then SCL = 1.0
                ML_SetScale(SCL,SCL)
                for x = 0 to 15
                    '' draw each part of sprite
                    ML_DrawPartOfSprite(SplashImage,stepwidth*(x+0.5),stepHeight*(y+0.5),_
                             stepwidth*x,stepHeight*y,stepwidth,stepHeight)
                next
            next
        end if
        '' tells OgreMagic that we
        '' finished our 2D stuff and
        '' must return to 3D world 
        ML_UsePerspectiveView

        ''
        '' using 3D world and shader to scrol chess
        ''
        if(ML_CheckEndFireTime(SplasTimer)) then ' is splash finished
            '' just as ML_UseOrthogonalView but with 3D world
            '' so we can use our sprites in 3D world
            ML_Use3DWorld()
            '' rotate the next drawing around x-x axis by 1.5 rdian angle
            ML_SetHorizontalRotation(1.5)
            const Scl = 1.5
            ML_SetScale(Scl,Scl*2 )
            '' tells OgerMagic to start using shader program
            ML_StartShaderProgram(ChessProgram)
            dim as single k =1.0-ML_GetDurationFromBaseTime()/3000.0
            '' pass a variable to shader program
            ML_SetPixelVariable(0,@k,1)
            '' set the sprite texture before drawing it
            ML_SetSpriteTexture(ChessImage)
            '' set the second texture and pass it to
            '' shader program for donig the effect
            ML_SetSpriteTexture(AlphaChess,1)
            dim as integer x
            for x = -3 to 3
            '' here the actual drawing of sprite
            ML_Draw3DSprite(ChessImage,x*32*Scl,-60,200)
            next
            '' we do our chess effect so we do not want to
            '' use the chess shader program any more
            ML_StopShaderProgram()
           
            '' we finished our 3D render
            ML_StopUsing3DWorld()
        end if

       
       
''
'' end drawing
''
IDirect3DDevice9_EndScene(g_pd3dDevice)
    IDirect3DDevice9_Present(g_pd3dDevice, NULL, NULL, NULL, NULL )
   
end sub

« Last Edit: February 27, 2007 by Emil_halim »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #13 on: February 27, 2007 »
Thanks Emil, I'm sure that more people will be able to run this now, I am just downloading the zip.
As for the help file, I will personally go through it and change any grammar that needs changing when the help file is done :) All I will need is a text file (Not html) to make it easier for me to proof read it. Is the help file finished as I would rather do this in one sitting :) Cheers.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline DrewPee

  • I Toast Therefore I am
  • Pentium
  • *****
  • Posts: 563
  • Karma: 25
  • Eat Cheese - It's good for you!
    • View Profile
    • Retro Computer Museum
Re: Source Code for Intro Inferno Promo.
« Reply #14 on: February 27, 2007 »
That sure is amazing what Emil is doing . . . can't wait to see more from him?
Looks quite complicated at the mo . . . looking forward to seeing the help file!

 :goodpost: to both Shockwave and Emil!!!

Drew
DrewPee
aka Falcon of The Lost Boyz (Amiga)
Ex-Amiga Coder and Graphic Designer
Administrator of > www.retrocomputermuseum.co.uk

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #15 on: February 27, 2007 »
@ shocky and DrewPee

thanks guys for your good words. :)

This time I have implemented a star field.

Here is the source

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  SIPDemo
''        Date    :  27/02/2007
''        Purpose :  wrettin by Shockwave for FreeBasic.
''                   ported to OgreMagic by Emil Halim.
''
''       website  :  http://www.freewebs.com/ogremagic/index.htm
''
''       link     :  http://dbfinteractive.com/index.php?topic=1422.0
''
''------------------------------------------------------------------------------
OPTION EXPLICIT

#include once "windows.bi"
#include once "win/d3d9.bi"
#include once "win/d3dx9.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 TimeLineData    ptr  SplasTimer     ' we want splash to stay only 2 seconds   
dim shared as SpriteData      ptr  SplashImage    ' holds pointer to splash Sprite structure
dim shared as SpriteData      ptr  ChessImage     ' holds pointer to chess Sprite structure
dim shared as SpriteData      ptr  AlphaChess     ' holds the alpha value
dim shared as HLSLProgramData ptr  ChessProgram   ' shader program to scroll the chess
dim shared as SpriteData      ptr  starBOB 
dim shared as AnimatedSpriteData  ptr   Mickey

'' 3D star field
    #define StarCount 150
    #define SCREEN_WIDTH 625
    #define SCREEN_HEIGHT 450
    type STAR3D
         x   as single
         y   as single
         z   as single
         zv  as single
    end type

dim shared as STAR3D Stars(0 to StarCount)

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

    '' create camera
    dim as D3DXMATRIXA16 mView , Projection
    dim as D3DXVECTOR3 Eye , LookAt , Up
     Eye->x = 0.0
     Eye->y = 0.0
     Eye->Z =-1.0
     LookAt->x = 0.0
     LookAt->y = 0.0
     LookAt->Z = 0.0
     Up->x = 0.0
     Up->y = 1.0
     Up->Z = 0.0
       
    D3DXMatrixLookAtLH(@mView, @Eye, @LookAt, @Up)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_VIEW, @mView)
    D3DXMatrixPerspectiveFovLH(@Projection, 1.0f, 480/640, 0.0f, 500.0f)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_PROJECTION, @Projection)
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    '' tells OgreMagic that from where it will load resources 
    ML_SetMediaDirectory("../SipMedia/")

    '' load splash sprite
    SplashImage = ML_LoadStaticSprite("intro.bmp")

    '' create an empty sprite , we will edit it
    ChessImage = ML_CreateStaticSprite(32,256)
    '' lock the Sprite texture intrnally for editing
    '' and save a pointer to the buffer that uesed with editing function
    ML_StartDrawingToSprite(ChessImage)
    '' fill the sprite buffer with 0 value
    ML_ClearDrawingArea(0)
    dim as integer white , blue
    dim as integer i ,j , w
    for j=0 to 15 step 2
      for i=0 to 15
        for w = 0 to 15
           white = rgb(111,111,223)
           blue  = rgb(13,13,111)
           ML_WriteRGBAChannels(w   ,(j*16)+ i    ,white)
           ML_WriteRGBAChannels(w   ,(j*16)+(i+16),blue )
           ML_WriteRGBAChannels(w+16,(j*16)+ i    ,blue )
           ML_WriteRGBAChannels(w+16,(j*16)+(i+16),white)
         next
      next
    next
    '' unlock the Sprite texture
    ML_StopDrawingToSprite(ChessImage)

    '' creating alpha sprite
    AlphaChess = ML_CreateStaticSprite(1,256)
    ML_StartDrawingToSprite(AlphaChess)
    for j=0 to 255
        ML_WriteAlphaChannel(0,j,j)
    next
    ML_StopDrawingToSprite(AlphaChess)
     
    '' creating pixel shader program
    ChessProgram = ML_CreateHLSLProgram()
    ML_EditPixelProgram(ChessProgram)
    ML_AddToProgram("sampler2D tex0;                                          ")
    ML_AddToProgram("sampler2D tex1;                                          ")
    ML_AddToProgram("float k;                                                 ")
    ML_AddToProgram("float4  main(  float2 TexCoord : TEXCOORD0) : COLOR0     ")
    ML_AddToProgram("{                                                        ")
    ML_AddToProgram("       float4 Color;                                     ")
    ML_AddToProgram("       float2 coord = float2(TexCoord.x,TexCoord.y+k);   ")
    ML_AddToProgram("       float4 col   = tex2D( tex0, coord);               ")
    ML_AddToProgram("       float4 alpha = tex2D( tex1, TexCoord);            ")
    ML_AddToProgram("       Color        = float4( col.rgb,alpha.a);          ")
    ML_AddToProgram("       return Color;                                     ")
    ML_AddToProgram("}                                                        ")
    ML_CompilePixelProgram(ChessProgram,"main")
     
   goto  SkipData
  StarBobData:
    DATA 0,0,1,1,1,0,0
    DATA 0,2,3,4,5,4,0
    DATA 1,2,2,5,6,5,1
    DATA 1,3,1,4,5,4,1
    DATA 1,4,2,1,2,3,1
    DATA 0,2,4,3,2,2,0
    DATA 0,0,1,1,1,0,0
  SkipData:
    dim clr,RG(0 to 6)
    RG(0)= 0
    RG(1)= RGBA(120, 90,120,255 )
    RG(2)= RGBA(150,110,150,255 )
    RG(3)= RGBA(190,150,190,255 )
    RG(4)= RGBA(210,180,210,255 )
    RG(5)= RGBA(240,230,240,255 )
    RG(6)= RGBA(250,250,250,255 )
    restore  StarBobData
    starBOB = ML_CreateStaticSprite(8,8)
    ML_StartDrawingToSprite(starBOB)
    ML_ClearDrawingArea(0)
    for j=0 to 6
      for i=0 to 6
        read clr 
        ML_WriteRGBAChannels(i,j,RG(clr))
      next
    next
    ML_StopDrawingToSprite(starBOB)
   
    randomize timer
    for i=0 to StarCount-1
          Stars(i)->x  = rnd()*1000-500
          Stars(i)->y  = rnd()*1000-500
          Stars(i)->z  = rnd()*900+100
          Stars(i)->zv =(rnd()*45)/10+.5
    next


    ML_SetMediaDirectory("../MagicMedia/")
 
    Mickey = ML_LoadAnimatedSprite("Sprites/Micky.bmp")
    ML_SetAnimatedSpriteFrameSize2(Mickey,84,62,0,0,252,248)
    ML_SetSpriteColorKeyFromPoint(Mickey,0,0)
    ML_SetAnimationSpeed(Mickey,10)
   

    '' creating line time to control animatiom timing
    ML_SetBaseTimeNow() '' must be called before creating time
    SplasTimer = ML_CreateNewTimeLine(0,2000)  ' give the splash 2 seconds to finish
    'ML_DisableCheckFireTime(SplasTimer)

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
    ''
        '' starting 2D drawing
        ML_UseOrthogonalView
        '' set the alpha blending factor
        ML_SetAlpha(1)
        '' srt the a white color
        ML_SetColor(255,255,255)
       
        ML_SetBlendMode(ALPHABLEND)
       
        ''
        ''   Splash stuff
        ''
        if(ML_CheckFireTime(SplasTimer)) then ' check if we inside the period of 2 seconds
            '' before we draw the sprite we must set it's texture
            ML_SetSpriteTexture(SplashImage)
            '' we divide our splash into small section
            dim as single stepwidth  = SplashImage->fullWidth/16
            dim as single stepHeight = SplashImage->fullHeight/16
            dim as integer y , x
            dim as single SCL
            for y = 0 to 15
                '' control the
                SCL = ML_GetDurationFromStart(SplasTimer)/1000 + y*0.03
                if (SCL > 1.0) then SCL = 1.0
                ML_SetScale(SCL,SCL)
                for x = 0 to 15
                    '' draw each part of sprite
                    ML_DrawPartOfSprite(SplashImage,stepwidth*(x+0.5),stepHeight*(y+0.5),_
                             stepwidth*x,stepHeight*y,stepwidth,stepHeight)
                next
            next
        end if
        '' tells OgreMagic that we
        '' finished our 2D stuff and
        '' must return to 3D world 
        ML_UsePerspectiveView

        ''
        '' using 3D world and shader to scrol chess
        ''
        if(ML_CheckEndFireTime(SplasTimer)) then ' is splash finished
            '' just as ML_UseOrthogonalView but with 3D world
            '' so we can use our sprites in 3D world
            ML_Use3DWorld()
            '' rotate the next drawing around x-x axis by 1.5 rdian angle
            ML_SetHorizontalRotation(1.5)
            const Scl = 1.5
            ML_SetScale(Scl,Scl*2 )
            '' tells OgerMagic to start using shader program
            ML_StartShaderProgram(ChessProgram)
            dim as single k =1.0-ML_GetDurationFromBaseTime()/3000.0
            '' pass a variable to shader program
            ML_SetPixelVariable(0,@k,1)
            '' set the sprite texture before drawing it
            ML_SetSpriteTexture(ChessImage)
            '' set the second texture and pass it to
            '' shader program for donig the effect
            ML_SetSpriteTexture(AlphaChess,1)
            dim as integer x
            for x = -3 to 3
            '' here the actual drawing of sprite
            ML_Draw3DSprite(ChessImage,x*32*Scl,-60,200)
            next
            '' we do our chess effect so we do not want to
            '' use the chess shader program any more
            ML_StopShaderProgram()
           
            '' we finished our 3D render
            ML_StopUsing3DWorld()

            ML_UseOrthogonalView
           
            ' 3D stars field
            ML_SetScale(1.5,1.5)
            ML_SetSpriteTexture(starBOB)
            dim i
            for I=0 to StarCount-1
                dim as uinteger SX,SY,b
                Stars(I)->z-=Stars(I)->zv
                SX=(Stars(I)->x/Stars(I)->z*100+SCREEN_WIDTH/2)
                SY=(Stars(I)->y/Stars(I)->z*100+SCREEN_HEIGHT/2)
                if(SX<0 or SY<0 or SX>=SCREEN_WIDTH or SY>=SCREEN_HEIGHT or Stars(I)->z<1) then
                    Stars(I)->x  = rnd()*1000-500
                    Stars(I)->y  = rnd()*1000-500
                    Stars(I)->z  = 100+rnd()*900
                    Stars(I)->zv = 0.5+(rnd()*45)/10
                else
                    b=(255-(Stars(I)->z*(255.0/1000.0)))
                    ML_SetColor(b,b,b)
                    ML_SetAlpha(0.0015*b)
                    ML_DrawSprite(starBOB,SX,SY)
                end if
            next

            ML_UsePerspectiveView
        end if

       
       
''
'' 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: Source Code for Intro Inferno Promo.
« Reply #16 on: February 27, 2007 »
This is looking really nice. You have got the colours right too as far as I can see :)
I had my doubts that you'd be able to port this easily at first as it is a hell of a lot of work, but fair play to you, it is coming along very nice and I think you'll probably do a good job of this.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #17 on: February 28, 2007 »
thanks shocky.

i am glad to hear this words , but remmember that you are a Genius programmer for doing a 3D software render in FreeBasic.

about the Victor Bob , i really have 2 Choice to make it , the first is to do it as you did , and the second to render it to Off Screen then use it as a 3D sprite which is more faster than Vector stuff.

any way i will keep testing and let you know the results




Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: Source Code for Intro Inferno Promo.
« Reply #18 on: February 28, 2007 »
 Hi  shocky

I have made a littlie change to your demo , so I  used  the font that found in your purebasic demo with Sip demo.

Download the update here and copy them to your OgreMagic folder in your computer

SipDemo

Here is the source code , and I think I will stop porting this demo for the next few days.

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  SIPDemo
''        Date    :  27/02/2007
''        Purpose :  wrettin by Shockwave for FreeBasic.
''                   ported to OgreMagic by Emil Halim.
''
''       website  :  http://www.freewebs.com/ogremagic/index.htm
''
''       link     :  http://dbfinteractive.com/index.php?topic=1422.0
''
''------------------------------------------------------------------------------
OPTION EXPLICIT

#include once "windows.bi"
#include once "win/d3d9.bi"
#include once "win/d3dx9.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 TimeLineData    ptr  SplasTimer     ' we want splash to stay only 2 seconds   
dim shared as SpriteData      ptr  SplashImage    ' holds pointer to splash Sprite structure
dim shared as SpriteData      ptr  ChessImage     ' holds pointer to chess Sprite structure
dim shared as SpriteData      ptr  AlphaChess     ' holds the alpha value
dim shared as HLSLProgramData ptr  ChessProgram   ' shader program to scroll the chess
dim shared as SpriteData      ptr  starBOB 

'' 3D star field
    #define StarCount 150
    #define SCREEN_WIDTH 625
    #define SCREEN_HEIGHT 450
    type STAR3D
         x   as single
         y   as single
         z   as single
         zv  as single
    end type

dim shared as STAR3D Stars(0 to StarCount)
dim shared as BitmapFontData  ptr font


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

    '' create camera
    dim as D3DXMATRIXA16 mView , Projection
    dim as D3DXVECTOR3 Eye , LookAt , Up
     Eye->x = 0.0
     Eye->y = 0.0
     Eye->Z =-1.0
     LookAt->x = 0.0
     LookAt->y = 0.0
     LookAt->Z = 0.0
     Up->x = 0.0
     Up->y = 1.0
     Up->Z = 0.0
       
    D3DXMatrixLookAtLH(@mView, @Eye, @LookAt, @Up)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_VIEW, @mView)
    D3DXMatrixPerspectiveFovLH(@Projection, 1.0f, 480/640, 0.0f, 500.0f)
    IDirect3DDevice9_SetTransform(g_pd3dDevice, D3DTS_PROJECTION, @Projection)
   
    '' Initial Magic Library here
    InitialMagicLibrary(g_pd3dDevice,640, 480)
   
    '' tells OgreMagic that from where it will load resources 
    ML_SetMediaDirectory("../SipMedia/")

    '' load splash sprite
    SplashImage = ML_LoadStaticSprite("intro.bmp")

    '' create an empty sprite , we will edit it
    ChessImage = ML_CreateStaticSprite(32,256)
    '' lock the Sprite texture intrnally for editing
    '' and save a pointer to the buffer that uesed with editing function
    ML_StartDrawingToSprite(ChessImage)
    '' fill the sprite buffer with 0 value
    ML_ClearDrawingArea(0)
    dim as integer white , blue
    dim as integer i ,j , w
    for j=0 to 15 step 2
      for i=0 to 15
        for w = 0 to 15
           white = rgb(111,111,223)
           blue  = rgb(13,13,111)
           ML_WriteRGBAChannels(w   ,(j*16)+ i    ,white)
           ML_WriteRGBAChannels(w   ,(j*16)+(i+16),blue )
           ML_WriteRGBAChannels(w+16,(j*16)+ i    ,blue )
           ML_WriteRGBAChannels(w+16,(j*16)+(i+16),white)
         next
      next
    next
    '' unlock the Sprite texture
    ML_StopDrawingToSprite(ChessImage)

    '' creating alpha sprite
    AlphaChess = ML_CreateStaticSprite(1,256)
    ML_StartDrawingToSprite(AlphaChess)
    for j=0 to 255
        ML_WriteAlphaChannel(0,j,j)
    next
    ML_StopDrawingToSprite(AlphaChess)
     
    '' creating pixel shader program
    ChessProgram = ML_CreateHLSLProgram()
    ML_EditPixelProgram(ChessProgram)
    ML_AddToProgram("sampler2D tex0;                                          ")
    ML_AddToProgram("sampler2D tex1;                                          ")
    ML_AddToProgram("float k;                                                 ")
    ML_AddToProgram("float4  main(  float2 TexCoord : TEXCOORD0) : COLOR0     ")
    ML_AddToProgram("{                                                        ")
    ML_AddToProgram("       float4 Color;                                     ")
    ML_AddToProgram("       float2 coord = float2(TexCoord.x,TexCoord.y+k);   ")
    ML_AddToProgram("       float4 col   = tex2D( tex0, coord);               ")
    ML_AddToProgram("       float4 alpha = tex2D( tex1, TexCoord);            ")
    ML_AddToProgram("       Color        = float4( col.rgb,alpha.a);          ")
    ML_AddToProgram("       return Color;                                     ")
    ML_AddToProgram("}                                                        ")
    ML_CompilePixelProgram(ChessProgram,"main")
     
    ' creating star field bob
    dim clr,RG(0 to 6)
    RG(0)= 0
    RG(1)= RGBA(120, 90,120,255 )
    RG(2)= RGBA(150,110,150,255 )
    RG(3)= RGBA(190,150,190,255 )
    RG(4)= RGBA(210,180,210,255 )
    RG(5)= RGBA(240,230,240,255 )
    RG(6)= RGBA(250,250,250,255 )
    'restore  StarBobData
    starBOB = ML_CreateStaticSprite(8,8)
    ML_StartDrawingToSprite(starBOB)
    ML_ClearDrawingArea(0)
    for j=0 to 6
      for i=0 to 6
        read clr 
        ML_WriteRGBAChannels(i,j,RG(clr))
      next
    next
    ML_StopDrawingToSprite(starBOB)
   
    randomize timer
    for i=0 to StarCount-1
          Stars(i)->x  = rnd()*1000-500
          Stars(i)->y  = rnd()*1000-500
          Stars(i)->z  = rnd()*900+100
          Stars(i)->zv =(rnd()*45)/10+.5
    next

   
    ML_SetMediaDirectory("../MagicMedia/")
    font = ML_LoadBitmapFont("font/Font.png",32,33,32)
    ML_SetSpriteColorKeyFromPoint(font,0,0)
    ML_SetActiveBitmapFont(font)
 
    '' creating line time to control animatiom timing
    ML_SetBaseTimeNow() '' must be called before creating time
    SplasTimer = ML_CreateNewTimeLine(0,2000)  ' give the splash 2 seconds to finish
    'ML_DisableCheckFireTime(SplasTimer)

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
    ''
        '' starting 2D drawing
        ML_UseOrthogonalView
        '' set the alpha blending factor
        ML_SetAlpha(1)
        '' srt the a white color
        ML_SetColor(255,255,255)
       
        ML_SetBlendMode(ALPHABLEND)
       
        ''
        ''   Splash stuff
        ''
        if(ML_CheckFireTime(SplasTimer)) then ' check if we inside the period of 2 seconds
            '' before we draw the sprite we must set it's texture
            ML_SetSpriteTexture(SplashImage)
            '' we divide our splash into small section
            dim as single stepwidth  = SplashImage->fullWidth/16
            dim as single stepHeight = SplashImage->fullHeight/16
            dim as integer y , x
            dim as single SCL
            for y = 0 to 15
                '' control the
                SCL = ML_GetDurationFromStart(SplasTimer)/1000 + y*0.03
                if (SCL > 1.0) then SCL = 1.0
                ML_SetScale(SCL,SCL)
                for x = 0 to 15
                    '' draw each part of sprite
                    ML_DrawPartOfSprite(SplashImage,stepwidth*(x+0.5),stepHeight*(y+0.5),_
                             stepwidth*x,stepHeight*y,stepwidth,stepHeight)
                next
            next
        end if
        '' tells OgreMagic that we
        '' finished our 2D stuff and
        '' must return to 3D world 
        ML_UsePerspectiveView

        ''
        '' using 3D world and shader to scrol chess
        ''
        if(ML_CheckEndFireTime(SplasTimer)) then ' is splash finished
            '' just as ML_UseOrthogonalView but with 3D world
            '' so we can use our sprites in 3D world
            ML_Use3DWorld()
            '' rotate the next drawing around x-x axis by 1.5 rdian angle
            ML_SetHorizontalRotation(1.5)
            const Scl = 1.5
            ML_SetScale(Scl,Scl*2 )
            '' tells OgerMagic to start using shader program
            ML_StartShaderProgram(ChessProgram)
            dim as single k =1.0-ML_GetDurationFromBaseTime()/3000.0
            '' pass a variable to shader program
            ML_SetPixelVariable(0,@k,1)
            '' set the sprite texture before drawing it
            ML_SetSpriteTexture(ChessImage)
            '' set the second texture and pass it to
            '' shader program for donig the effect
            ML_SetSpriteTexture(AlphaChess,1)
            dim as integer x
            for x = -3 to 3
            '' here the actual drawing of sprite
            ML_Draw3DSprite(ChessImage,x*32*Scl,-60,200)
            next
            '' we do our chess effect so we do not want to
            '' use the chess shader program any more
            ML_StopShaderProgram()
           
            dim as single rot
            rot = ML_GetDurationFromBaseTime()/3000.0
            ML_SetHorizontalRotation(0)
            ML_SetVerticalRotation(rot)
            ML_SetSpriteTexture(font)
            ML_Draw3DString("WELCOME",-10,-300,1000)
            ML_SetVerticalFlip(true)
            ML_SetAlpha(0.0,TopLeft) 
            ML_SetAlpha(0.0,TopRight) 
            ML_SetAlpha(0.6,BottomLeft) 
            ML_SetAlpha(0.6,BottomRight) 
            ML_Draw3DString("WELCOME",-10,-410,1000)
            ML_SetVerticalFlip(false) 
            ML_SetVerticalRotation(0)
           
            '' we finished our 3D render
            ML_StopUsing3DWorld()

            ML_UseOrthogonalView
           
            ' 3D stars field
            ML_SetScale(1.5,1.5)
            ML_SetSpriteTexture(starBOB)
            dim as integer i
            for I=0 to StarCount-1
                dim as uinteger SX,SY,b
                Stars(I)->z-=Stars(I)->zv
                SX=(Stars(I)->x/Stars(I)->z*100+SCREEN_WIDTH/2)
                SY=(Stars(I)->y/Stars(I)->z*100+SCREEN_HEIGHT/2)
                if(SX<0 or SY<0 or SX>=SCREEN_WIDTH or SY>=SCREEN_HEIGHT or Stars(I)->z<1) then
                    Stars(I)->x  = rnd()*1000-500
                    Stars(I)->y  = rnd()*1000-500
                    Stars(I)->z  = 100+rnd()*900
                    Stars(I)->zv = 0.5+(rnd()*45)/10
                else
                    b=(255-(Stars(I)->z*(255.0/1000.0)))
                    ML_SetColor(b,b,b)
                    ML_SetAlpha(0.0015*b)
                    ML_DrawSprite(starBOB,SX,SY)
                end if
            next
       
            ML_UsePerspectiveView
        end if

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

StarBobData:
    DATA 0,0,1,1,1,0,0
    DATA 0,2,3,4,5,4,0
    DATA 1,2,2,5,6,5,1
    DATA 1,3,1,4,5,4,1
    DATA 1,4,2,1,2,3,1
    DATA 0,2,4,3,2,2,0
    DATA 0,0,1,1,1,0,0


Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: Source Code for Intro Inferno Promo.
« Reply #19 on: February 28, 2007 »
It's nice and all, but if you want to achieve a perect conversion, the starfield needs to be wider, they are all concentrated in the center of the screen at the moment, also the stars need to be reflected in the chessfloor. The logo on the chessfloor should be made out of vectorballs, but I understand that it would probably take you longer to convert this intro that it did for me to write it.

You've done a great job in what you've done so far Emil and I will certainly be adding you to my greetings list if I ever get the damn thing I am working on at the moment finished.

Have some positive Karma and keep on with the converting (even if you need a break for a few days!!)
Shockwave ^ Codigos
Challenge Trophies Won: