Page 15 of 24
Posted: Sun Feb 22, 2009 12:00 am
by Olby
Mistrel wrote:The first change is that only the GDK table is required now. The syntax is slightly different as well. The first line of the .gdt file (note the extension) has two strings separated by a percent (%). The first is the library name and the second is the dependency string (some DBP function from the library).
Everything else is the same. You can drag the .gdt file on top of the library builder, use the command line, or a shortcut. Just make sure that your current directory is where you want the output files to go. Two folders will be created, a "Sources" and a "Dependencies" folder with your .pb and .gde (formerly .d) files.
Hmm, I don't understand this part! I am passing the TXT file with the commands as stated in the manual - the GDKTable.txt, the empty PB file (?) and the dll it self. As I understand it should output the PB source so that it can be later compiled into pb library using tailbite? Where the .ġdt or .gdd files come from? This is hard to understand for me currently

Posted: Sun Feb 22, 2009 12:18 am
by Mistrel
Save this file as Lib-P_AdvanedTerrain.gdt and pass it to the library builder. Then compile with TailBite. That's it.
You'll need to compile twice with TailBite, once for a normal library and another for a ThreadSafe library. Make sure you don't mix up where you put these otherwise you'll get a compile error.
Notice the change to the first line and the new extension to the file.
Code: Select all
AdvancedTerrain.dll%SET TERRAIN SPLIT 0,0
dbSetTerrainScale%LFFF%?SetTerrainScale@@YAXHMMM@Z%TerrainID, x.f, y.f, z.f
dbSetTerrainSplit%LL%?SetTerrainSplit@@YAXHH@Z%TerrainID, Split
dbSetTerrainTiling%LL%?SetTerrainTiling@@YAXHH@Z%TerrainID, Tile
dbSetTerrainHeightMap%LS%?SetTerrainHeightMap@@YAXHK@Z%TerrainID, Filename.s
dbSetTerrainLight%LFFFFFFF%?SetTerrainLight@@YAXHMMMMMMM@Z%TerrainID, xDirection.f, yDirection.f, zDirection.f, Red.f, Green.f, Blue.f, Scale.f
dbBuildTerrain%L%?BuildTerrain@@YAXH@Z%TerrainID
dbUpdateTerrain%0%?UpdateTerrain@@YAXXZ%
dbSetTerrainTexture%LLL%?SetTerrainTexture@@YAXHHH@Z%TerrainID, BaseImage, DetailImage
dbMakeObjectTerrain%L%?MakeObjectTerrain@@YAXH@Z%TerrainID
dbGetTerrainGroundHeight[%FLFF%?GetTerrainGroundHeight@@YAKHMM@Z%TerrainID, x.f, z.f
dbLoadTerrain%SL%?LoadTerrain@@YAXKH@Z%Filename.s, TerrainID
dbSaveTerrain%SL%?SaveTerrain@@YAXKH@Z%Filename.s, TerrainID
dbGetTerrainXSize[%FL%?GetTerrainXSize@@YAKH@Z%TerrainID
dbGetTerrainZSize[%FL%?GetTerrainZSize@@YAKH@Z%TerrainID
dbDestroyTerrain%L%?DeleteTerrain@@YAXH@Z%TerrainID
; UPDATE TERRAIN%L%?UpdateTerrainNoCull@@YAXH@Z
; BUILD TERRAIN%LL%?BuildTerrainEx@@YAXHH@Z
Posted: Sun Feb 22, 2009 12:19 pm
by Olby
Ok, thanks Mistrel, I got my lib compiled and working as far as I can tell
I wanted to point out that the PureGDK compiler does not highlight error line it reports. It just shows the compiler GUI with the text but the IDE does not jump to the corresponding line. Is it possible to fix this. It does so in the default IDE.
Posted: Sun Feb 22, 2009 12:27 pm
by Mistrel
It will only highlight the line if the debugger is on. There's no way to notify the IDE of a runtime error otherwise.
Is it possible to fix this. It does so in the default IDE.
Can you be more specific? As far as I'm aware with the debugger on it's highlighting the line correctly.
Posted: Sun Feb 22, 2009 12:46 pm
by Olby
Ahh, I see. Now that I know that it works only in debug mode I could get those error lines back to work.
Could you please tell, why this does not work ?
Code: Select all
; Open the PureGDK render window
OpenWindow( 0, 0, 0, 640, 480, "DarkBasic Professional - PureGDK", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
hDBWnd = OpenDBWnd( WindowID( 0 ), 0, 0, 640, 480 )
dbMakeObjectCube(1,200)
Repeat
dbSync()
Until dbEscapeKey()=1
End
I mean it should obviously exit the application when I press escape, but for me all those db input commands like dbspacekey() dbescapkey() etc. do not work.
I'm completely screwed these few days, I cannot get a damn thing to work on my computer... I guess this is just a small period of my life!

Posted: Sun Feb 22, 2009 12:55 pm
by Mistrel
If you don't use WindowEvent() or WaitWindowEvent() then no message processing is possible and your window will lock up. Notice how you can't drag the window either.
This functionality is different in PureGDK 1.1 that it was previously where the DBP screen had its own window (watch out for old code snippets). It's just a display now and relies upon the message processing of its parent to receive input.
Code: Select all
Repeat
dbSync()
Until WindowEvent()=#PB_Event_CloseWindow Or dbEscapeKey()
This is a fundamental difference between DBP which does message processing for you. In PureBasic it's your responsibility. See this example where forgetting to process window events will lock up the window:
Code: Select all
OpenWindow(0,0,0,320,240,"",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
Repeat
ForEver
Posted: Sun Feb 22, 2009 1:03 pm
by Olby
I think it is better this way so that the DB and PB integrates better. Thanks for explaining. I also just noticed that the
LOAD EFFECT has an additional parameter:
Code: Select all
LOAD EFFECT Filename, Effect Number, Texture Flag, DoNotGenerateExtraData
PureGDK documentation/compiler does not include this!
Posted: Sun Feb 22, 2009 1:11 pm
by Mistrel
If it's not in the help file then it was probably added sometime since 6.7 and wasn't included in the release notes. I can add this if it's a documented parameter.
Posted: Sun Feb 22, 2009 1:17 pm
by Olby
Yes these are all documented in DBPro help files.
Here is another one you've missed:
Code: Select all
SET CAMERA TO IMAGE Camera Number, Image Number, Width, Height, Generate Alpha Mode, D3D Format
PureGDK includes only first 4 parameters, dropping the last two.
Posted: Sun Feb 22, 2009 1:19 pm
by Mistrel
I'll add these as well. Just as an FYI if PureGDK is missing a command that you need immediately you can always create a supplemental library using the GDKLibBuilder.

Posted: Sun Feb 22, 2009 1:23 pm
by Olby
I know, I thought about that also. I will try this right now.

Posted: Sun Feb 22, 2009 10:52 pm
by Olby
Sorry to bother you about such silly things but how I can convert from those binary (?) virtual key codes to those that I can pass directly to dbKeyState() ? For example when I enter (0x50) it says I need a valid decimal number. Thanks.
Posted: Mon Feb 23, 2009 3:35 am
by Mistrel
Hex in PureBasic is like this: $50. 0x50 in hex to binary would be: Bin($50).
You use the function by passing one of the constants listed, for example:
Code: Select all
If dbKeyState(#VK_ESCAPE)
End
EndIf
Posted: Tue Feb 24, 2009 11:04 am
by Mistrel
Here is an example of how to tie in recovery for an invalid render device with changing the display resolution. This is useful for windowed applications that want to reset the device resolution after resizing the window.
This example also demonstrates how to safely handle rendering in a thread and also how to maintain a given aspect ratio when altering the device resolution.
http://puregdk.com/files/upload/aspect-ratio.zip
Code: Select all
Structure Glob_Globstruct
RenderThreadID.i
ProgramEnding.l
PauseThread.l
DefaultAspectRatio.f
DefaultFOV.f
MaxFOV.f
EndStructure
Global Glob_Globstruct.Glob_Globstruct
Declare WinCallback(hWnd, uMsg, wParam, lParam)
Declare D3DDeviceLost()
Declare D3DDeviceReset()
Declare GDKRenderThread(Null)
ExamineDesktops()
Procedure WinCallback(hWnd, uMsg, wParam, lParam)
Static OldWidth.l, OldHeight.l, FirstRun
Protected NewWidth.l, NewHeight.l
If Not FirstRun
OldWidth=WindowWidth(1)
OldHeight=WindowHeight(1)
FirstRun=1
EndIf
Select uMsg
Case #WM_ERASEBKGND
;/ Don't erase the background to elminate resize flickering
ProcedureReturn 1
Case #WM_SIZING, #WM_WINDOWPOSCHANGING, #WM_SIZE, #WM_WINDOWPOSCHANGED
dbSetWindowSize(WindowWidth(1),WindowHeight(1))
Case #WM_EXITSIZEMOVE
;/ Handle window resizing
If InterlockedCompareExchange_(@Glob_Globstruct\PauseThread,1,0)=0
NewWidth=WindowWidth(1)
NewHeight=WindowHeight(1)
If ((Not NewWidth=OldWidth) Or (Not OldHeight=NewHeight)) And NewWidth>0 And NewHeight>0
Repeat: Delay(1)
Until Glob_Globstruct\PauseThread=2
dbSetDisplayMode(NewWidth,NewHeight)
D3DDeviceReset()
OldWidth=NewWidth
OldHeight=NewHeight
;/ Reset camera aspect ratio
DefaultAspectRatio=Glob_Globstruct\DefaultAspectRatio
DefaultFOV=Glob_Globstruct\DefaultFOV
MaxFOV=Glob_Globstruct\MaxFOV
AspectRatio.f=(NewWidth*DefaultAspectRatio)/(NewHeight*DefaultAspectRatio)
FOV.f=MaxFOV-(AspectRatio.f*100.0)
If FOV.f<DefaultFOV
FOV.f=DefaultFOV
EndIf
If FOV.f>MaxFOV
FOV.f=MaxFOV
EndIf
dbSetCameraAspect(AspectRatio.f,dbCurrentCamera())
dbSetCameraFOV(FOV.f,dbCurrentCamera())
EndIf
;/ Set PauseThread to 0
InterlockedExchange_(@Glob_Globstruct\PauseThread,0)
EndIf
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
Procedure D3DDeviceLost()
;/ Notify the render thread that the render device has been lost
If Not Glob_Globstruct\PauseThread
InterlockedExchange_(@Glob_Globstruct\PauseThread,1)
EndIf
EndProcedure
Procedure D3DDeviceReset()
;/ Wait until the render thread is ready for the device to be reset
Repeat: Delay(1)
Until InterlockedCompareExchange_(@Glob_Globstruct\PauseThread,3,2)=2
;/ Reload project data here
dbMakeObjectCube(1,3)
dbScaleObject(1,88,88,88)
dbColorBackdrop(RGB(Random(255),Random(255),Random(255)))
;/ Set PauseThread to 0
InterlockedExchange_(@Glob_Globstruct\PauseThread,0)
EndProcedure
Procedure GDKRenderThread(Null)
Repeat
Delay(1) ;/ Don't use all of the cpu
dbXRotateObject(1,dbWrapValue(dbObjectAngleX(1)+0.3))
dbYRotateObject(1,dbWrapValue(dbObjectAngleY(1)+0.5))
;/ Render the backbuffer
dbSync()
;/ Check for suspend notificatons
If InterlockedCompareExchange_(@Glob_Globstruct\PauseThread,2,1)=1
Repeat: Delay(1)
dbSync()
Until Not Glob_Globstruct\PauseThread
EndIf
Until Glob_Globstruct\ProgramEnding
EndProcedure
;/ Show the PureGDK render window
OpenWindow(0,0,0,640,480,"DarkBasic Professional - PureGDK",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
MDIGadget(0,0,0,640,480,0,0)
AddGadgetItem(0,1,"Render window",0,#PB_Window_TitleBar|#PB_Window_SizeGadget)
hDBWnd=OpenDBWnd(WindowID(1),0,0,WindowWidth(1),WindowHeight(1))
;/ Set the default aspect ratio and FOV
Glob_Globstruct\DefaultAspectRatio=640.0/480.0
Glob_Globstruct\DefaultFOV=61.9621391296
Glob_Globstruct\MaxFOV=164.0
;/ Set the window callback for window 0
SetWindowCallback(@WinCallback(),1)
;/ Set D3D device callbacks
dbSetD3DDeviceCallback(@D3DDeviceLost(),#GDK_Callback_DeviceLost)
dbSetD3DDeviceCallback(@D3DDeviceReset(),#GDK_Callback_DeviceReset)
;/ Load media
dbMakeObjectCube(1,3)
dbScaleObject(1,88,88,88)
dbColorBackdrop(RGB(0,0,0))
;/ Create render thread
Glob_Globstruct\RenderThreadID=CreateThread(@GDKRenderThread(),0)
;/ Program loop
Repeat
Event=WaitWindowEvent()
Until Event=#PB_Event_CloseWindow ;Or dbKeyState(#VK_ESCAPE)
;/ Cleanup
Glob_Globstruct\ProgramEnding=1
WaitThread(Glob_Globstruct\RenderThreadID)
End
Posted: Thu Feb 26, 2009 9:59 pm
by Olby
PureGDK beta has expired!
