freebasic.net Forum Index
FreeBASIC's Official Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log inLog in

FB HGEWrapper 2D Game Engine
Goto page 1, 2, 3, 4, 5  Next
 
Post new topic   Reply to topic    freebasic.net Forum Index -> Libraries
View previous topic :: View next topic  
Author Message
Dalex

PostPosted: Oct 14, 2007 13:22    Post subject: FB HGEWrapper 2D Game Engine Reply with quote

HgeWrapper for FreeBasic(0.18.2) (Win32)

(HGE version 1.8) doc:http://hge.relishgames.com/doc/index.html
==================
Actual:Version 0.1.7
==================
hge_System
hge_Gfx
hge_Ini
hge_Input
hge_Texture
hge_Timer
hge_Random
hge_Resource
hge_Sprite
hge_Font
hge_Music
hge_Channel
hge_Effect
hge_Target
hge_ParticleSystem
hge_ParticleManager
hge_DistortionMesh
hge_Animation
hge_GUI
hge_StringTable
hge_Rect
hge_Vector
2DPhysics
==================
Status: 312 Function
==================
Site: http://dalex.ucoz.ru/
==================
source code
hge.dll
bass.dll
HgeWrapper.dll
HgeWrapper.bi
HgeType.bi
libHgeWrapper.a
FBhge_tut01.bas - Minimal HGE application.
FBhge_tut02.bas - Using input, sound and rendering.
FBhge_tut03.bas - Using helper classes.
FBhge_tut04.bas - Using render targets.
FBhge_tut05.bas - Using distortion mesh.
FBhge_tut06.bas - Creating menus.
FBhge_tut07.bas - Thousand of Hares.
FBhge_tut09.bas - 2DPhysics ,Body,Joint,Car
==================
Static lib project http://dalex.ucoz.ru/load/4-1-0-6
==================
Please test...


Last edited by Dalex on Dec 18, 2007 13:32; edited 14 times in total
 
Back to top
View user's profile Send e-mail Visit poster's website
duke4e
Sr. Member
PostPosted: Oct 14, 2007 14:55    Post subject: Reply with quote

Works good, but there are still much things to do, like hgecolor, hgeparticle... Also you're missing tons of system constants (like HGE_SHOWSPLASH, etc...)

Damn, I just wish this turns out into complete HGE wrapper and keeps up with upcoming updates...


Anyways, nice work so far...
 
Back to top
View user's profile Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
v1ctor
Site Admin
PostPosted: Oct 14, 2007 18:19    Post subject: Reply with quote

Cool library, didn't know about it (or rather, it wasn't OSS when i checked it ages ago). It's nice how you can define a fixed FPS and such.

I hope you will release the wrapper sources later so people can learn how to write a C++ wrapper and could keep updating it if you don't want to maintain it.

Btw, i noticed there's no import library. While LD will be able to find the symbols directly in the DLL, it takes much longer than when using an imp library.
 
Back to top
View user's profile Visit poster's website MSN Messenger
livewire

PostPosted: Oct 15, 2007 1:59    Post subject: Reply with quote

Works great. I was able to port the Tutorial number 2 to FreeBASIC very easily. Could you post the source to the wrapper?

Code:
#Include "HgeWrapper.bi"

Declare Function FrameFunc() As Integer
Declare Function RenderFunc() As Integer
Declare Sub Boom()
Declare Sub Main()

Dim Shared As Long   fnt
Dim Shared As Long   tex1
Dim Shared As Long   tex2
Dim Shared As Long   spr1
Dim Shared As Long   spr2
Dim Shared As String FPS

Dim Shared quad As hgeQuad
Dim Shared snd As HEFFECT
Dim Shared As Single x,y
Dim Shared As Single dx,dy
Const speed As Single = 90
Const friction As Single = 0.98

Main()

Sub Boom()
    Dim pan As Integer
    Dim pitch As Single
   
    pan = Cast(Integer,(x-400)/4)
        pitch = (dx*dx + dy*dy) * 0.0005 + 0.2
        hge_Effect_PlayEx(snd,100,pan,pitch,0)
End Sub

Function FrameFunc() As Integer
    Dim dt As Single
    dt = hge_Timer_GetDelta()
   
        If (hge_Input_GetKeyState(HGEK_ESCAPE)) Then Return 1
        If (hge_Input_GetKeyState(HGEK_LEFT)) Then dx-=speed*dt
        If (hge_Input_GetKeyState(HGEK_RIGHT)) Then dx+=speed*dt
        If (hge_Input_GetKeyState(HGEK_UP)) Then dy-=speed*dt
        If (hge_Input_GetKeyState(HGEK_DOWN)) Then dy+=speed*dt
   
        dx*=friction
    dy*=friction
    x+=dx
    y+=dy
   
        If (x>784) Then
        x=784-(x-784)
        dx=-dx
        boom()
    End If
        If (x<16) Then
        x=16+16-x
        dx=-dx
        boom()
    End If
        If (y>584) Then
        y=584-(y-584)
        dy=-dy
        boom()
    End If
        If (y<16) Then
        y=16+16-y
        dy=-dy
        boom()
    End If
   
        quad.v(0).x=x-16
    quad.v(0).y=y-16
        quad.v(1).x=x+16
    quad.v(1).y=y-16
        quad.v(2).x=x+16
    quad.v(2).y=y+16
        quad.v(3).x=x-16
    quad.v(3).y=y+16
   
        Return 0
End Function

Function RenderFunc() As Integer
        hge_Gfx_BeginScene()
        hge_Gfx_Clear(0)
        hge_Gfx_RenderQuad(@quad)
        hge_Gfx_EndScene()
        Return 0
End Function

Sub Main()
    Dim i As Integer
   
    hge_Create(hge_VERSION)
    hge_System_SetStateString(HGE_LOGFILE, "hge_tut02.log")
        hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
        hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
    hge_System_SetStateString(HGE_TITLE, "HGE Tutorial 02 - Using input, sound and rendering")
        hge_System_SetStateBool(HGE_WINDOWED, 1)
        hge_System_SetStateInt(HGE_SCREENWIDTH, 800)
        hge_System_SetStateInt(HGE_SCREENHEIGHT, 600)
        hge_System_SetStateInt(HGE_SCREENBPP, 32)
   
    If (hge_System_Initiate()) Then
        snd = hge_Effect_Load("menu.wav",0)
        quad.tex = hge_Texture_Load("particles.png")
       
        If (snd = 0) Or (quad.tex = 0) Then
            MessageBox(NULL,"Can't load MENU.WAV or PARTICLES.PNG","Error",MB_OK)
            hge_System_Shutdown()
            hge_Release()
            Return
        End If
       
        quad.blend = BLEND_ALPHAADD Or BLEND_COLORMUL Or BLEND_ZWRITE
       
        For i = 0 To 3
            quad.v(i).z = 0.5
            quad.v(i).col = &HFFFFA000
        Next
       
        quad.v(0).tx=96.0/128.0
        quad.v(0).ty=64.0/128.0
        quad.v(1).tx=128.0/128.0
        quad.v(1).ty=64.0/128.0
        quad.v(2).tx=128.0/128.0
        quad.v(2).ty=96.0/128.0
        quad.v(3).tx=96.0/128.0
        quad.v(3).ty=96.0/128.0
       
        hge_System_Start()
       
        hge_Texture_Free(quad.tex)
        hge_Effect_Free(snd)
    Else
        MessageBox(NULL, "", "Error", MB_OK )
    End If
   
    hge_System_Shutdown()
    hge_Release()
End Sub
 
Back to top
View user's profile AIM Address
Dalex

PostPosted: Oct 15, 2007 16:22    Post subject: Reply with quote

Well...
All thank you...
Continuation follows...
 
Back to top
View user's profile Send e-mail Visit poster's website
Dalex

PostPosted: Oct 15, 2007 21:35    Post subject: Reply with quote

Update Version 0.1.1b first post ...(+29 function)
There is problems...?
 
Back to top
View user's profile Send e-mail Visit poster's website
speedlemon

PostPosted: Oct 17, 2007 20:26    Post subject: Reply with quote

Hey Dalex,
Thanks for doing this project. It is very interesting.

I noticed a problem with hgetype.bi when I was trying to use the ARGB macro.. I realized that the whole color section of the header had the same issue, so I fixed it by changing it to the following:

Code:
#Define ARGB(a,r,g,b)  ((cast(dword,a) Shl 24)+(cast(dword,r) Shl 16)+(cast(dword,g) Shl 8)+cast(dword,b))
#Define GETA(col)      ((col) Shr 24)
#Define GETR(col)      (((col) Shr 16) & &hFF)
#Define GETG(col)      (((col) Shr 8) & &hFF)
#Define GETB(col)      ((col) & &hFF)
#Define SETA(col,a)    (((col) & &h00FFFFFF) + (cast(dword,a) Shl 24))
#Define SETR(col,r)    (((col) & &hFF00FFFF) + (cast(dword,r) Shl 16))
#Define SETG(col,g)    (((col) & &hFFFF00FF) + (cast(dword,g) Shl 8))
#Define SETB(col,b)    (((col) & &hFFFFFF00) + cast(dword,b))


There wasn't a function called 'dword'.
and
'<<' and '>>' should've been 'shl' and 'shr'.
and
on the last line of the snippet, you had 'word' when it should be 'dword' (unless you did 'word' for some reason, they used 'dword' in the hge docs)...

Thanks again,
Erik
 
Back to top
View user's profile Send e-mail
Dalex

PostPosted: Oct 19, 2007 18:51    Post subject: Reply with quote

Update Version 0.1.2b first post ...(+71 function)

P.S livewire, speedlemon... thank you...
 
Back to top
View user's profile Send e-mail Visit poster's website
duke4e
Sr. Member
PostPosted: Oct 20, 2007 7:56    Post subject: Reply with quote

thanks alot. if i'll have some free time, i'll translate few tutorials.

edit: found a bug. in tutorial 2 and 3 when ball hits the wall, pitch is always same while in c++ pitch varies.

edit 2: here's a a render target tutorial... seems like something isn't well translated or i have screwed something while translating.
Code:
'*************************************************
' FBhge_tut04 - Using render targets
'*************************************************

#Include  "inc/HgeType.bi"
#Include  "inc/HgeWrapper.bi"

Dim Shared As Long   spr
Dim Shared As Long   spt
Dim Shared As Long   tar
Dim Shared As Long   fnt
Dim Shared As Long   par
Dim Shared As Long   tex
Dim Shared As Long   snd
Dim Shared As Long   target
Dim Shared As hgeParticleSystemInfo  psi

Dim Shared As Single  x=100.0f
Dim Shared As Single  y=100.0f
Dim Shared As Single  dx=0.0f
Dim Shared As Single  dy=0.0f
Const As Single       speed=90
Const As Single       friction=0.98

Function GfxRestoreFunc() As Integer
        If(tar And target) Then
        hge_Sprite_SetTexture(tar,hge_Target_GetTexture(target))
    End If
        Return false
End Function

Sub Boom()   
    Dim As Integer pan = Int((x-256)/2.56f)
    Dim As Single pitch = pitch=(dx*dx+dy*dy)*0.0005f+0.2f
    hge_Effect_PlayEx(snd,100,pan,pitch,0)
End Sub

Function FrameFunc() As Integer
       
        Dim As Single dt=hge_Timer_GetDelta()
   
        ''Process keys
        If (hge_Input_GetKeyState(HGEK_ESCAPE))Then Return true
        If (hge_Input_GetKeyState(HGEK_LEFT))  Then dx-=speed*dt
        If (hge_Input_GetKeyState(HGEK_RIGHT)) Then dx+=speed*dt
        If (hge_Input_GetKeyState(HGEK_UP))    Then dy-=speed*dt
        If (hge_Input_GetKeyState(HGEK_DOWN))  Then dy+=speed*dt
   
        '' Do some movement calculations and collision detection       
        dx*=friction: dy*=friction: x+=dx: y+=dy
        If(x>784)Then x=784-(x-784):dx=-dx:boom()
        If(x<16) Then x=16+16-x:dx=-dx:boom()
        If(y>584)Then y=584-(y-584):dy=-dy:boom()
        If(y<16) Then y=16+16-y:dy=-dy:boom()   
   
    psi.nEmission=Int(dx*dx+dy*dy)
    hge_PartSys_SetInfo(par,psi)
    hge_PartSys_MoveTo(par,x,y)
    hge_PartSys_Update(par,dt)
   
        Return false
End Function

Function  RenderFunc()As  Integer
        hge_Gfx_BeginScene(target)
        hge_Gfx_Clear(0)
        hge_PartSys_Render(par)
        hge_Sprite_Render(spr,x,y)
    hge_Gfx_EndScene()
   

        hge_Gfx_BeginScene()
        hge_Gfx_Clear(0)
        For i As Integer = 0 To 5
                hge_Sprite_SetColor(tar, &hFFFFFF Or (((5-i)*40+55) Shl 24))
        hge_Sprite_RenderEx(tar, i*100.0f, i*50.0f, i*M_PI/8, 1.0f-i*0.1f)
        Next
   
    hge_Gfx_EndScene()
    Return 0
End  Function

hge_Create(hge_VERSION)
hge_System_SetStateInt(hge_SHOWSPLASH, 0)
hge_System_SetStateString(HGE_LOGFILE, "FBhge_tut04.log")
hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
hge_System_SetStateFunc(HGE_GFXRESTOREFUNC, @GfxRestoreFunc)
hge_System_SetStateString(HGE_TITLE, "FreeBasic-HGE Tutorial 04 - Using render targets")
hge_System_SetStateInt(HGE_FPS, 100)
hge_System_SetStateBool(HGE_WINDOWED, true)
hge_System_SetStateInt(HGE_SCREENWIDTH, 800)
hge_System_SetStateInt(HGE_SCREENHEIGHT, 600)
hge_System_SetStateInt(HGE_SCREENBPP, 32)


If (hge_System_Initiate()) Then
    snd = hge_Effect_Load("Res/menu.wav",0)
    tex = hge_Texture_Load("Res/particles.png")
   
    If (snd = 0) Or (tex = 0) Then
        MessageBox(NULL,"Can't load MENU.WAV or PARTICLES.PNG","Error",MB_OK)
        hge_System_Shutdown()
        hge_Release()
    End If
   
   
   
    spr = hge_Sprite(tex, 96, 64, 32, 32)
    hge_Sprite_SetColor(spr,&hFFFFA000)
    hge_Sprite_SetHotSpot(spr,16,16)
   
    spt=hge_Sprite(tex, 32, 32, 32, 32)
    hge_Sprite_SetBlendMode(spt,BLEND_COLORMUL Or BLEND_ALPHAADD Or BLEND_NOZWRITE)
    hge_Sprite_SetHotSpot(spt,16,16)
    par = hge_PartSys("Res/trail.psi",spt)
    hge_PartSys_GetInfo(par,psi)
    hge_PartSys_Fire(par)
   
    tar=hge_Sprite(hge_Target_GetTexture(target),0,0,512,512)

    hge_System_Start()
       
    hge_Texture_Free(target)
    hge_Texture_Free(tex)
    hge_Effect_Free(snd)
End If

hge_System_Shutdown()
hge_Release()


edit 3: here's a not working distortion mesh tutorial
Code:
'*************************************************
' FBhge_tut05 - Using distortion mesh
'*************************************************

#Include  "inc/HgeType.bi"
#Include  "inc/HgeWrapper.bi"

Dim Shared As Long   tex 'htexture
Dim Shared As Long   dis 'hgeDistortionMesh
Dim Shared As Long   fnt 'hgeFont

Const nRows=16
Const nCols=16
Const As Single cellw=512.0f/(nCols-1)
Const As Single cellh=512.0f/(nRows-1)

Const As Single meshx=144
Const As Single meshy=44

Dim Shared As String FPS


Function FrameFunc() As Integer
       
        Dim As Single dt=hge_Timer_GetDelta()
    Static As Single t = 0.0f
    Static As Integer trans = 0
   
        Dim As Integer i, j, col
        Dim As Single r, a, dx, dy
        t += dt
   
        ' Process keys
        Select Case hge_Input_GetKey
                Case HGEK_ESCAPE
                        Return true
           
        Case HGEK_SPACE
            trans += 1
                        If trans > 2 Then trans=0
            'hge_DistortionMesh_Clear(dis, &hFF000000, 0)
    End Select
   
        ' Calculate new displacements and coloring for one of the three effects
        Select Case trans
                Case 0
            For i = 1 To nRows - 2
                For j = 1 To nCols - 2
                    hge_DistortionMesh_SetDisplacement(dis, j,i,Cos(t*10+(i+j)/2)*5,Sin(t*10+(i+j)/2)*5,HGEDISP_NODE)
                Next
            Next
           
        Case 1
            For i = 0 To nRows - 1
                For j = 0 To nCols - 1
                    hge_DistortionMesh_SetDisplacement(dis, j,i,Cos(t*5+j/2)*15,0,HGEDISP_NODE)
                    col=Int((Cos(t*5+(i+j)/2)+1)*35)
                    hge_DistortionMesh_SetColor(dis, j,i,&hFF Shl 24 Or col Shl 16 Or col Shl 8 Or col)
                Next
            Next
           
        Case 2
            For i = 0 To nRows - 1
                For j = 0 To nCols - 1
                    r=Sqr(((j-nCols/2)*(j-nCols/2)) + (i-nRows/2)*(i-nRows/2))
                    a=r*Cos(t*2)*0.1f
                    dx=Sin(a)*(i*cellh-256)+Cos(a)*(j*cellw-256)
                    dy=Cos(a)*(i*cellh-256)-Sin(a)*(j*cellw-256)
                    hge_DistortionMesh_SetDisplacement(dis, j,i,dx,dy,HGEDISP_CENTER)
                    col=Int((Cos(r+t*4)+1)*40)
                    hge_DistortionMesh_SetColor(dis, j,i, &hFF Shl 24 Or col Shl 16 Or (col/2) Shl 8)
                Next
            Next
           
    End Select
   
        Return false
End  Function

Function  RenderFunc()As  Integer
        hge_Gfx_BeginScene()
        hge_Gfx_Clear(0)
    hge_DistortionMesh_Render(dis, meshx, meshy)
   
        FPS = Str(hge_Timer_GetFPS())
        hge_Font_SetColor(fnt,Rgb(255,255,255))
    hge_Font_Render(fnt,6, 6, HGETEXT_LEFT, "FPS: " + FPS)
    hge_Font_Render(fnt,6, 58, HGETEXT_LEFT, "Use your")
    hge_Font_Render(fnt,6, 84, HGETEXT_LEFT, "SPACE")
    hge_Gfx_EndScene()
    Return 0
End  Function

hge_Create(hge_VERSION)
hge_System_SetStateString(HGE_LOGFILE, "FBhge_tut05.log")
hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
hge_System_SetStateString(HGE_TITLE, "FreeBasic-HGE Tutorial 05 - Using distortion mesh")
hge_System_SetStateBool(HGE_WINDOWED, true)
hge_System_SetStateInt(HGE_SCREENWIDTH, 800)
hge_System_SetStateInt(HGE_SCREENHEIGHT, 600)
hge_System_SetStateInt(HGE_SCREENBPP, 32)
hge_System_SetStateInt(HGE_USESOUND, false)


If (hge_System_Initiate()) Then
    tex = hge_Texture_Load("Res/texture.jpg")
   
    If tex = 0 Then
        MessageBox(NULL,"Can't load TEXTURE.JPG","Error",MB_OK)
        hge_System_Shutdown()
        hge_Release()
    End If
   
        hge_DistortionMesh(dis, nCols, nRows)
    hge_DistortionMesh_SetTexture(dis, tex)
    hge_DistortionMesh_SetTextureRect(dis,0,0,512,512)
    hge_DistortionMesh_SetBlendMode(dis, BLEND_COLORADD Or BLEND_ALPHABLEND Or BLEND_ZWRITE)
    hge_DistortionMesh_Clear(dis, &hFF000000, 0)
   
    fnt = hge_Font("Res/font1.fnt",0)
    hge_System_Start()
       
    hge_Texture_Free(tex)
End If

hge_System_Shutdown()
hge_Release()


edit 4: and finally a working tutorial (7)
Code:
'*************************************************
' FBhge_tut07 - Thousand of Hares
'*************************************************

#Include  "inc/HgeType.bi"
#Include  "inc/HgeWrapper.bi"

#undef Color
#define SCREEN_WIDTH  800
#define SCREEN_HEIGHT 600

#define MIN_OBJECTS        100
#define MAX_OBJECTS 2000

Type sprObject
        As Single x,y
        As Single dx,dy
        As Single scale,rot
        As Single dscale,drot
        As DWORD Color
End Type

Dim Shared As sprObject pObjects(MAX_OBJECTS)
Dim Shared As Integer nObjects
Dim Shared As Integer nBlend

Dim Shared As Long   tex, bgtex
Dim Shared As Long   spr, bgspr
Dim Shared As Long   fnt

Sub SetBlend(blend As Integer)
        Static As Integer sprBlend(5) = _
    {_
                BLEND_COLORMUL Or BLEND_ALPHABLEND Or BLEND_NOZWRITE,_
                BLEND_COLORADD Or BLEND_ALPHABLEND Or BLEND_NOZWRITE,_
                BLEND_COLORMUL Or BLEND_ALPHABLEND Or BLEND_NOZWRITE,_
                BLEND_COLORMUL Or BLEND_ALPHAADD   Or BLEND_NOZWRITE,_
                BLEND_COLORMUL Or BLEND_ALPHABLEND Or BLEND_NOZWRITE _
        }
   
        Static As DWORD fntColor(5)= {&hFFFFFFFF, &hFF000000, &hFFFFFFFF, &hFF000000, &hFFFFFFFF}

        Static As DWORD sprColors(5, 5) = _
        {_
                { &hFFFFFFFF, &hFFFFE080, &hFF80A0FF, &hFFA0FF80, &hFFFF80A0 }, _
                { &hFF000000, &hFF303000, &hFF000060, &hFF006000, &hFF600000 }, _
                { &h80FFFFFF, &h80FFE080, &h8080A0FF, &h80A0FF80, &h80FF80A0 }, _
                { &h80FFFFFF, &h80FFE080, &h8080A0FF, &h80A0FF80, &h80FF80A0 }, _
                { &h40202020, &h40302010, &h40102030, &h40203010, &h40102030 } _
        }

        If blend > 4 Then blend=0
        nBlend=blend

        hge_Sprite_SetBlendMode(spr, sprBlend(blend))
    hge_Font_SetColor(fnt, fntColor(blend))
        For i As Integer = 0 To MAX_OBJECTS - 1
        pObjects(i).color=sprColors(blend, hge_Random_Int(0,4))
    Next
End Sub





Dim Shared As String FPS


Function FrameFunc() As Integer
       
        Dim As Single dt=hge_Timer_GetDelta()
    Dim As Integer i
   
        ' Process keys
   
        Select Case hge_Input_GetKey
                Case HGEK_UP
            If nObjects < MAX_OBJECTS Then nObjects += 100
           
                Case HGEK_DOWN
            If nObjects > MIN_OBJECTS Then nObjects -= 100
               
        Case HGEK_SPACE
            nblend += 1
            SetBlend(nBlend)
           
                Case HGEK_ESCAPE
                        Return true
    End Select
   
        ' Update the scene
       
        For i = 0 To nObjects - 1
                pObjects(i).x+=pObjects(i).dx*dt
                If (pObjects(i).x>SCREEN_WIDTH Or pObjects(i).x<0) Then pObjects(i).dx=-pObjects(i).dx
       
                pObjects(i).y+=pObjects(i).dy*dt
                If (pObjects(i).y>SCREEN_HEIGHT Or pObjects(i).y<0) Then pObjects(i).dy=-pObjects(i).dy
       
                pObjects(i).scale+=pObjects(i).dscale*dt
                If (pObjects(i).scale>2 Or pObjects(i).scale<0.5) Then pObjects(i).dscale=-pObjects(i).dscale
               
        pObjects(i).rot+=pObjects(i).drot*dt
        Next

        Return false
End Function

Function RenderFunc() As Integer

        Dim As Integer i
       
        ' Render the scene
       
        hge_Gfx_BeginScene()
    hge_Sprite_Render(bgspr, 0, 0)
       
        For i = 0 To nObjects - 1
        hge_Sprite_SetColor(spr, pObjects(i).color)
        hge_Sprite_RenderEx(spr, pObjects(i).x, pObjects(i).y, pObjects(i).rot, pObjects(i).scale)
        Next
   
   
        FPS = Str(hge_Timer_GetFPS())
    hge_Font_SetColor(fnt,Rgb(255,255,255))
    hge_Font_Render(fnt, 7, 7, HGETEXT_LEFT, "UP and DOWN to adjust number of hares: " + Str(nObjects))
    hge_Font_Render(fnt, 7, 7 + 12, HGETEXT_LEFT, "SPACE to change blending mode: " + Str(nBlend))
    hge_Font_Render(fnt, 7, 7 + 24, HGETEXT_LEFT, "FPS: " + FPS)
   
   
   
    hge_Gfx_EndScene()
    Return false
End Function

hge_Create(hge_VERSION)
hge_System_SetStateString(HGE_LOGFILE, "FBhge_tut07.log")
hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
hge_System_SetStateString(HGE_TITLE, "FreeBasic-HGE Tutorial 07 - Thousand of Hares")
hge_System_SetStateInt(HGE_USESOUND, false)
hge_System_SetStateBool(HGE_WINDOWED, false)
hge_System_SetStateInt(HGE_SCREENWIDTH, SCREEN_WIDTH)
hge_System_SetStateInt(HGE_SCREENHEIGHT, SCREEN_HEIGHT)
hge_System_SetStateInt(HGE_SCREENBPP, 32)


If (hge_System_Initiate()) Then
    bgtex = hge_Texture_Load("Res/bg2.png")
    tex = hge_Texture_Load("Res/zazaka.png")
   
    If (bgtex = 0) Or (tex = 0) Then
        MessageBox(NULL,"Can't load BG2.PNG or ZAZAKA.PNG","Error",MB_OK)
        hge_System_Shutdown()
        hge_Release()
    End If
   
    fnt = hge_Font("Res/font2.fnt", 0)
 
    spr = hge_Sprite(tex, 0, 0, 64, 64)
    hge_Sprite_SetHotSpot(spr, 16, 16)


    bgspr = hge_Sprite(bgtex, 0, 0, 800, 600)
    hge_Sprite_SetBlendMode(bgspr, BLEND_COLORADD Or BLEND_ALPHABLEND Or BLEND_NOZWRITE)
    hge_Sprite_SetColor(bgspr, &hFF000000, 0)
    hge_Sprite_SetColor(bgspr, &hFF000000, 1)
    hge_Sprite_SetColor(bgspr, &hFF000040, 2)
    hge_Sprite_SetColor(bgspr, &hFF000040, 3)

    ' Initialize objects list

    nObjects=1000

    For i As Integer = 0 To MAX_OBJECTS - 1
        pObjects(i).x=hge_Random_Float(0,SCREEN_WIDTH)
        pObjects(i).y=hge_Random_Float(0,SCREEN_HEIGHT)
        pObjects(i).dx=hge_Random_Float(-200,200)
        pObjects(i).dy=hge_Random_Float(-200,200)
        pObjects(i).scale=hge_Random_Float(0.5f,2.0f)
        pObjects(i).dscale=hge_Random_Float(-1.0f,1.0f)
        pObjects(i).rot=hge_Random_Float(0,M_PI*2)
        pObjects(i).drot=hge_Random_Float(-1.0f,1.0f)
    Next
   
    SetBlend(0)
    hge_System_Start()
       
    hge_Texture_Free(bgtex)
    hge_Texture_Free(tex)
End If

hge_System_Shutdown()
hge_Release()
 
Back to top
View user's profile Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Dalex

PostPosted: Oct 20, 2007 20:24    Post subject: Reply with quote

duke4e thanks...

HgeWrapper.bi
Old function bug
Code:

Declare Function hge_DistortionMesh  Cdecl Alias  "hge_DistortionMesh" (Byval As Dword,Byval As Integer,Byval As Integer)As Long
 

HgeWrapper.bi
New function
Code:

Declare Function hge_DistortionMesh Cdecl Alias  "hge_DistortionMesh" (Byval As Integer,Byval As Integer)As Long
 




New Tutorial04
Code:
'*************************************************
' FBhge_tut04 - Using render targets
'*************************************************

#Include  "inc/HgeType.bi"
#Include  "inc/HgeWrapper.bi"

Dim Shared As Long   spr
Dim Shared As Long   spt
Dim Shared As Long   tar
Dim Shared As Long   fnt
Dim Shared As Long   par
Dim Shared As Long   tex
Dim Shared As Long   snd
Dim Shared As Long   target
Dim Shared As hgeParticleSystemInfo  psi
Dim Shared As String FPS
Dim Shared As Single dt

Dim Shared As Single  x=100.0f
Dim Shared As Single  y=100.0f
Dim Shared As Single  dx=0.0f
Dim Shared As Single  dy=0.0f
Const As Single       speed=90
Const As Single       friction=0.98

Function GfxRestoreFunc() As Integer
        If(tar And target) Then
        hge_Sprite_SetTexture(tar,hge_Target_GetTexture(target))
        End If
        Return false
End Function

Sub Boom()   
    Dim As Integer pan = Int((x-256)/2.56)
    Dim As Single pitch = pitch=(dx*dx+dy*dy)*0.0005+0.2
    hge_Effect_PlayEx(snd,100,pan,pitch,0)
End Sub

Function FrameFunc() As Integer
       
        dt=hge_Timer_GetDelta()
   
        ''Process keys
        If (hge_Input_GetKeyState(HGEK_ESCAPE))Then Return true
        If (hge_Input_GetKeyState(HGEK_LEFT))  Then dx-=speed*dt
        If (hge_Input_GetKeyState(HGEK_RIGHT)) Then dx+=speed*dt
        If (hge_Input_GetKeyState(HGEK_UP))    Then dy-=speed*dt
        If (hge_Input_GetKeyState(HGEK_DOWN))  Then dy+=speed*dt
   
        '' Do some movement calculations and collision detection       
        dx*=friction: dy*=friction: x+=dx: y+=dy
        If(x>496)Then x=496-(x-496):dx=-dx:boom()
        If(x<16) Then x=16+16-x:dx=-dx:boom()
        If(y>496)Then y=496-(y-496):dy=-dy:boom()
        If(y<16) Then y=16+16-y:dy=-dy:boom()   
   
        psi.nEmission=Int(dx*dx+dy*dy)
        hge_PartSys_SetInfo(par,psi)
        hge_PartSys_MoveTo(par,x,y)
        hge_PartSys_Update(par,dt)
   
        Return false
End Function

Function  RenderFunc()As  Integer
        hge_Gfx_BeginScene(target)
        hge_Gfx_Clear(0)
        hge_PartSys_Render(par)
        hge_Sprite_Render(spr,x,y)
        hge_Gfx_EndScene()
   
        FPS = Str(hge_Timer_GetFPS())
       
        hge_Gfx_BeginScene()
        hge_Gfx_Clear(0)
        For i As Integer = 0 To 5
                hge_Sprite_SetColor(tar, &hFFFFFF Or (((5-i)*40+55) Shl 24))
                hge_Sprite_RenderEx(tar, i*100.0f, i*50.0f, i*M_PI/8, 1.0f-i*0.1f)
        Next
        hge_Font_Render(fnt,5, 5, HGETEXT_LEFT, "FPS: "+FPS+"(constant)")
        hge_Font_Render(fnt,5, 35, HGETEXT_LEFT, "dt: "+wstr(dt))
        hge_Gfx_EndScene()
    Return 0
End  Function

hge_Create(hge_VERSION)
hge_System_SetStateInt(hge_SHOWSPLASH, 0)
hge_System_SetStateString(HGE_LOGFILE, "FBhge_tut04.log")
hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
hge_System_SetStateFunc(HGE_GFXRESTOREFUNC, @GfxRestoreFunc)
hge_System_SetStateString(HGE_TITLE, "FreeBasic-HGE Tutorial 04 - Using render targets")
hge_System_SetStateInt(HGE_FPS, 100)
hge_System_SetStateBool(HGE_WINDOWED,true)
hge_System_SetStateInt(HGE_SCREENWIDTH, 800)
hge_System_SetStateInt(HGE_SCREENHEIGHT, 600)
hge_System_SetStateInt(HGE_SCREENBPP, 32)


If (hge_System_Initiate()) Then
    snd = hge_Effect_Load("Res/menu.wav",0)
    tex = hge_Texture_Load("Res/particles.png")
   
    If (snd = 0) Or (tex = 0) Then
        MessageBox(NULL,"Can't load MENU.WAV or PARTICLES.PNG","Error",MB_OK)
        hge_System_Shutdown()
        hge_Release()
    End If
   
    fnt = hge_Font("Res/font1.fnt",0)
   
    spr = hge_Sprite(tex, 96, 64, 32, 32)
    hge_Sprite_SetColor(spr,&hFFFFA000)
    hge_Sprite_SetHotSpot(spr,16,16)
   
    spt=hge_Sprite(tex, 32, 32, 32, 32)
    hge_Sprite_SetBlendMode(spt,BLEND_COLORMUL Or BLEND_ALPHAADD Or BLEND_NOZWRITE)
    hge_Sprite_SetHotSpot(spt,16,16)
    par = hge_PartSys("Res/trail.psi",spt)
    hge_PartSys_GetInfo(par,psi)
    hge_PartSys_Fire(par)
   
    target=hge_Target_Create(512,512,false)
    tar=hge_Sprite(hge_Target_GetTexture(target),0,0,512,512)
        hge_Sprite_SetBlendMode(tar,BLEND_COLORMUL Or BLEND_ALPHAADD Or BLEND_NOZWRITE)

   

    hge_System_Start()
       
    hge_Target_Free(target)
    hge_Texture_Free(tex)
    hge_Effect_Free(snd)
End If

hge_System_Shutdown()
hge_Release()

New Tutorial05
Code:
'*************************************************
' FBhge_tut05 - Using distortion mesh
'*************************************************

#Include  "inc/HgeType.bi"
#Include  "inc/HgeWrapper.bi"

Dim Shared As Long   tex 'htexture
Dim Shared As Long   dis 'hgeDistortionMesh
Dim Shared As Long   fnt 'hgeFont

Const nRows=16
Const nCols=16
Const As Single cellw=512.0/(nCols-1)
Const As Single cellh=512.0/(nRows-1)

Const As Single meshx=144
Const As Single meshy=44

Dim Shared As String FPS


Function FrameFunc() As Integer
       
        Dim As Single dt=hge_Timer_GetDelta()
        Static As Single t = 0
        Static As Integer trans = 0
   
        Dim As Integer i, j, col
        Dim As Single r, a, dx, dy
        t += dt
   
        ' Process keys
        Select Case hge_Input_GetKey
               Case HGEK_ESCAPE
                    Return true
           
               Case HGEK_SPACE
                    trans += 1
                     If trans > 2 Then trans=0
            hge_DistortionMesh_Clear(dis, &hFF000000, 0)
       End Select
   
        ' Calculate new displacements and coloring for one of the three effects
        Select Case trans
                Case 0
            For i = 1 To nRows - 2
                For j = 1 To nCols - 2
                    hge_DistortionMesh_SetDisplacement(dis, j,i,Cos(t*10+(i+j)/2)*5,Sin(t*10+(i+j)/2)*5,HGEDISP_NODE)
                Next
            Next
           
        Case 1
            For i = 0 To nRows - 1
                For j = 0 To nCols - 1
                    hge_DistortionMesh_SetDisplacement(dis, j,i,Cos(t*5+j/2)*15,0,HGEDISP_NODE)
                    col=Int((Cos(t*5+(i+j)/2)+1)*35)
                    hge_DistortionMesh_SetColor(dis, j,i,&hFF Shl 24 Or col Shl 16 Or col Shl 8 Or col)
                Next
            Next
           
        Case 2
            For i = 0 To nRows - 1
                For j = 0 To nCols - 1
                    r=Sqr(((j-nCols/2)*(j-nCols/2)) + (i-nRows/2)*(i-nRows/2))
                    a=r*Cos(t*2)*0.1f
                    dx=Sin(a)*(i*cellh-256)+Cos(a)*(j*cellw-256)
                    dy=Cos(a)*(i*cellh-256)-Sin(a)*(j*cellw-256)
                    hge_DistortionMesh_SetDisplacement(dis, j,i,dx,dy,HGEDISP_CENTER)
                    col=Int((Cos(r+t*4)+1)*40)
                    hge_DistortionMesh_SetColor(dis, j,i, &hFF Shl 24 Or col Shl 16 Or (col/2) Shl 8)
                Next
            Next
           
    End Select
   
        Return false
End  Function

Function  RenderFunc()As  Integer
        hge_Gfx_BeginScene()
        hge_Gfx_Clear(0)
        hge_DistortionMesh_Render(dis, meshx, meshy)
   
        FPS = Str(hge_Timer_GetFPS())
        hge_Font_SetColor(fnt,Rgb(255,255,255))
        hge_Font_Render(fnt,6, 6, HGETEXT_LEFT, "FPS: " + FPS)
        hge_Font_Render(fnt,6, 58, HGETEXT_LEFT, "Use your")
        hge_Font_Render(fnt,6, 84, HGETEXT_LEFT, "SPACE")
        hge_Gfx_EndScene()
    Return 0
End  Function

hge_Create(hge_VERSION)
hge_System_SetStateString(HGE_LOGFILE, "FBhge_tut05.log")
hge_System_SetStateFunc(HGE_FRAMEFUNC, @FrameFunc)
hge_System_SetStateFunc(HGE_RENDERFUNC, @RenderFunc)
hge_System_SetStateString(HGE_TITLE, "FreeBasic-HGE Tutorial 05 - Using distortion mesh")
hge_System_SetStateBool(HGE_WINDOWED, true)
hge_System_SetStateInt(HGE_SCREENWIDTH, 800)
hge_System_SetStateInt(HGE_SCREENHEIGHT, 600)
hge_System_SetStateInt(HGE_SCREENBPP, 32)
hge_System_SetStateInt(HGE_USESOUND, false)


If (hge_System_Initiate()) Then
    tex = hge_Texture_Load("Res/texture.jpg")
   
    If tex = 0 Then
        MessageBox(NULL,"Can't load TEXTURE.JPG","Error",MB_OK)
        hge_System_Shutdown()
        hge_Release()
    End If
    fnt = hge_Font("Res/font1.fnt",0)
   
    dis=hge_DistortionMesh(nCols, nRows)
    hge_DistortionMesh_SetTexture(dis, tex)
    hge_DistortionMesh_SetTextureRect(dis,0,0,512,512)
    hge_DistortionMesh_SetBlendMode(dis, BLEND_COLORADD Or BLEND_ALPHABLEND Or BLEND_ZWRITE)
    hge_DistortionMesh_Clear(dis, &hFF000000, 0)
   
   
    hge_System_Start()
       
    hge_Texture_Free(tex)
End If

hge_System_Shutdown()
hge_Release()


good luck...
 
Back to top
View user's profile Send e-mail Visit poster's website
duke4e
Sr. Member
PostPosted: Oct 20, 2007 21:00    Post subject: Reply with quote

wow, this is becoming the most powerful FB gfx library EVER!

do you plan to release the sources once the library is completely translated? i'm planning to make a wrapper for your wrapper, to simlify things even more and to bring the commands closer to FBGFX users...
 
Back to top
View user's profile Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
v1ctor
Site Admin
PostPosted: Oct 21, 2007 2:57    Post subject: Reply with quote

To make LD (the GNU linker) use the import library instead of trying to look at the DLL's (what takes much longer), add this to the wrapper.bi file:

Code:
#libpath "lib"
#inclib "HgeWrapper"


To compile the examples included for anywhere else, the -p must be used or the wrapper.a file copied to the [fbc-dir]/lib/win32 path.
 
Back to top
View user's profile Visit poster's website MSN Messenger
Dalex

PostPosted: Oct 21, 2007 10:10    Post subject: Reply with quote

Update Version 0.1.3b first post ...(+41 function)


duke4e
Quote:
do you plan to release the sources once the library is completely translated?

Yes...

v1ctor thanks...
 
Back to top
View user's profile Send e-mail Visit poster's website
livewire

PostPosted: Oct 21, 2007 16:33    Post subject: Reply with quote

Excellent work Dalex. This will be a very useful library for the FB users.

-Livewire
 
Back to top
View user's profile AIM Address
Ryan
Sr. Member
PostPosted: Oct 22, 2007 3:46    Post subject: Reply with quote

Found this thread accidentally when searching for something else... super impressed and look forward to playing around with it. Thanks for posting!
 
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    freebasic.net Forum Index -> Libraries All times are GMT
Goto page 1, 2, 3, 4, 5  Next
Page 1 of 5

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



sf.net phatcode