1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
| #D3D_SDK_VERSION=49
#D3D_OK=0
#D3DFVF_XYZ=2
#D3DFVF_XYZRHW=4
#D3DFVF_DIFFUSE=64
#D3DSWAPEFFECT_DISCARD=1
#D3DSWAPEFFECT_FLIP=2
#D3DSWAPEFFECT_COPY=3
#D3DSWAPEFFECT_COPY_VSYNC=4
#D3DCLEAR_TARGET=1
#D3DADAPTER_DEFAULT=0
#D3DDEVTYPE_HAL=1
#D3DDEVTYPE_REF=2
#D3DDEVTYPE_SW=3
#D3DCREATE_SOFTWARE_VERTEXPROCESSING=32
#D3DCREATE_HARDWARE_VERTEXPROCESSING=64
#D3DCREATE_MIXED_VERTEXPROCESSING=128
#D3DPT_POINTLIST=1
#D3DPT_LINELIST=2
#D3DPT_LINESTRIP=3
#D3DPT_TRIANGLELIST=4
#D3DPT_TRIANGLESTRIP=5
#D3DFMT_X1R5G5B5=24
#D3DFMT_A1R5G5B5=25
#D3DFMT_R5G6B5=23
#D3DFMT_X8R8G8B8=22
#D3DFMT_A8R8G8B8=21
#D3DFMT_R8G8B8=20
#D3DTS_PROJECTION=3
#D3DTS_WORLD=256
#D3DPRESENTFLAG_LOCKABLE_BACKBUFFER=1
#D3DRS_LIGHTING=137
#D3DRS_ALPHABLENDENABLE=27
#D3DRS_FILLMODE=8
#D3DRS_CULLMODE=22
#D3DRS_SRCBLEND=19
#D3DRS_DESTBLEND=20
#D3DRS_FOGENABLE=28
#D3DRS_FOGCOLOR=34
Structure My_Vertex
x.f
y.f
z.f
col.l
EndStructure
Structure D3DXMATRIX
_11.f
_12.f
_13.f
_14.f
_21.f
_22.f
_23.f
_24.f
_31.f
_32.f
_33.f
_34.f
_41.f
_42.f
_43.f
_44.f
EndStructure
Structure D3DDISPLAYMODE
Width.l
Height.l
RefreshRate.l
Format.l
EndStructure
Structure D3DADAPTER_IDENTIFIER9
Driver.b[512]
Description.b[512]
DeviceName.b[32]
DriverVersion.Large_Integer
DriverVersionLowPart.l
DriverVersionHighPart.l
VendorId.l
DeviceId.l
SubSysId.l
Revision.l
DeviceIdentifier.GUID
WHQLLevel.l
EndStructure
Structure D3DPresent_Parameters
BackBufferWidth.l
BackBufferHeight.l
BackBufferFormat.l
BackBufferCount.l
MultiSampleType.l
MultiSampleQuality.l
SwapEffect.l
hDeviceWindow.l
Windowed.l
EnableAutoDepthStencil.l
AutoDepthStencilFormat.l
Flags.l
FullScreen_RefreshRateInHz.l
FullScreen_PresentationInterval.l
EndStructure
Procedure MoveMatrix(*Matrix.D3DXMATRIX,X.f,Y.f,Z.f)
*Matrix\_41=X
*Matrix\_42=Y
*Matrix\_43=Z
EndProcedure
Procedure RotateMatrixX(*Matrix.D3DXMATRIX,Grad.f)
*Matrix\_11=1.0
*Matrix\_44=1.0
*Matrix\_12=0.0
*Matrix\_13=0.0
*Matrix\_14=0.0
*Matrix\_41=0.0
*Matrix\_21=0.0
*Matrix\_24=0.0
*Matrix\_42=0.0
*Matrix\_31=0.0
*Matrix\_34=0.0
*Matrix\_43=0.0
Rad.f=Grad/#PI*2
*Matrix\_22= Cos(Rad)
*Matrix\_23= Sin(Rad)
*Matrix\_32=-Sin(Rad)
*Matrix\_33= Cos(Rad)
EndProcedure
Procedure RotateMatrixY(*Matrix.D3DXMATRIX,Grad.f)
*Matrix\_22=1.0
*Matrix\_44=1.0
*Matrix\_12=0.0
*Matrix\_14=0.0
*Matrix\_41=0.0
*Matrix\_21=0.0
*Matrix\_23=0.0
*Matrix\_24=0.0
*Matrix\_42=0.0
*Matrix\_32=0.0
*Matrix\_34=0.0
*Matrix\_43=0.0
Rad.f=Grad/#PI*2
*Matrix\_11= Cos(Rad)
*Matrix\_13=-Sin(Rad)
*Matrix\_31= Sin(Rad)
*Matrix\_33= Cos(Rad)
EndProcedure
Procedure RotateMatrixZ(*Matrix.D3DXMATRIX,Grad.f)
*Matrix\_33=1.0
*Matrix\_44=1.0
*Matrix\_13=0.0
*Matrix\_14=0.0
*Matrix\_41=0.0
*Matrix\_23=0.0
*Matrix\_24=0.0
*Matrix\_42=0.0
*Matrix\_31=0.0
*Matrix\_32=0.0
*Matrix\_34=0.0
*Matrix\_43=0.0
Rad.f=Grad/#PI*2
*Matrix\_11= Cos(Rad)
*Matrix\_12= Sin(Rad)
*Matrix\_21=-Sin(Rad)
*Matrix\_22= Cos(Rad)
EndProcedure
Procedure D3D_Init()
Global D3DInst
Global D3D.IDirect3D9
Global D3DWnd.D3DPresent_Parameters
Global D3DDevice.IDirect3DDevice9
Global D3DInst
D3DInst=LoadLibrary_("D:\Downloads\Torrent\SDK's\Developer Runtime\x86\D3D9.dll")
If D3DInst
D3D=CallFunctionFast(GetProcAddress_(D3DInst,"Direct3DCreate9"),#D3D_SDK_VERSION)
EndIf
ProcedureReturn D3D
EndProcedure
Procedure D3D_OpenScreen(WindowID,Width,Height,PixelFormat,SwapEffect,Lockable)
If D3D
D3DWnd\SwapEffect=SwapEffect
D3DWnd\BackBufferWidth=Width
D3DWnd\BackBufferHeight=Height
D3DWnd\BackBufferCount=1
D3DWnd\BackBufferFormat=PixelFormat
D3DWnd\hDeviceWindow=WindowID
D3DWnd\Flags=#D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
If Lockable=0:D3DWnd\Flags=0:EndIf
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
EndIf
ProcedureReturn D3DDevice
EndProcedure
Procedure D3D_OpenWindowedScreen(WindowID,Lockable)
If D3D
ScrInfo.D3DDISPLAYMODE
D3D\GetAdapterDisplayMode(#D3DADAPTER_DEFAULT,ScrInfo)
D3DWnd\SwapEffect=#D3DSWAPEFFECT_DISCARD
D3DWnd\BackBufferFormat=ScrInfo\Format
D3DWnd\Windowed=-1
D3DWnd\hDeviceWindow=WindowID
D3DWnd\Flags=#D3DPRESENTFLAG_LOCKABLE_BACKBUFFER
If Lockable=0:D3DWnd\Flags=0:EndIf
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_HAL,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_REF,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_HARDWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_MIXED_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
If Result
Result=D3D\CreateDevice(#D3DADAPTER_DEFAULT,#D3DDEVTYPE_SW,WindowID,#D3DCREATE_SOFTWARE_VERTEXPROCESSING,D3DWnd,@D3DDevice)
EndIf
EndIf
ProcedureReturn D3DDevice
EndProcedure
Procedure D3D_Release()
If D3DDevice:D3DDevice\Release():EndIf
If D3D:D3D\Release():EndIf
If D3DInst:FreeLibrary_(D3DInst):EndIf
EndProcedure
Global FPS,Count,Start
Global BackBuffer.IDirect3DSurface9,AdapterInfo.D3DADAPTER_IDENTIFIER9,ScrInfo.D3DDISPLAYMODE
Global VertexNr
Global Dim Vertex.My_Vertex(1000)
Procedure SetVertexColor(RGB)
Vertex(VertexNr)\col=RGB(Blue(RGB),Green(RGB),Red(RGB))
EndProcedure
Procedure SetVertex(x.f,y.f,z.f)
Vertex(VertexNr)\x=x
Vertex(VertexNr)\y=y
Vertex(VertexNr)\z=z
VertexNr+1
EndProcedure
Procedure RenderScene()
D3DDevice\Clear(0,0,#D3DCLEAR_TARGET,$FF,0.0,0)
DC.l
BackBuffer\GetDC(@DC)
SetBkMode_(DC,1)
SetTextColor_(DC,#White)
SelectObject_(DC,GetStockObject_(#ANSI_VAR_FONT))
Text$="FPS: "+Str(FPS)
TextOut_(DC,350,0,@Text$,Len(Text$))
Text$=Str(ScrInfo\Width)+"x"+Str(ScrInfo\Height)+"@"+Str(ScrInfo\RefreshRate)+" Hz"
TextOut_(DC,350,20,@Text$,Len(Text$))
Text$=PeekS(@AdapterInfo\Description)+"("+PeekS(@AdapterInfo\Driver)+")"
TextOut_(DC,350,40,@Text$,Len(Text$))
BackBuffer\ReleaseDC(DC)
D3DDevice\BeginScene()
D3DDevice\DrawPrimitiveUP(#D3DPT_TRIANGLELIST,VertexNr/3,@Vertex(0),16)
D3DDevice\EndScene()
D3DDevice\Present(0,0,0,0)
EndProcedure
If D3D_Init()=0
MessageRequester("","Direct3D konnte nicht gestartet werden.")
D3D_Release()
End
EndIf
Flags=#PB_Window_ScreenCentered|#PB_Window_SizeGadget|#PB_Window_MaximizeGadget
OpenWindow(1,0,0,640,480,"Direct3D 9 Test",Flags)
OpenWindow(2,0,0,100,100,"D3D9 Test",#PB_Window_SystemMenu,WindowID(1))
SetWindowPos_(WindowID(1),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
SetWindowPos_(WindowID(2),#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE|#SWP_NOMOVE)
OptionGadget(1,0, 0,100,25,"1.)")
OptionGadget(2,0,25,100,25,"2.)")
OptionGadget(3,0,50,100,25,"3.)")
OptionGadget(4,0,75,100,25,"4.)")
SetGadgetState(1,1)
;Result=D3D_OpenWindowedScreen(WindowID(1),#True)
Result=D3D_OpenScreen(WindowID(1),640,480,#D3DFMT_X8R8G8B8,#D3DSWAPEFFECT_DISCARD,#True)
If Result=0
Result=D3D_OpenScreen(WindowID(1),640,480,#D3DFMT_R5G6B5,#D3DSWAPEFFECT_DISCARD,#True)
EndIf
If Result=0
Result=D3D_OpenScreen(WindowID(1),640,480,#D3DFMT_X1R5G5B5,#D3DSWAPEFFECT_DISCARD,#True)
EndIf
If Result=0
Result=D3D_OpenWindowedScreen(WindowID(1),#True)
EndIf
If Result=0
MessageRequester("","Direct3D konnte nicht gestartet werden.")
D3D_Release()
End
EndIf
ProjMatrix.D3DXMATRIX
ProjMatrix\_11=Cos((#PI/4)/2)/Sin((#PI/4)/2)
ProjMatrix\_22=Cos((#PI/4)/2)/Sin((#PI/4)/2)
ProjMatrix\_33=1/(1-0.001)
ProjMatrix\_34=1
ProjMatrix\_43=-(1/(1-0.001))
D3DDevice\SetTransform(#D3DTS_PROJECTION,@ProjMatrix)
RGB1=RGB(192,192,0)
RGB2=RGB(64,128,0)
RGB3=RGB(128,64,0)
SetVertexColor(RGB1)
SetVertex(0.0,0.25,0.0)
SetVertexColor(RGB2)
SetVertex(-0.5,-0.5,0.5)
SetVertexColor(RGB3)
SetVertex(0.5,-0.5,0.5)
SetVertexColor(RGB1)
SetVertex(0.0,0.25,0.0)
SetVertexColor(RGB3)
SetVertex(0.5,-0.5,0.5)
SetVertexColor(RGB2)
SetVertex(0.5,-0.5,-0.5)
SetVertexColor(RGB1)
SetVertex(0.0,0.25,0.0)
SetVertexColor(RGB2)
SetVertex(0.5,-0.5,-0.5)
SetVertexColor(RGB3)
SetVertex(-0.5,-0.5,-0.5)
SetVertexColor(RGB1)
SetVertex(0.0,0.25,0.0)
SetVertexColor(RGB3)
SetVertex(-0.5,-0.5,-0.5)
SetVertexColor(RGB2)
SetVertex(-0.5,-0.5,0.5)
D3DDevice\SetFVF(#D3DFVF_XYZ|#D3DFVF_DIFFUSE)
D3DDevice\SetRenderState(#D3DRS_LIGHTING,0)
D3DDevice\GetBackBuffer(0,0,0,@BackBuffer)
D3D\GetAdapterIdentifier(0,0,AdapterInfo)
D3D\GetAdapterDisplayMode(#D3DADAPTER_DEFAULT,ScrInfo)
Z.f=5
X.f=0
Y.f=0
RotY.f
D3DDevice\SetDialogBoxMode(-1)
Repeat
Count+1:If timeGetTime_()-Start>1000:FPS=Count:Count=0:Start=timeGetTime_():EndIf
If GetGadgetState(1)
D3DDevice\SetRenderState(#D3DRS_FOGENABLE,0)
D3DDevice\SetRenderState(#D3DRS_ALPHABLENDENABLE,0)
D3DDevice\SetRenderState(#D3DRS_FILLMODE,3)
D3DDevice\SetRenderState(#D3DRS_CULLMODE,3)
EndIf
If GetGadgetState(2)
D3DDevice\SetRenderState(#D3DRS_FOGENABLE,0)
D3DDevice\SetRenderState(#D3DRS_ALPHABLENDENABLE,0)
D3DDevice\SetRenderState(#D3DRS_FILLMODE,2)
D3DDevice\SetRenderState(#D3DRS_CULLMODE,0)
EndIf
If GetGadgetState(3)
D3DDevice\SetRenderState(#D3DRS_FOGENABLE,0)
D3DDevice\SetRenderState(#D3DRS_FILLMODE,3)
D3DDevice\SetRenderState(#D3DRS_CULLMODE,3)
D3DDevice\SetRenderState(#D3DRS_ALPHABLENDENABLE,-1)
D3DDevice\SetRenderState(#D3DRS_SRCBLEND,2)
D3DDevice\SetRenderState(#D3DRS_DESTBLEND,2)
EndIf
If GetGadgetState(4)
D3DDevice\SetRenderState(#D3DRS_ALPHABLENDENABLE,0)
D3DDevice\SetRenderState(#D3DRS_FILLMODE,3)
D3DDevice\SetRenderState(#D3DRS_CULLMODE,3)
D3DDevice\SetRenderState(#D3DRS_FOGENABLE,-1)
D3DDevice\SetRenderState(#D3DRS_FOGCOLOR,RGB(96,96,96))
EndIf
RenderScene()
If GetAsyncKeyState_(#VK_UP)=-32767 :z-0.15:EndIf
If GetAsyncKeyState_(#VK_DOWN)=-32767 :z+0.15:EndIf
If GetAsyncKeyState_(#VK_LEFT)=-32767 :x+0.15:EndIf
If GetAsyncKeyState_(#VK_RIGHT)=-32767:x-0.15:EndIf
WorldMatrix.D3DXMATRIX
RotY+0.1
RotateMatrixY(@WorldMatrix,RotY)
MoveMatrix(@WorldMatrix,x,y,z)
D3DDevice\SetTransform(#D3DTS_WORLD,@WorldMatrix)
Event=WindowEvent()
If Event=#PB_Event_CloseWindow And EventWindow()=2
D3DDevice\SetDialogBoxMode(0)
CloseWindow(2)
EndIf
Until GetAsyncKeyState_(#VK_ESCAPE)=-32767
D3DDevice\SetDialogBoxMode(0)
;D3D_Release()
End |