Author Topic: ResterDemo / OgreMagic  (Read 3795 times)

0 Members and 1 Guest are viewing this topic.

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
ResterDemo / OgreMagic
« on: February 28, 2007 »
Hi shocky.

just for fun, here is the source code of raster demo that was written by you for Cobra

i have ported to OgreMagic , please i want you to make a FPS comparison and tell us.

Code: [Select]
''------------------------------------------------------------------------------
''
''              Magic Library For Ogre
''                beta version 0.40
''                  by Emil Halim
''
''        Name    :  RASTER EFFECT Demo
''        Date    :  28/02/2007
''        Purpose :  written by BY SHOCKWAVE
''                   for Cobra language
''                   ported to OgreMagic by Emil Halim
''
''       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   Rester
dim shared as HLSLProgramData      ptr   HLSLProgram  

''-----------------------------------------------------------------------------
'' 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/")
    
    Rester = ML_CreateStaticSprite(1,480)    
    
    HLSLProgram = ML_CreateHLSLProgram()
    ML_EditPixelProgram(HLSLProgram)                              
    ML_AddToProgram("sampler2D tex0;                                                                    ")
    ML_AddToProgram("float GADD,GADD2,GADD3;                                                            ")
    ML_AddToProgram("float4   main(  float2 TexCoord : TEXCOORD0) : COLOR0                              ")
    ML_AddToProgram("{                                                                                  ")
    ML_AddToProgram("    float4 col0 = tex2D( tex0, TexCoord);                                          ")
    ML_AddToProgram("    float  y = TexCoord.y *10;                                                     ")
    ML_AddToProgram("    float RD = (125+((sin(y+GADD3)*50)+(cos(y+GADD2)*50)-(sin(y+GADD)*24)))/255.0; ")
    ML_AddToProgram("    float GR = (125+((sin(y+GADD2)*50)+(cos(y+GADD)*50)+(sin(y+GADD3)*24)))/255.0; ")
    ML_AddToProgram("    float BL = (125+((sin(y+GADD)*50)-(cos(y+GADD3)*50)-(sin(y+GADD2)*24)))/255.0; ")
    ML_AddToProgram("    return  float4(RD,GR,BL,1);                                                    ")
    ML_AddToProgram("}                                                                                  ")
    ML_CompilePixelProgram(HLSLProgram,"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)
        
        ML_SetScale(640,1)
        static as single GADD,GADD2,GADD3
        GADD  += 0.01
        GADD2 += 0.02
        GADD3 += 0.03
        ML_SetPixelVariable(0,@GADD,1)
        ML_SetPixelVariable(1,@GADD2,1)
        ML_SetPixelVariable(2,@GADD3,1)
        ML_StartShaderProgram(HLSLProgram)  
        ML_DrawSprite(Rester,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 )

« Last Edit: February 28, 2007 by Emil_halim »

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: ResterDemo / OgreMagic
« Reply #1 on: March 01, 2007 »
I'd love to mate, but this won't compile. It cant find magiclibrary.bi. Sorry.
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: ResterDemo / OgreMagic
« Reply #2 on: March 01, 2007 »
you will find it in greMagic/inc folder, so please copy it to Freebasic/inc folder , also the "LibOgreMagic.dll.a" you will find it in OgreMagic/Libs so copy it to Freebasic/lib/win/ .

BTW this instruction is included in help file under instalation section.

 

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: ResterDemo / OgreMagic
« Reply #3 on: March 01, 2007 »
It still dies.
Exe please.

Fails on this line;

Code: [Select]
declare function ML_GetTextLength cdecl alias "ML_GetTextLength" (byval text as zstring ptr, byval BitmapFont as BitmapFontData ptr=ActiveFont) as single

Expected constant, found ")"

I have made sure that both those files were in the right places. I am using an older version of Fb, don't kniow whether this library needs the newest version?
I don't really want to update, the reason being that I supply intros to some groups, they need to be able to easily edit the scrolls, and the people using these intros have no programming knowledge. To this end I have made a version of fb without the ide and a batch file to compile the intro. I managed to get the whole package down to less than 1mb. I am afraid that if I update my version of FB then I will have to go through all the hassle of working out which things I need to include in my "self assembly kit", probably there would be no changes but for me, I would probably never use a library like this in the things I do, hardware stuff just isn't the sort of thing I write.

This library will be of a lot of use to the other people here who like to be able to load images easily and possibly even write games.

What I am suggesting is that maybe an installer to properly install this lib would be an idea when you have it nearly finished.

The other thing is that it's going to be faster than cobra, I can guarantee that, you are using hardware to draw these lines, I used the pure2d module in Cobra, Graham did a test using hardware and it ran at about 1500 fps. I hope that helps :)

I still want to see this in action though, so how about a step by step guide to cleanly installing the ogermagic lib? Or even better still a program to do it for the average user (who won't have a clue how to do this! Please bear in mind that these easy commands will appeal to new programmers at first).
Shockwave ^ Codigos
Challenge Trophies Won:

Offline Emil_halim

  • Atari ST
  • ***
  • Posts: 248
  • Karma: 21
    • View Profile
    • OgreMagic Library
Re: ResterDemo / OgreMagic
« Reply #4 on: March 01, 2007 »

ok , shocky , your suggestion looks good , i will make it.

BTW , i am using version FB 0.16 .

about the speed of FPS , just i want to tell you that , may be it has not higher FPS because it has not optimized yet.

any way thank you for spending the time for test trying, just keep doing an other effect , and i will port them. :) 

Offline Shockwave

  • good/evil
  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 17409
  • Karma: 498
  • evil/good
    • View Profile
    • My Homepage
Re: ResterDemo / OgreMagic
« Reply #5 on: March 01, 2007 »
Ah, maybe it's because I haven't updated my version of FB then Emil.

I will keep on making effects for you to test :) I would like to say that the work you are putting into your lib is absolutely fantastic, thank you for spending your time to make such a cool extension for no money, just the love of it and for the benefit of others.

You are a rare type of person and the world would be a better place if there were more like you, fortunately I can think of at least 10 people who think the same way as you on this one board. We are lucky :)
Shockwave ^ Codigos
Challenge Trophies Won: