Someone can help me with Direct3D 7 and devices?
Posted: Tue Sep 07, 2004 3:50 pm
Hi, i was playing with DirectDraw and Direct3D 7, but i have some problems to initalise the device of Direct3D, i can't make any Direct3D drawing, because i can't get the device, i was searching on inet, but exist very few pages about DirectX 7, all are about DirectX 8.0 or higher, and it change a lot between versions 7 and 8. This is the code:
I hope that someone can help me with DirectX 7 stuff... Thanks in advance..
Code: Select all
Global Quit
Structure D3D_TLVERTEX8
x.f
y.f
z.f
rhw.f;res.l
color.l
EndStructure
;* DDCOLORKEY
Structure DDCOLORKEY
dwColorSpaceLowValue.l ;// low boundary of color space that is to
;// be treated as Color Key, inclusive
dwColorSpaceHighValue.l ;// high boundary of color space that is
;// to be treated as Color Key, inclusive
EndStructure
;* DDSCAPS2
Structure DDSCAPS2
dwCaps.l ;// capabilities of surface wanted
dwCaps2.l
dwCaps3.l
dwCaps4.l
EndStructure
;* DDPIXELFORMAT
Structure DDPIXELFORMAT
dwSize.l; // size of structure
dwFlags.l; // pixel format flags
dwFourCC.l; // (FOURCC code)
StructureUnion
dwRGBBitCount.l; // how many bits per pixel
dwYUVBitCount.l; // how many bits per pixel
dwZBufferBitDepth.l; // how many total bits/pixel in z buffer (including any stencil bits)
dwAlphaBitDepth.l; // how many bits for alpha channels
dwLuminanceBitCount.l; // how many bits per pixel
dwBumpBitCount.l; // how many bits per "buxel", total
EndStructureUnion
StructureUnion
dwRBitMask.l; // mask for red bit
dwYBitMask.l; // mask for Y bits
dwStencilBitDepth.l; // how many stencil bits (note: dwZBufferBitDepth-dwStencilBitDepth is total Z-only bits)
dwLuminanceBitMask.l; // mask for luminance bits
dwBumpDuBitMask.l; // mask for bump map U delta bits
EndStructureUnion
StructureUnion
dwGBitMask.l; // mask for green bits
dwUBitMask.l; // mask for U bits
dwZBitMask.l; // mask for Z bits
dwBumpDvBitMask.l; // mask for bump map V delta bits
EndStructureUnion
StructureUnion
dwBBitMask.l; // mask for blue bits
dwVBitMask.l; // mask for V bits
dwStencilBitMask.l; // mask for stencil bits
dwBumpLuminanceBitMask.l; // mask for luminance in bump map
EndStructureUnion
StructureUnion
dwRGBAlphaBitMask.l; // mask for alpha channel
dwYUVAlphaBitMask.l; // mask for alpha channel
dwLuminanceAlphaBitMask.l; // mask for alpha channel
dwRGBZBitMask.l; // mask for Z channel
dwYUVZBitMask.l; // mask for Z channel
EndStructureUnion
EndStructure
;* DDSURFACEDESC2
Structure DDSURFACEDESC2
dwSize.l; // size of the DDSURFACEDESC structure
dwFlags.l; // determines what fields are valid
dwHeight.l; // height of surface to be created
dwWidth.l; // width of input surface
StructureUnion
lPitch.l; // distance to start of next line (return value only)
dwLinearSize.l; // Formless late-allocated optimized surface size
EndStructureUnion
dwBackBufferCount.l; // number of back buffers requested
StructureUnion
dwMipMapCount.l; // number of mip-map levels requestde
; // dwZBufferBitDepth removed, use ddpfPixelFormat one instead
dwRefreshRate.l; // refresh rate (used when display mode is described)
dwSrcVBHandle.l; // The source used in VB::Optimize
EndStructureUnion
dwAlphaBitDepth.l; // depth of alpha buffer requested
dwReserved.l; // reserved
lpSurface.l; // pointer to the associated surface memory
StructureUnion
ddckCKDestOverlay.DDCOLORKEY; // color key for destination overlay use
dwEmptyFaceColor.l; // Physical color for empty cubemap faces
EndStructureUnion
ddckCKDestBlt.DDCOLORKEY; // color key for destination blt use
ddckCKSrcOverlay.DDCOLORKEY; // color key for source overlay use
ddckCKSrcBlt.DDCOLORKEY; // color key for source blt use
StructureUnion
ddpfPixelFormat.DDPIXELFORMAT; // pixel format description of the surface
dwFVF.l; // vertex format description of vertex buffers
EndStructureUnion
ddsCaps.DDSCAPS2; // direct draw surface capabilities
dwTextureStage.l; // stage in multitexture cascade
EndStructure
Structure DDBLTFX
dwSize.l; // size of structure
dwDDFX.l; // FX operations
dwROP.l; // Win32 raster operations
dwDDROP.l; // Raster operations new for DirectDraw
dwRotationAngle.l; // Rotation angle for blt
dwZBufferOpCode.l; // ZBuffer compares
dwZBufferLow.l; // Low limit of Z buffer
dwZBufferHigh.l; // High limit of Z buffer
dwZBufferBaseDest.l; // Destination base value
dwZDestConstBitDepth.l; // Bit depth used to specify Z constant for destination
StructureUnion
dwZDestConst.l; // Constant to use as Z buffer for dest
lpDDSZBufferDest.l; // Surface to use as Z buffer for dest
EndStructureUnion
dwZSrcConstBitDepth.l; // Bit depth used to specify Z constant for source
StructureUnion
dwZSrcConst.l; // Constant to use as Z buffer for src
lpDDSZBufferSrc.l; // Surface to use as Z buffer for src
EndStructureUnion
dwAlphaEdgeBlendBitDepth.l; // Bit depth used to specify constant for alpha edge blend
dwAlphaEdgeBlend.l; // Alpha for edge blending
dwReserved.l;
dwAlphaDestConstBitDepth.l; // Bit depth used to specify alpha constant for destination
StructureUnion
dwAlphaDestConst.l; // Constant to use as Alpha Channel
lpDDSAlphaDest.l; // Surface to use as Alpha Channel
EndStructureUnion
dwAlphaSrcConstBitDepth.l; // Bit depth used to specify alpha constant for source
StructureUnion
dwAlphaSrcConst.l; // Constant to use as Alpha Channel
lpDDSAlphaSrc.l; // Surface to use as Alpha Channel
EndStructureUnion
StructureUnion
dwFillColor.l; // color in RGB or Palettized
dwFillDepth.l; // depth value for z-buffer
dwFillPixel.l; // pixel value for RGBA or RGBZ
lpDDSPattern.l; // Surface to use as pattern
EndStructureUnion
ddckDestColorkey.DDCOLORKEY; // DestColorkey override
ddckSrcColorkey.DDCOLORKEY; // SrcColorkey override
EndStructure
#DDSCAPS_3DDEVICE = $00002000
#DD_OK = 0
#DD_FALSE = 1
#DDBLT_WAIT = $01000000
#DDBLTFAST_DONOTWAIT = $20
#DDSCL_FULLSCREEN = $00000001
#DDSCL_EXCLUSIVE = $00000010
#DDSCL_NORMAL = $00000081
#DDSCL_NOWINDOWCHANGES = $00000002
#DDSD_CAPS = $00000001
#DDSD_HEIGHT = $00000002
#DDSD_WIDTH = $00000004
#DDSD_BACKBUFFERCOUNT = $00000020
#DDSCAPS_BACKBUFFER = $00000004
#DDSCAPS_OFFSCREENPLAIN = $00000040
#DDSCAPS_PRIMARYSURFACE = $00000200
#DDSCAPS_COMPLEX = $00000008
#DDSCAPS_FLIP = $00000010
#DDCKEY_SRCBLT = $00000008
#DDFLIP_WAIT = $00000001
#DDBLTFAST_NOCOLORKEY = $00000000
#DDBLTFAST_SRCCOLORKEY = $00000001
#DDBLTFAST_WAIT = $00000010
#DDBLT_KEYSRC = $00008000
#DDBLT_COLORFILL = $00000400
#DDERR_SURFACELOST = $450
#D3DCLEAR_TARGET = $1
#D3DDP_WAIT = $00000001
#D3DPT_POINTLIST=1
#D3DPT_LINELIST=2
#D3DPT_LINESTRIP=3
#D3DPT_TRIANGLELIST=4
#D3DPT_TRIANGLESTRIP=5
#D3DFVF_RESERVED0 = $001
#D3DFVF_POSITION_MASK = $00E
#D3DFVF_XYZ = $002
#D3DFVF_XYZRHW = $004
#D3DFVF_XYZB1 = $006
#D3DFVF_XYZB2 = $008
#D3DFVF_XYZB3 = $00a
#D3DFVF_XYZB4 = $00c
#D3DFVF_XYZB5 = $00e
#D3DFVF_NORMAL = $010
#D3DFVF_RESERVED1 = $020
#D3DFVF_DIFFUSE = $040
#D3DFVF_SPECULAR = $080
#D3DFVF_TEXCOUNT_MASK = $f00
#D3DFVF_TEXCOUNT_SHIFT = 8
#D3DFVF_TEX0 = $000
#D3DFVF_TEX1 = $100
#D3DFVF_TEX2 = $200
#D3DFVF_TEX3 = $300
#D3DFVF_TEX4 = $400
#D3DFVF_TEX5 = $500
#D3DFVF_TEX6 = $600
#D3DFVF_TEX7 = $700
#D3DFVF_TEX8 = $800
#D3DFVF_RESERVED2 = $f000 ; // 4 reserved bits
#D3DFVF_VERTEX =( #D3DFVF_XYZ | #D3DFVF_NORMAL | #D3DFVF_TEX1 )
#D3DFVF_LVERTEX =( #D3DFVF_XYZ | #D3DFVF_RESERVED1 | #D3DFVF_DIFFUSE | #D3DFVF_SPECULAR | #D3DFVF_TEX1 )
#D3DFVF_TLVERTEX =( #D3DFVF_XYZRHW | #D3DFVF_DIFFUSE | #D3DFVF_SPECULAR | #D3DFVF_TEX1 )
DD.IDirectDraw7 ;Direct Draw
Primary.IDirectDrawSurface7 ;Primary surface
BackBuffer.IDirectDrawSurface7 ;Backbuffer
Direct3D.IDirect3D7 ;Direct 3D
Device.IDirect3DDevice7 ;Direct 3D Device
ddsd.DDSURFACEDESC2
caps.DDSCAPS2
DEnum.IDirect3DDevice7
Procedure WindowCallback(Window, Message, wParam, lParam)
Select Message
Case #WM_CLOSE
Quit=1
DestroyWindow_(Window)
; Result = DefWindowProc_(Window, Message, wParam, lParam)
Case #WM_DESTROY
PostQuitMessage_(0)
Result = 0
Default
Result = DefWindowProc_(Window, Message, wParam, lParam)
EndSelect
ProcedureReturn Result
EndProcedure
#StyleEx = 0
WindowClass.s = "DirectDraw"
wc.WNDCLASSEX
wc\cbSize = SizeOf(WNDCLASSEX)
wc\lpfnWndProc = @WindowCallback()
wc\hCursor = LoadCursor_(0, #IDC_ARROW)
wc\hbrBackground = #COLOR_BTNFACE+1
wc\lpszClassName = @WindowClass
RegisterClassEx_(@wc)
hWnd = CreateWindowEx_(#StyleEx, WindowClass, "DirectX", #WS_VISIBLE | #WS_BORDER | #WS_SYSMENU, 100, 100, 400, 300, 0, 0, 0, 0)
ShowWindow_(hWnd, #SW_SHOWDEFAULT)
UpdateWindow_(hWnd)
SetFocus_(hWnd)
If OpenLibrary(0,"ddraw.dll")
If CallFunction(0,"DirectDrawCreateEx",0,@DD.IDirectDraw7,?IID_IDirectDraw7,0) <> #DD_OK
MessageRequester("Warning:","Couldn't init DirectDraw",0)
End
EndIf
Else
MessageRequester("Warning:","Couldn't init DirectDraw",0)
End
EndIf
;
; If OpenLibrary(1,"d3d8.dll")
; If CallFunction(1,"Direct3DCreate7",0,Direct3D.IDirect3D7,?IID_IDirect3D7,0) <> #DD_OK
; MessageRequester("Warning:","Couldn't init DirectDraw",0)
; End
; EndIf
; Else
; MessageRequester("Warning:","Couldn't init DirectDraw",0)
; End
; EndIf
; Make a fullscreen, exclusive application
DD\SetCooperativeLevel(hWnd, #DDSCL_EXCLUSIVE|#DDSCL_FULLSCREEN)
DD\SetDisplayMode(640, 480, 16, 0, 0)
; Prepare and create the primary surface.
ddsd\dwSize = SizeOf(DDSURFACEDESC2)
ddsd\dwFlags = #DDSD_BACKBUFFERCOUNT|#DDSD_CAPS
ddsd\ddsCaps\dwCaps = #DDSCAPS_COMPLEX|#DDSCAPS_FLIP|#DDSCAPS_3DDEVICE|#DDSCAPS_PRIMARYSURFACE
ddsd\dwBackBufferCount = 1
DD\CreateSurface(ddsd,@Primary,0)
caps\dwCaps = #DDSCAPS_BACKBUFFER | #DDSCAPS_3DDEVICE
Primary\GetAttachedSurface(caps, @BackBuffer)
DD\QueryInterface(?IID_IDirect3D7, @Direct3D)
Direct3D\CreateDevice(?IID_IDirect3DHalDevice, backsurface, @Device)
; The direct3d device isn't initialised.
Debug Device
;CallDebugger
msg.MSG
Repeat
If PeekMessage_(@msg, 0, 0, 0, #PM_REMOVE)
TranslateMessage_(@msg)
DispatchMessage_(@msg)
EndIf
; If the device isn't initialised, it crash the program
;Device\Clear(0,0,#D3DCLEAR_TARGET,color,0.0,0)
;Flip the primary surface
Primary\Flip(0, #DDFLIP_WAIT)
BlitFX.DDBLTFX\dwSize = SizeOf(DDBLTFX)
BlitFX\dwFillColor = RGB(255, 0, 0)
BackBuffer\Blt(0, 0, 0, #DDBLT_COLORFILL, BlitFX)
Until Quit=1
;Restore the display mode.
DD\RestoreDisplayMode()
DD\SetCooperativeLevel(hWnd, #DDSCL_NORMAL)
End
DataSection
IID_IDirectDraw7:
Data.l $15e65ec0
Data.w $3b9c, $11d2
Data.b $b9, $2f, $00, $60, $97, $97, $ea, $5b
IID_IDirect3DRGBDevice:
Data.l $A4665C60
Data.w $2673,$11CF
Data.b $A3,$1A,$0,$AA,$0,$B9,$33,$56
IID_IDirect3DHALDevice:
Data.l $84E63DE0
Data.w $46AA,$11CF
Data.b $81,$6F,$0,$0,$C0,$20,$15,$6E
IID_IDirect3DTnLHalDevice:
Data.l $F5049E78
Data.w $4861,$11D2
Data.b $A4,$7,$0,$A0,$C9,$6,$29,$A8
IID_IDirect3D7:
Data.l $F5049E77
Data.w $4861,$11D2
Data.b $A4,$7,$0,$A0,$C9,$6,$29,$A8
EndDataSection