DirectX 9 For PB (October 2006)

Developed or developing a new product in PureBasic? Tell the world about it.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

DirectX 9 For PB (October 2006)

Post 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
Last edited by Dreglor on Sun Dec 10, 2006 10:47 am, edited 8 times in total.
~Dreglor
User avatar
Sveinung
Enthusiast
Enthusiast
Posts: 142
Joined: Tue Oct 07, 2003 11:03 am
Location: Bergen, Norway

Post 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
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post by Shannara »

At this time, the link is down and takes me to a spam page.
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
~Dreglor
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post by Dreglor »

New version (fixed Muiltable define problem)
check first post
~Dreglor
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Post by djes »

Works like a charm! Thank you! :D
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

nice, incredible work :shock:

do you have a source code that show how to program the joystick ?
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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
~Dreglor
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

nice to you dreglor.

but i get 5 x POLINK Errors :

_c_dfDIMouse
_c_dfDIMouse2
_c_dfDIKeyboard
_c_dfDIJoystick
_c_dfDIJoystick2
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

same in the dinput Mouse and keyboard provided samples.

dxdiag say that i have DirectX 9.0c (4.09.0000.0904)
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
Dreglor
Enthusiast
Enthusiast
Posts: 759
Joined: Sat Aug 02, 2003 11:22 pm
Location: OR, USA

Post 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?
~Dreglor
User avatar
Flype
Addict
Addict
Posts: 1542
Joined: Tue Jul 22, 2003 5:02 pm
Location: In a long distant galaxy

Post by Flype »

Yes it works - after restarting the IDE. no problem.
No programming language is perfect. There is not even a single best language.
There are only languages well suited or perhaps poorly suited for particular purposes. Herbert Mayer
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post 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! :)
acidburn
User
User
Posts: 23
Joined: Mon Aug 07, 2006 1:37 pm

Post 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 :(
magicjo
User
User
Posts: 61
Joined: Sun May 07, 2006 10:43 am
Location: Italy

Post by magicjo »

@acidburn,

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

Bye
PB Registered User, Egrid Registered User
Win7 x64 Ultimate, 4,00 Gb Mem, Ati Radeon HD4600 Series, Realtek High Definition Audio Integrated
Post Reply