Page 1 of 2

DirectX 9 For PB (October 2006)

Posted: Wed Jul 12, 2006 1:24 pm
by Dreglor
I Finnally got this out,

From Read Me:
-------------------------------------------------
- - - - DirectX 9c for Pure Basic 4.0 - - - -
-------------------------------------------------

Written / Converted By: Steven "Dreglor" Garcia
Version: 2.0.2.1
Version Date: 10 - 14 - 06

Questions and comments are welcome. Email me at
"Dreglor@comcast.net" if you have any.
You can also reach me at the Purebasic Forum at
http://www.purebasic.fr/english/

- - - - Whats New - - - -
*Removed uneeded libaries from the libary zip
*Fixed major problem with muiltable defines
*Fixed minor miss interpeted types with Direct Sound
*Updated to October 2006 Libaries
*Added End-User DirectX 9c (October 2006) Install

- - - - What this Does - - - -
This allows for all purebasic users to easily use Direct3D,
DirectInput, And DirectSound with in the comfort of Pure Basic,
with out blindly feeling around in the maze of DirectX architecture.
These Includes define all of functions, Constants, Types, and macros
that are currently in the DirectX SDK.

- - - - Requirements - - - -
DirectX 9C (October 2006) end user installed,
and PureBasic 4.00+
(This WILL not work with a earlier version of Purebasic)

- - - - How to Use / Install - - - -
Extract the "DirectX SDK (October 2006) Libaries.zip" archive into:
"..\PureBasic\PureLibraries\Windows\Libraries" Then
just Include the file for the DirectX system (d3d9x.pb or d3d9.pb
for Direct3d, etc.), don't forget to use a include path if there are stored in a different
folder than the main source directory, like in the examples.
after that is done you can start to coding away.
There are a lot of Examples you can refer to and with a few tips,
C++ examples and tutorials are hardly different from PB.

- - - - Notes - - - -
When Converting from C++ remeber that "->" in C++ means "\"
in PureBasic also LP in structures or interface types drop, it
just means it is long pointer in some cases you should have a "*" on
the beginning of the variable others it is not required.
"&" in C++ MOST of the time means "@".
If your functions return an error handle use the DirectX Error program
or use the DxErr functions to interpet the meaning of it.
If you encounter any problems about missing Dll's install the end-user runtimes
that should clear it up.

- - - - Remarks - - - -
Now I tried to get this as easy to use and as compatiable to Pure Basic
as much as possible but there will allways be a few quarks in this because
PureBasic isn't C and these includes are not 1:1 conversion but for the most
part it is all there. I will try to help hammer out quarks If some encounters them.

Enjoy,
~Dreglor

- - - - Disclaimer - - - -
You may use these sources, libaries, utilities, and examples contained in this
archive in any project, free or commercial, with and/or in Pure Basic. You may
modify the sources as long as the topmost commented header in the sources
are intact and not modified nor moved in any way. You may Disribute freely
as long as this readme remains intact and together with the packaged sources,
libaries, utilities, and examples.
here are a few screens of the examples

DirectX initilization
Image

Use of Mesh and Matrices
Image

Textures
Image

Famous Rotating Cube
Image

New Version! October 2006
Mirror00: http://www.secretly.de/publicFTP/dreglo ... _Oct06.zip
Mirror01: http://purearea.net/pb/download/devtool ... _Oct06.zip

Forgive me for the sparse commenting in the examples I'm not exactly a DirectX Guru and most of theses examples are from my experience with C++ examples...

Grab it and check out the examples
and code away!

Make sure that inline asm is enabled for Direct Input Projects
you will get a compiler Error if you don't

Posted: Wed Jul 12, 2006 4:45 pm
by Sveinung
Thanks for a nice lib.

But I got some errors in the dinput.pbi

error is:
Line 84 '_TempPointer is not a valid operator

Regards
Sveinung

Posted: Wed Jul 12, 2006 5:05 pm
by Shannara
At this time, the link is down and takes me to a spam page.

Posted: Wed Jul 12, 2006 5:18 pm
by Dreglor
Sveinung wrote:Thanks for a nice lib.

But I got some errors in the dinput.pbi

error is:
Line 84 '_TempPointer is not a valid operator

Regards
Sveinung
forgot to mention the work around in dinput requires you to enable inline asm
Shannara wrote:At this time, the link is down and takes me to a spam page.
you MUST copy and paste link

Posted: Wed Jul 12, 2006 6:21 pm
by Dreglor
New version (fixed Muiltable define problem)
check first post

Posted: Wed Jul 12, 2006 7:00 pm
by djes
Works like a charm! Thank you! :D

Posted: Wed Jul 12, 2006 8:56 pm
by Flype
nice, incredible work :shock:

do you have a source code that show how to program the joystick ?

Posted: Wed Jul 12, 2006 9:10 pm
by Dreglor
this is just a quick write up

and i can't test it (no joystick herer)

Code: Select all

;////////////////////////////////////////////////////////////////
;//
;// Project Title: DirectX 9C for PureBasic
;// File Title: Joystick
;// Created On: 6-28-05
;// Updated On: 7-11-06
;// Author: Steven "Dreglor" Garcia
;//
;////////////////////////////////////////////////////////////////

;- Includes

IncludePath "Includes\DirectX\"
XIncludeFile "dinput.pbi"

;- Constants

Enumeration
  #Window_DI
EndEnumeration

Enumeration
  #Text_Info
  #Text_Output
EndEnumeration

;- Globals

Global *DI.IDIRECTINPUT8
Global *Joystick.IDIRECTINPUTDEVICE8
Global JoystickState.DIJOYSTATE

;- Procedures

Procedure InitDirectInput()
  If DirectInput8Create(GetModuleHandle_(#Null), #DIRECTINPUT_VERSION, IID_IDirectInput8A, @*DI, #Null) = #DI_OK
    
    ProcedureReturn #True
  Else
    
    ;direct input failed to be created
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure DI_InitKeyboard(WindowID.l, CooperativeLevel.l)
  If *DI\CreateDevice(GUID_Joystick, @*Joystick, #Null) = #DI_OK
    
    If *Joystick\SetDataFormat(c_dfDIJoystick) = #DI_OK
      
      If *Joystick\SetCooperativeLevel(WindowID, CooperativeLevel) = #DI_OK
        
        If *Joystick\Acquire() = #DI_OK
          
          ProcedureReturn #True
        Else
          
          
          ;acquire failed
          *Joystick\Release()
          *Joystick = #Null
          ProcedureReturn #False
        EndIf 
      Else
        
        ;cooperative level set failed
        *Joystick\Release()
        *Joystick = #Null
        ProcedureReturn #False
      EndIf
    Else
      
      ;data set format failed
      *Joystick\Release()
      *Joystick = #Null
      ProcedureReturn #False
    EndIf
  Else
    
    ;device creation failed
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure DI_Shutdown()
  
  If *Joystick <> #Null
    
    *Joystick\Release()
    *Joystick = #Null
  EndIf
  If *DI <> #Null
    
    *DI\Release()
    *DI = #Null
  EndIf
EndProcedure

Procedure DI_ExamineJoystick()
  If *Joystick\GetDeviceState(SizeOf(DIJOYSTATE), JoystickState) = #DI_OK
    
    ProcedureReturn #True
  Else
    
    ;failed to get device state
    ProcedureReturn #False
  EndIf
EndProcedure

;refer to JoystickState and DIJOYSTATE
;on how to get button and axis data

;- Entry Point

If OpenWindow(#Window_DI, 10, 10, 128, 128, "DirectX for PB: Joystick",  #PB_Window_SystemMenu | #PB_Window_TitleBar )
  
  If CreateGadgetList(WindowID(#Window_DI))
    
    TextGadget(#Text_Info, 10, 10, 112, 20, "Test the Keys out")
    TextGadget(#Text_Output, 10, 40, 112, 80, "", #PB_Text_Center | #PB_Text_Border)
  Else
    
    ;gadget list failed to be created
    End
  EndIf
Else
  
  ;window failed to open
  End
EndIf

If InitDirectInput() = #True
  
  If DI_InitKeyboard(WindowID(0), #DISCL_BACKGROUND | #DISCL_NONEXCLUSIVE) = #False
    
    ;keyboard failed to initilze
    End
  EndIf
Else
  
  ;directinput failed To initilize
  End
EndIf

;main loop
Repeat
  
  Delay(10)
  
  If DI_ExamineJoystick()
    
  Else
    
    End
  EndIf
  
  SetGadgetText(#Text_Output, String)
  String = ""
Until WindowEvent() = #PB_Event_CloseWindow
DI_Shutdown()
End

Posted: Wed Jul 12, 2006 9:32 pm
by Flype
nice to you dreglor.

but i get 5 x POLINK Errors :

_c_dfDIMouse
_c_dfDIMouse2
_c_dfDIKeyboard
_c_dfDIJoystick
_c_dfDIJoystick2

Posted: Wed Jul 12, 2006 9:34 pm
by Flype
same in the dinput Mouse and keyboard provided samples.

dxdiag say that i have DirectX 9.0c (4.09.0000.0904)

Posted: Sun Jul 16, 2006 4:24 am
by Dreglor
enable inline asm should be enabled but if your not using JAPBE then it might not be

edit:
did you install the libs?

Posted: Sun Jul 16, 2006 9:58 am
by Flype
Yes it works - after restarting the IDE. no problem.

Posted: Tue Jul 18, 2006 5:23 pm
by SFSxOI
As I wipe the drool from my chin from salivating over this announcement having waited for something like this.....I am almost trembling in anticipation of using it. Thank You very much! :)

Posted: Thu Aug 10, 2006 10:30 am
by acidburn
can't run Dirext3d - Primitives example
error encountered :


>>> This application has failed to start because d3dx9_30.dll was not found. - Re-installing the application may fix the problem..


but already installed :(

Posted: Thu Aug 10, 2006 11:23 am
by magicjo
@acidburn,

try to install the Directx's distro of August , I've had the same problem with some demos.

Bye