Subversion Repositories Kolibri OS

Rev

Rev 6126 | Rev 6288 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
5418 IgorA 1
use32
2
	org 0x0
3
	db 'MENUET01'
6120 IgorA 4
	dd 1,start,i_end,mem,stacktop,0,cur_dir_path
5418 IgorA 5
 
6
include '../../../../../proc32.inc'
7
include '../../../../../macros.inc'
6120 IgorA 8
include '../../../../../KOSfuncs.inc'
5418 IgorA 9
include '../../../../../develop/libraries/box_lib/load_lib.mac'
10
include '../../../../../dll.inc'
11
include '../opengl_const.inc'
6120 IgorA 12
include 'fps.inc'
5418 IgorA 13
 
14
@use_library
15
 
16
macro matr_cell c_funct,c_param,funct,param, dia
17
{
18
	dia dword[esp-4*(c_param*(c_funct-funct)+(1+c_param-param))]
19
}
20
 
21
align 4
22
start:
23
	load_library name_tgl, cur_dir_path, library_path, system_path, \
24
		err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i
25
	cmp eax,-1
26
	jz button.exit
27
 
6120 IgorA 28
	mcall SF_SET_EVENTS_MASK,0x27
5418 IgorA 29
 
6120 IgorA 30
	stdcall [kosglMakeCurrent], 0,15,400,380,ctx1
31
	stdcall reshape, 400,380
5418 IgorA 32
 
33
; *** init ***
34
	stdcall [glLightfv], GL_LIGHT0, GL_POSITION, pos
35
	stdcall [glEnable], GL_CULL_FACE
36
	stdcall [glEnable], GL_LIGHTING
37
	stdcall [glEnable], GL_LIGHT0
38
	stdcall [glEnable], GL_DEPTH_TEST
39
 
40
	; make the gears
41
	stdcall [glGenLists],1
42
	mov [gear1],eax
43
	stdcall [glNewList], eax, GL_COMPILE
44
	stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red
45
	stdcall gear, 1.0, 4.0, 1.0, 20, 0.7
46
	call [glEndList]
47
 
48
	stdcall [glGenLists],1
49
	mov [gear2],eax
50
	stdcall [glNewList], eax, GL_COMPILE
51
	stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green
52
	stdcall gear, 0.5, 2.0, 2.0, 10, 0.7
53
	call [glEndList]
54
 
55
	stdcall [glGenLists],1
56
	mov [gear3],eax
57
	stdcall [glNewList], eax, GL_COMPILE
58
	stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue
59
	stdcall gear, 1.3, 2.0, 0.5, 10, 0.7
60
	call [glEndList]
61
 
62
	stdcall [glEnable], GL_NORMALIZE
63
; *** end init ***
64
 
65
align 4
66
red_win:
67
	call draw_window
68
 
6120 IgorA 69
align 16
5418 IgorA 70
still:
6120 IgorA 71
	call draw_3d
72
 
73
	stdcall Fps, 330,4
74
	mov dword[esp-4],eax
75
	fild dword[esp-4]
76
	fmul dword[a2]
77
	fadd dword[a1]
78
	fadd dword[angle]
79
	fstp dword[angle]
80
 
81
	mcall SF_CHECK_EVENT
5418 IgorA 82
	cmp al,1
83
	jz red_win
84
	cmp al,2
85
	jz key
86
	cmp al,3
87
	jz button
88
	jmp still
89
 
6120 IgorA 90
align 4
91
a1 dd 0.01
92
a2 dd 0.3
93
 
5418 IgorA 94
; new window size or exposure
95
align 4
96
proc reshape uses ebx ecx, width:dword, height:dword
97
locals
98
	h dq ?
99
	mh dq ?
100
endl
101
 
102
	stdcall [glViewport], 0, 0, [width], [height]
103
	stdcall [glMatrixMode], GL_PROJECTION
104
	stdcall [glLoadIdentity]
105
	fild dword[height]
106
	fidiv dword[width]
107
	fst qword[h] ;h = height / width
108
	fchs
109
	fstp qword[mh]
110
	mov ebx,ebp
111
	sub ebx,8
112
	mov ecx,ebp
113
	sub ecx,16
114
	stdcall [glFrustum], dword p1, dword p2, ebx, ecx, dword p5, dword p6
115
	stdcall [glMatrixMode], GL_MODELVIEW
116
	stdcall [glLoadIdentity]
117
	stdcall [glTranslatef], 0.0, 0.0, -40.0
118
	stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
119
	ret
120
endp
121
 
122
align 4
123
p1 dq -1.0
124
p2 dq  1.0
125
p5 dq  5.0
126
p6 dq 60.0
127
 
128
align 4
129
draw_window:
130
	pushad
6120 IgorA 131
	mcall SF_REDRAW,SSF_BEGIN_DRAW
5418 IgorA 132
 
6200 IgorA 133
	mcall SF_CREATE_WINDOW,(50 shl 16)+410,(30 shl 16)+425,0x33404040,,title1
5418 IgorA 134
	stdcall [kosglSwapBuffers]
135
 
6120 IgorA 136
	;Title
6200 IgorA 137
	mcall SF_DRAW_TEXT,(300 shl 16)+4,0xc0c0c0,fps,   fps.end-fps
138
	mcall SF_DRAW_TEXT,(8 shl 16)+4,0xc0c0c0,title3,title3.end-title3
139
	;mcall SF_DRAW_TEXT,(180 shl 16)+4,0xc0c0c0,title2,title2.end-title2
6120 IgorA 140
 
141
	mcall SF_REDRAW,SSF_END_DRAW
5418 IgorA 142
	popad
143
	ret
144
 
145
align 4
146
key:
6120 IgorA 147
	mcall SF_GET_KEY
5418 IgorA 148
 
149
	cmp ah,27 ;Esc
150
	je button.exit
151
 
152
	cmp ah,61 ;+
153
	jne @f
154
		fld dword[scale]
155
		fdiv dword[delt_sc]
156
		fstp dword[scale]
157
		call draw_3d
158
	@@:
159
	cmp ah,45 ;-
160
	jne @f
161
		fld dword[scale]
162
		fmul dword[delt_sc]
163
		fstp dword[scale]
164
		call draw_3d
165
	@@:
166
	cmp ah,178 ;Up
167
	jne @f
168
		fld dword[view_rotx]
169
		fadd dword[delt_size]
170
		fstp dword[view_rotx]
171
		call draw_3d
172
	@@:
173
	cmp ah,177 ;Down
174
	jne @f
175
		fld dword[view_rotx]
176
		fsub dword[delt_size]
177
		fstp dword[view_rotx]
178
		call draw_3d
179
	@@:
180
	cmp ah,176 ;Left
181
	jne @f
182
		fld dword[view_roty]
183
		fadd dword[delt_size]
184
		fstp dword[view_roty]
185
		call draw_3d
186
	@@:
187
	cmp ah,179 ;Right
188
	jne @f
189
		fld dword[view_roty]
190
		fsub dword[delt_size]
191
		fstp dword[view_roty]
192
		call draw_3d
193
	@@:
194
 
195
	jmp still
196
 
197
align 4
198
button:
6120 IgorA 199
	mcall SF_GET_BUTTON
5418 IgorA 200
	cmp ah,1
201
	jne still
202
.exit:
6120 IgorA 203
	mcall SF_TERMINATE_PROCESS
5418 IgorA 204
 
205
 
206
align 4
6120 IgorA 207
title1: db 'TinyGL in KolibriOS'
208
.end: db 0
209
title2: db 'F full screen'
210
.end: db 0
211
title3: db 'ESC - exit'
212
.end: db 0
6200 IgorA 213
fps:	db 'FPS:'
6120 IgorA 214
.end: db 0
215
 
5418 IgorA 216
align 4
217
ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext
218
;sizeof.TinyGLContext = 28
219
 
6120 IgorA 220
align 16
5418 IgorA 221
draw_3d:
222
	stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
223
 
224
	stdcall [glPushMatrix]
6120 IgorA 225
	;stdcall [glScalef], [scale], [scale], [scale]
5418 IgorA 226
	stdcall [glRotatef], [view_rotx], 1.0, 0.0, 0.0
227
	stdcall [glRotatef], [view_roty], 0.0, 1.0, 0.0
228
	stdcall [glRotatef], [view_rotz], 0.0, 0.0, 1.0
229
 
230
	stdcall [glPushMatrix]
231
	stdcall [glTranslatef], -3.0, -2.0, 0.0
232
	stdcall [glRotatef], [angle], 0.0, 0.0, 1.0
233
	stdcall [glCallList],[gear1]
234
	stdcall [glPopMatrix]
235
 
236
	stdcall [glPushMatrix]
237
	stdcall [glTranslatef], 3.1, -2.0, 0.0
238
	push dword 1.0
239
	push dword 0.0
240
	push dword 0.0
241
	finit
242
	fld1
243
	fld1
244
	faddp
245
	fchs
246
	fld dword[angle]
247
	fmulp
248
	fsub dword[an_9]
249
	fstp dword[esp-4]
250
	sub esp,4
251
	call [glRotatef] ;, -2.0*angle-9.0, 0.0, 0.0, 1.0
252
	stdcall [glCallList],[gear2]
253
	stdcall [glPopMatrix]
254
 
255
	stdcall [glPushMatrix]
256
	stdcall [glTranslatef], -3.1, 4.2, 0.0
257
	push dword 1.0
258
	push dword 0.0
259
	push dword 0.0
260
	finit
261
	fld1
262
	fld1
263
	faddp
264
	fchs
265
	fld dword[angle]
266
	fmulp
267
	fsub dword[an_25]
268
	fstp dword[esp-4]
269
	sub esp,4
270
	call [glRotatef] ;, -2.0*angle-25.0, 0.0, 0.0, 1.0
271
	stdcall [glCallList],[gear3]
272
	stdcall [glPopMatrix]
273
 
274
	stdcall [glPopMatrix]
275
 
6120 IgorA 276
	stdcall [kosglSwapBuffers]
5418 IgorA 277
 
278
;   count++;
279
;   if (count==limit) {
280
;       exit(0);
6120 IgorA 281
	ret
5418 IgorA 282
 
283
align 4
284
an_9 dd 9.0
285
an_25 dd 25.0
286
scale dd 0.14 ;???
287
delt_sc dd 0.85 ;???
288
delt_size dd 5.0
289
 
290
align 4
291
pos dd 5.0, 5.0, 10.0, 0.0
292
red dd 0.8, 0.1, 0.0, 1.0
293
green dd 0.0, 0.8, 0.2, 1.0
294
blue  dd 0.2, 0.2, 1.0, 1.0
295
 
296
view_rotx dd 20.0
297
view_roty dd 30.0
298
view_rotz dd  0.0
299
gear1 dd ?
300
gear2 dd ?
301
gear3 dd ?
302
angle dd 0.0
303
 
304
limit dd ?
305
count dd 1
306
 
307
;
308
;  Draw a gear wheel.  You'll probably want to call this function when
309
;  building a display list since we do a lot of trig here.
310
;
311
;  Input:  inner_radius - radius of hole at center
312
;          outer_radius - radius at center of teeth
313
;          width - width of gear
314
;          teeth - number of teeth
315
;          tooth_depth - depth of tooth
316
;
317
align 4
318
proc gear uses eax ebx, inner_radius:dword, outer_radius:dword, width:dword, teeth:dword, tooth_depth:dword
319
locals
320
	i dd ?
321
	r0 dd ?
322
	r1 dd ?
323
	r2 dd ?
324
	angle dd ?
325
	da dd ?
326
	u dd ?
327
	v dd ?
328
endl
329
 
330
	finit
331
	mov eax,[inner_radius]
332
	mov [r0],eax
333
	fld1
334
	fld1
335
	faddp
336
	fld dword[tooth_depth]
337
	fdiv st0,st1
338
	fld dword[outer_radius]
339
	fsub st0,st1
340
	fst  dword[r1] ;r1 = outer_radius - tooth_depth/2.0
341
	fadd dword[tooth_depth]
342
	fstp dword[r2] ;r2 = outer_radius + tooth_depth/2.0
343
	ffree st0 ;st0 = tooth_depth/2.0
344
	fincstp
345
	;st0 = 2.0
346
 
347
	fldpi
348
	fidiv dword[teeth]
349
	fdiv st0,st1
350
	fstp dword[da] ;da = M_PI / teeth / 2.0
351
 
352
	stdcall [glShadeModel], GL_FLAT
353
 
354
	stdcall [glNormal3f], 0.0, 0.0, 1.0
355
 
356
	mov ebx,[teeth]
357
 
358
	; draw front face
359
	stdcall [glBegin], GL_QUAD_STRIP
360
	mov dword[i],0
361
	@@:
362
	cmp dword[i],ebx
363
	jg @f
364
		finit
365
		fld1
366
		fld1
367
		faddp
368
 
369
		fldpi
370
		fmul st0,st1
371
		fimul dword[i]
372
		fidiv dword[teeth]
373
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
374
 
375
		fld dword[width]
376
		fdiv st0,st2
377
		matr_cell 4,3,1,3,fst
378
		matr_cell 4,3,2,3,fst
379
		matr_cell 4,3,3,3,fst
380
		matr_cell 4,3,4,3,fstp
381
 
382
		fld st0
383
		fsin
384
		fmul dword[r0]
385
		matr_cell 4,3,1,2,fst
386
		matr_cell 4,3,3,2,fstp
387
		fld st0
388
		fcos
389
		fmul dword[r0]
390
		matr_cell 4,3,1,1,fst
391
		matr_cell 4,3,3,1,fstp
392
 
393
		fld st0
394
		fsin
395
		fmul dword[r1]
396
		matr_cell 4,3,2,2,fstp
397
		fld st0
398
		fcos
399
		fmul dword[r1]
400
		matr_cell 4,3,2,1,fstp
401
 
402
		;st0 = angle
403
		fadd dword[da]
404
		fadd dword[da]
405
		fadd dword[da]
406
		fld st0
407
		fsin
408
		fmul dword[r1]
409
		matr_cell 4,3,4,2,fstp
410
		fcos
411
		fmul dword[r1]
412
		matr_cell 4,3,4,1,fstp
413
 
414
		sub esp,48 ;12*4
415
 
416
		call [glVertex3f] ;, r0*cos(angle), r0*sin(angle), width*0.5
417
		call [glVertex3f] ;, r1*cos(angle), r1*sin(angle), width*0.5
418
		call [glVertex3f] ;, r0*cos(angle), r0*sin(angle), width*0.5
419
		call [glVertex3f] ;, r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5
420
		inc dword[i]
421
		jmp @b
422
	@@:
423
	call [glEnd]
424
 
425
	; draw front sides of teeth
426
	stdcall [glBegin], GL_QUADS
427
	mov dword[i],0
428
	@@:
429
	cmp dword[i],ebx
430
	jg @f
431
		finit
432
		fld1
433
		fld1
434
		faddp
435
 
436
		fldpi
437
		fmul st0,st1
438
		fimul dword[i]
439
		fidiv dword[teeth]
440
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
441
 
442
		fld dword[width]
443
		fdiv st0,st2
444
		matr_cell 4,3,1,3,fst
445
		matr_cell 4,3,2,3,fst
446
		matr_cell 4,3,3,3,fst
447
		matr_cell 4,3,4,3,fstp
448
 
449
		fld st0
450
		fcos
451
		fmul dword[r1]
452
		matr_cell 4,3,1,1,fstp
453
		fld st0
454
		fsin
455
		fmul dword[r1]
456
		matr_cell 4,3,1,2,fstp
457
 
458
		fadd dword[da] ;st0 = angle+da
459
		fld st0
460
		fcos
461
		fmul dword[r2]
462
		matr_cell 4,3,2,1,fstp
463
		fld st0
464
		fsin
465
		fmul dword[r2]
466
		matr_cell 4,3,2,2,fstp
467
 
468
		fadd dword[da] ;st0 = angle+2*da
469
		fld st0
470
		fcos
471
		fmul dword[r2]
472
		matr_cell 4,3,3,1,fstp
473
		fld st0
474
		fsin
475
		fmul dword[r2]
476
		matr_cell 4,3,3,2,fstp
477
 
478
		fadd dword[da] ;st0 = angle+3*da
479
		fld st0
480
		fcos
481
		fmul dword[r1]
482
		matr_cell 4,3,4,1,fstp
483
		fsin
484
		fmul dword[r1]
485
		matr_cell 4,3,4,2,fstp
486
 
487
		sub esp,48 ;12*4
488
 
489
		call [glVertex3f];, r1*cos(angle),      r1*sin(angle),      width*0.5
490
		call [glVertex3f];, r2*cos(angle+da),   r2*sin(angle+da),   width*0.5
491
		call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5
492
		call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5
493
		inc dword[i]
494
		jmp @b
495
	@@:
496
	call [glEnd]
497
 
498
	stdcall [glNormal3f], 0.0, 0.0, -1.0
499
 
500
	; draw back face
501
	stdcall [glBegin], GL_QUAD_STRIP
502
	mov dword[i],0
503
	@@:
504
	cmp dword[i],ebx
505
	jg @f
506
		finit
507
		fld1
508
		fld1
509
		faddp
510
 
511
		fldpi
512
		fmul st0,st1
513
		fimul dword[i]
514
		fidiv dword[teeth]
515
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
516
 
517
		fld dword[width]
518
		fdiv st0,st2
519
		fchs
520
		matr_cell 4,3,1,3,fst
521
		matr_cell 4,3,2,3,fst
522
		matr_cell 4,3,3,3,fst
523
		matr_cell 4,3,4,3,fstp
524
 
525
		fld st0
526
		fsin
527
		fld st0
528
		fmul dword[r1]
529
		matr_cell 4,3,1,2,fstp
530
		fmul dword[r0]
531
		matr_cell 4,3,2,2,fst
532
		matr_cell 4,3,4,2,fstp
533
 
534
		fld st0
535
		fcos
536
		fld st0
537
		fmul dword[r1]
538
		matr_cell 4,3,1,1,fstp
539
		fmul dword[r0]
540
		matr_cell 4,3,2,1,fst
541
		matr_cell 4,3,4,1,fstp
542
 
543
		;st0 = angle
544
		fadd dword[da]
545
		fadd dword[da]
546
		fadd dword[da]
547
		fld st0
548
		fsin
549
		fmul dword[r1]
550
		matr_cell 4,3,3,2,fstp
551
		fcos
552
		fmul dword[r1]
553
		matr_cell 4,3,3,1,fstp
554
 
555
		sub esp,48 ;12*4
556
 
557
		call [glVertex3f];, r1*cos(angle), r1*sin(angle), -width*0.5
558
		call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
559
		call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
560
		call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
561
		inc dword[i]
562
		jmp @b
563
	@@:
564
	call [glEnd]
565
 
566
	; draw back sides of teeth
567
	stdcall [glBegin], GL_QUADS
568
	mov dword[i],0
569
	@@:
570
	cmp dword[i],ebx
571
	jg @f
572
		finit
573
		fld1
574
		fld1
575
		faddp
576
 
577
		fldpi
578
		fmul st0,st1
579
		fimul dword[i]
580
		fidiv dword[teeth]
581
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
582
 
583
		fld dword[width]
584
		fdiv st0,st2
585
		fchs
586
		matr_cell 4,3,1,3,fst
587
		matr_cell 4,3,2,3,fst
588
		matr_cell 4,3,3,3,fst
589
		matr_cell 4,3,4,3,fstp
590
 
591
		fld st0
592
		fcos
593
		fmul dword[r1]
594
		matr_cell 4,3,4,1,fstp
595
		fld st0
596
		fsin
597
		fmul dword[r1]
598
		matr_cell 4,3,4,2,fstp
599
 
600
		fadd dword[da] ;st0 = angle+da
601
		fld st0
602
		fcos
603
		fmul dword[r2]
604
		matr_cell 4,3,3,1,fstp
605
		fld st0
606
		fsin
607
		fmul dword[r2]
608
		matr_cell 4,3,3,2,fstp
609
 
610
		fadd dword[da] ;st0 = angle+2*da
611
		fld st0
612
		fcos
613
		fmul dword[r2]
614
		matr_cell 4,3,2,1,fstp
615
		fld st0
616
		fsin
617
		fmul dword[r2]
618
		matr_cell 4,3,2,2,fstp
619
 
620
		fadd dword[da] ;st0 = angle+3*da
621
		fld st0
622
		fcos
623
		fmul dword[r1]
624
		matr_cell 4,3,1,1,fstp
625
		fsin
626
		fmul dword[r1]
627
		matr_cell 4,3,1,2,fstp
628
 
629
		sub esp,48 ;12*4
630
 
631
		call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
632
		call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5
633
		call [glVertex3f];, r2*cos(angle+da),   r2*sin(angle+da),   -width*0.5
634
		call [glVertex3f];, r1*cos(angle),      r1*sin(angle),      -width*0.5
635
		inc dword[i]
636
		jmp @b
637
	@@:
638
	call [glEnd]
639
 
640
	; draw outward faces of teeth
641
	stdcall [glBegin], GL_QUAD_STRIP
642
	mov dword[i],0
643
	@@:
644
	cmp dword[i],ebx
645
	jg @f
646
		finit
647
		fld1
648
		fld1
649
		faddp
650
 
651
		fldpi
652
		fmul st0,st1
653
		fimul dword[i]
654
		fidiv dword[teeth]
655
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
656
 
657
		fld dword[width]
658
		fdiv st0,st2
659
		matr_cell 12,3, 1,3,fst
660
		matr_cell 12,3, 4,3,fst
661
		matr_cell 12,3, 7,3,fst
662
		matr_cell 12,3,10,3,fst
663
		fchs
664
		matr_cell 12,3, 2,3,fst
665
		matr_cell 12,3, 5,3,fst
666
		matr_cell 12,3, 8,3,fst
667
		matr_cell 12,3,11,3,fstp
668
		fldz
669
		matr_cell 12,3, 3,3,fst
670
		matr_cell 12,3, 6,3,fst
671
		matr_cell 12,3, 9,3,fst
672
		matr_cell 12,3,12,3,fstp
673
 
674
		fld st0
675
		fsin
676
		matr_cell 12,3, 6,2,fst
677
		matr_cell 12,3,12,2,fst
678
		fmul dword[r1]
679
		matr_cell 12,3, 1,2,fst
680
		matr_cell 12,3, 2,2,fstp
681
 
682
		fld st0
683
		fcos
684
		matr_cell 12,3, 6,1,fst
685
		matr_cell 12,3,12,1,fst
686
		fmul dword[r1]
687
		matr_cell 12,3, 1,1,fst
688
		matr_cell 12,3, 2,1,fstp
689
 
690
		fadd dword[da] ;st0 = angle+da
691
		fld st0
692
		fcos
693
		fmul dword[r2]
694
		matr_cell 12,3, 4,1,fst
695
		matr_cell 12,3, 5,1,fst
696
		matr_cell 12,3, 1,1,fsub
697
		fstp dword[u]
698
 
699
		fld st0
700
		fsin
701
		fmul dword[r2]
702
		matr_cell 12,3, 4,2,fst
703
		matr_cell 12,3, 5,2,fst
704
		matr_cell 12,3, 1,2,fsub
705
		fst  dword[v]
706
 
707
		fmul st0,st0
708
		fld  dword[u]
709
		fmul st0,st0
710
		faddp
711
		fsqrt ;st0 = len
712
		fld  dword[u]
713
		fdiv st0,st1
714
		fchs
715
		matr_cell 12,3, 3,2,fstp
716
		fld  dword[v]
717
		fdiv st0,st1
718
		matr_cell 12,3, 3,1,fstp
719
		ffree st0 ;len
720
		fincstp
721
 
722
		fadd dword[da] ;st0 = angle+2*da
723
		fld st0
724
		fcos
725
		fmul dword[r2]
726
		matr_cell 12,3, 7,1,fst
727
		matr_cell 12,3, 8,1,fstp
728
		fld st0
729
		fsin
730
		fmul dword[r2]
731
		matr_cell 12,3, 7,2,fst
732
		matr_cell 12,3, 8,2,fstp
733
 
734
		fadd dword[da] ;st0 = angle+3*da
735
		fld st0
736
		fcos
737
		fmul dword[r1]
738
		matr_cell 12,3,10,1,fst
739
		matr_cell 12,3,11,1,fst
740
		matr_cell 12,3, 7,1,fsub
741
		fchs
742
		matr_cell 12,3, 9,2,fstp ;-u
743
 
744
		fsin
745
		fmul dword[r1]
746
		matr_cell 12,3,10,2,fst
747
		matr_cell 12,3,11,2,fst
748
		matr_cell 12,3, 7,2,fsub
749
		matr_cell 12,3, 9,1,fstp ;v
750
 
751
		sub esp,144 ;12*12
752
 
753
		call [glVertex3f];, r1*cos(angle), r1*sin(angle), width*0.5
754
		call [glVertex3f];, r1*cos(angle), r1*sin(angle), -width*0.5
755
;u = r2*cos(angle+da) - r1*cos(angle)
756
;v = r2*sin(angle+da) - r1*sin(angle)
757
;len = sqrt( u*u + v*v )
758
;u /= len
759
;v /= len
760
		call [glNormal3f];, v, -u, 0.0
761
		call [glVertex3f];, r2*cos(angle+da),   r2*sin(angle+da),    width*0.5
762
		call [glVertex3f];, r2*cos(angle+da),   r2*sin(angle+da),   -width*0.5
763
		call [glNormal3f];, cos(angle), sin(angle), 0.0
764
		call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da),  width*0.5
765
		call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5
766
;u = r1*cos(angle+3*da) - r2*cos(angle+2*da)
767
;v = r1*sin(angle+3*da) - r2*sin(angle+2*da)
768
		call [glNormal3f];, v, -u, 0.0
769
		call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da),  width*0.5
770
		call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
771
		call [glNormal3f];, cos(angle), sin(angle), 0.0
772
		inc dword[i]
773
		jmp @b
774
	@@:
775
 
776
	finit
777
	fld1
778
	fld1
779
	faddp
780
 
781
	fld dword[width]
782
	fdiv st0,st1
783
	matr_cell 2,3,1,3,fst
784
	fchs
785
	matr_cell 2,3,2,3,fstp
786
	fldz
787
	matr_cell 2,3,1,2,fst
788
	matr_cell 2,3,2,2,fstp
789
	fldz
790
	fcos
791
	fmul dword[r1]
792
	matr_cell 2,3,1,1,fst
793
	matr_cell 2,3,2,1,fstp
794
 
795
	sub esp,24
796
 
797
	call [glVertex3f];, r1*cos(0), r1*sin(0), width*0.5
798
	call [glVertex3f];, r1*cos(0), r1*sin(0), -width*0.5
799
 
800
	call [glEnd]
801
 
802
 
803
	stdcall [glShadeModel], GL_SMOOTH
804
 
805
	; draw inside radius cylinder
806
	stdcall [glBegin], GL_QUAD_STRIP
807
	mov dword[i],0
6126 IgorA 808
	finit
5418 IgorA 809
	@@:
810
	cmp dword[i],ebx
811
	jg @f
812
		fld1
813
		fld1
814
		faddp
815
 
816
		fldpi
6126 IgorA 817
		fmul st0,st1
5418 IgorA 818
		fimul dword[i]
819
		fidiv dword[teeth]
820
		fst dword[angle] ;angle = i * 2.0*M_PI / teeth
821
 
822
		fldz
823
		matr_cell 3,3,1,3,fstp
824
		fld dword[width]
825
		fdiv st0,st2
826
		matr_cell 3,3,3,3,fst
827
		fchs
828
		matr_cell 3,3,2,3,fstp
829
 
830
		fld st0
831
		fsin
832
		fchs
833
		matr_cell 3,3,1,2,fst
834
		fchs
835
		fmul dword[r0]
836
		matr_cell 3,3,2,2,fst
837
		matr_cell 3,3,3,2,fstp
838
 
839
		fcos
840
		fchs
841
		matr_cell 3,3,1,1,fst
842
		fchs
843
		fmul dword[r0]
844
		matr_cell 3,3,2,1,fst
845
		matr_cell 3,3,3,1,fstp
846
 
847
		sub esp,36 ;12*3
848
 
849
		call [glNormal3f];, -cos(angle), -sin(angle), 0.0
850
		call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
851
		call [glVertex3f];, r0*cos(angle), r0*sin(angle), width*0.5
6126 IgorA 852
		ffree st0 ;2.0
853
		fincstp
5418 IgorA 854
		inc dword[i]
855
		jmp @b
856
	@@:
857
	call [glEnd]
858
 
859
	ret
860
endp
861
 
862
 
863
 
864
;--------------------------------------------------
865
align 4
866
import_lib_tinygl:
867
 
868
macro E_LIB n
869
{
870
	n dd sz_#n
871
}
872
include '../export.inc'
873
	dd 0,0
874
macro E_LIB n
875
{
876
	sz_#n db `n,0
877
}
878
include '../export.inc'
879
 
880
;--------------------------------------------------
881
system_path db '/sys/lib/'
882
name_tgl db 'tinygl.obj',0
883
err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0
884
head_f_i:
885
head_f_l db 'System error',0
886
err_message_import db 'Error on load import library tinygl.obj',0
887
;--------------------------------------------------
888
 
889
align 16
890
i_end:
891
	rb 4096
892
stacktop:
893
cur_dir_path:
894
	rb 4096
895
library_path:
896
	rb 4096
897
mem: