Subversion Repositories Kolibri OS

Rev

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