fix mode 'GL_CULL_FACE'

fix functions 'glColor4fv', 'glFrustum'
add example 'gears.asm'

git-svn-id: svn://kolibrios.org@5418 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
IgorA 2015-02-17 23:01:48 +00:00
parent baa45f4a47
commit 469ba9e901
6 changed files with 926 additions and 86 deletions

View File

@ -116,32 +116,8 @@ endp
align 4
proc glColor4fv uses eax ebx, v:dword
locals
p rd 8
endl
mov dword[p],OP_Color
mov eax,[v]
mov ebx,[eax+8]
mov dword[p+4],ebx
mov ebx,[eax+4]
mov dword[p+8],ebx
mov ebx,[eax]
mov dword[p+12],ebx
mov ebx,[eax+12]
mov dword[p+16],ebx
; direct convertion to integer to go faster if no shading
mov eax,ebp
sub eax,4
push eax ;&p[7]
sub eax,4
push eax ;&p[6]
sub eax,4
push eax ;&p[5]
stdcall RGBFtoRGBI,[eax+8],[eax+4],[eax] ;call: v[2],v[1],v[0],p[5],p[6],p[7]
mov eax,ebp
sub eax,32 ;=sizeof(dd)*8
stdcall gl_add_op,eax
stdcall glColor4f,[eax],[eax+4],[eax+8],[eax+12],1.0
ret
endp

View File

@ -708,36 +708,38 @@ pushad
;if (co==0)
mov edi,dword[edx+offs_vert_zp+offs_zbup_x]
sub edi,dword[ebx+offs_vert_zp+offs_zbup_x]
mov dword[norm],edi
mov dword[norm],edi ;p2.x-p0.x
fild dword[norm]
mov edi,dword[ecx+offs_vert_zp+offs_zbup_y]
sub edi,dword[ebx+offs_vert_zp+offs_zbup_y]
mov dword[norm],edi
mov dword[norm],edi ;p1.y-p0.y
fimul dword[norm]
fchs
mov edi,dword[ecx+offs_vert_zp+offs_zbup_x]
sub edi,dword[ebx+offs_vert_zp+offs_zbup_x]
mov dword[norm],edi
mov dword[norm],edi ;p1.x-p0.x
fild dword[norm]
mov edi,dword[edx+offs_vert_zp+offs_zbup_y]
sub edi,dword[ebx+offs_vert_zp+offs_zbup_y]
mov dword[norm],edi
mov dword[norm],edi ;p2.y-p0.y
fimul dword[norm]
fsubp
faddp
;st0 = (p1.zp.x-p0.zp.x)*(p2.zp.y-p0.zp.y) - (p2.zp.x-p0.zp.x)*(p1.zp.y-p0.zp.y)
mov dword[front],0
fldz
fcompp
ftst
fstsw ax
ffree st0
fincstp
sahf
je .end_f
jbe @f ;jb @f ???
inc dword[front] ;front = 0.0 > norm
jae @f
inc dword[front] ;front = norm < 0.0
@@:
mov edi,[context]
mov eax,dword[edi+offs_cont_current_front_face]
xor dword[front],eax ;front ^= context.current_front_face
; back face culling
cmp dword[edi+offs_cont_cull_face_enabled],0
je .els_1

View File

@ -0,0 +1,886 @@
use32
org 0x0
db 'MENUET01'
dd 0x1
dd start
dd i_end
dd mem,stacktop
dd 0,cur_dir_path
include '../../../../../proc32.inc'
include '../../../../../macros.inc'
include '../../../../../develop/libraries/box_lib/load_lib.mac'
include '../../../../../dll.inc'
include '../opengl_const.inc'
@use_library
macro matr_cell c_funct,c_param,funct,param, dia
{
dia dword[esp-4*(c_param*(c_funct-funct)+(1+c_param-param))]
}
align 4
start:
load_library name_tgl, cur_dir_path, library_path, system_path, \
err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i
cmp eax,-1
jz button.exit
mcall 40,0x27
stdcall [kosglMakeCurrent], 10,10,400,350,ctx1
stdcall reshape, 400,350
; *** init ***
stdcall [glLightfv], GL_LIGHT0, GL_POSITION, pos
stdcall [glEnable], GL_CULL_FACE
stdcall [glEnable], GL_LIGHTING
stdcall [glEnable], GL_LIGHT0
stdcall [glEnable], GL_DEPTH_TEST
; make the gears
stdcall [glGenLists],1
mov [gear1],eax
stdcall [glNewList], eax, GL_COMPILE
stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red
;;;stdcall [glColor4fv], red
stdcall gear, 1.0, 4.0, 1.0, 20, 0.7
call [glEndList]
stdcall [glGenLists],1
mov [gear2],eax
stdcall [glNewList], eax, GL_COMPILE
stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green
;;;stdcall [glColor4fv], green
stdcall gear, 0.5, 2.0, 2.0, 10, 0.7
call [glEndList]
stdcall [glGenLists],1
mov [gear3],eax
stdcall [glNewList], eax, GL_COMPILE
stdcall [glMaterialfv], GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue
;;;stdcall [glColor4fv], blue
stdcall gear, 1.3, 2.0, 0.5, 10, 0.7
call [glEndList]
stdcall [glEnable], GL_NORMALIZE
; *** end init ***
call draw_3d
align 4
red_win:
call draw_window
align 4
still:
mcall 10
cmp al,1
jz red_win
cmp al,2
jz key
cmp al,3
jz button
jmp still
; new window size or exposure
align 4
proc reshape uses ebx ecx, width:dword, height:dword
locals
h dq ?
mh dq ?
endl
stdcall [glViewport], 0, 0, [width], [height]
stdcall [glMatrixMode], GL_PROJECTION
stdcall [glLoadIdentity]
fild dword[height]
fidiv dword[width]
fst qword[h] ;h = height / width
fchs
fstp qword[mh]
mov ebx,ebp
sub ebx,8
mov ecx,ebp
sub ecx,16
stdcall [glFrustum], dword p1, dword p2, ebx, ecx, dword p5, dword p6
stdcall [glMatrixMode], GL_MODELVIEW
stdcall [glLoadIdentity]
stdcall [glTranslatef], 0.0, 0.0, -40.0
stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
ret
endp
align 4
p1 dq -1.0
p2 dq 1.0
p5 dq 5.0
p6 dq 60.0
align 4
draw_window:
pushad
mcall 12,1
mov edx,0x33ffffff ;0x73ffffff
mcall 0,(50 shl 16)+430,(30 shl 16)+400,,,caption
stdcall [kosglSwapBuffers]
mcall 12,2
popad
ret
align 4
key:
mcall 2
cmp ah,27 ;Esc
je button.exit
cmp ah,61 ;+
jne @f
fld dword[scale]
fdiv dword[delt_sc]
fstp dword[scale]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
cmp ah,45 ;-
jne @f
fld dword[scale]
fmul dword[delt_sc]
fstp dword[scale]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
cmp ah,178 ;Up
jne @f
fld dword[view_rotx]
fadd dword[delt_size]
fstp dword[view_rotx]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
cmp ah,177 ;Down
jne @f
fld dword[view_rotx]
fsub dword[delt_size]
fstp dword[view_rotx]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
cmp ah,176 ;Left
jne @f
fld dword[view_roty]
fadd dword[delt_size]
fstp dword[view_roty]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
cmp ah,179 ;Right
jne @f
fld dword[view_roty]
fsub dword[delt_size]
fstp dword[view_roty]
call draw_3d
stdcall [kosglSwapBuffers]
@@:
jmp still
align 4
button:
mcall 17
cmp ah,1
jne still
.exit:
mcall -1
align 4
caption db 'Gears, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0
align 4
ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext
;sizeof.TinyGLContext = 28
align 4
draw_3d:
stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT
stdcall [glPushMatrix]
;;;stdcall [glScalef], [scale], [scale], [scale] ;???
stdcall [glRotatef], [view_rotx], 1.0, 0.0, 0.0
stdcall [glRotatef], [view_roty], 0.0, 1.0, 0.0
stdcall [glRotatef], [view_rotz], 0.0, 0.0, 1.0
stdcall [glPushMatrix]
stdcall [glTranslatef], -3.0, -2.0, 0.0
stdcall [glRotatef], [angle], 0.0, 0.0, 1.0
stdcall [glCallList],[gear1]
stdcall [glPopMatrix]
stdcall [glPushMatrix]
stdcall [glTranslatef], 3.1, -2.0, 0.0
push dword 1.0
push dword 0.0
push dword 0.0
finit
fld1
fld1
faddp
fchs
fld dword[angle]
fmulp
fsub dword[an_9]
fstp dword[esp-4]
sub esp,4
call [glRotatef] ;, -2.0*angle-9.0, 0.0, 0.0, 1.0
stdcall [glCallList],[gear2]
stdcall [glPopMatrix]
stdcall [glPushMatrix]
stdcall [glTranslatef], -3.1, 4.2, 0.0
push dword 1.0
push dword 0.0
push dword 0.0
finit
fld1
fld1
faddp
fchs
fld dword[angle]
fmulp
fsub dword[an_25]
fstp dword[esp-4]
sub esp,4
call [glRotatef] ;, -2.0*angle-25.0, 0.0, 0.0, 1.0
stdcall [glCallList],[gear3]
stdcall [glPopMatrix]
stdcall [glPopMatrix]
;;; tkSwapBuffers();
; count++;
; if (count==limit) {
; exit(0);
ret
align 4
an_9 dd 9.0
an_25 dd 25.0
qObj dd 0 ;???
scale dd 0.14 ;???
delt_sc dd 0.85 ;???
delt_size dd 5.0
align 4
pos dd 5.0, 5.0, 10.0, 0.0
red dd 0.8, 0.1, 0.0, 1.0
green dd 0.0, 0.8, 0.2, 1.0
blue dd 0.2, 0.2, 1.0, 1.0
view_rotx dd 20.0
view_roty dd 30.0
view_rotz dd 0.0
gear1 dd ?
gear2 dd ?
gear3 dd ?
angle dd 0.0
limit dd ?
count dd 1
;
; Draw a gear wheel. You'll probably want to call this function when
; building a display list since we do a lot of trig here.
;
; Input: inner_radius - radius of hole at center
; outer_radius - radius at center of teeth
; width - width of gear
; teeth - number of teeth
; tooth_depth - depth of tooth
;
align 4
proc gear uses eax ebx, inner_radius:dword, outer_radius:dword, width:dword, teeth:dword, tooth_depth:dword
locals
i dd ?
r0 dd ?
r1 dd ?
r2 dd ?
angle dd ?
da dd ?
u dd ?
v dd ?
endl
finit
mov eax,[inner_radius]
mov [r0],eax
fld1
fld1
faddp
fld dword[tooth_depth]
fdiv st0,st1
fld dword[outer_radius]
fsub st0,st1
fst dword[r1] ;r1 = outer_radius - tooth_depth/2.0
fadd dword[tooth_depth]
fstp dword[r2] ;r2 = outer_radius + tooth_depth/2.0
ffree st0 ;st0 = tooth_depth/2.0
fincstp
;st0 = 2.0
fldpi
fidiv dword[teeth]
fdiv st0,st1
fstp dword[da] ;da = M_PI / teeth / 2.0
stdcall [glShadeModel], GL_FLAT
stdcall [glNormal3f], 0.0, 0.0, 1.0
mov ebx,[teeth]
; draw front face
stdcall [glBegin], GL_QUAD_STRIP
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fld dword[width]
fdiv st0,st2
matr_cell 4,3,1,3,fst
matr_cell 4,3,2,3,fst
matr_cell 4,3,3,3,fst
matr_cell 4,3,4,3,fstp
fld st0
fsin
fmul dword[r0]
matr_cell 4,3,1,2,fst
matr_cell 4,3,3,2,fstp
fld st0
fcos
fmul dword[r0]
matr_cell 4,3,1,1,fst
matr_cell 4,3,3,1,fstp
fld st0
fsin
fmul dword[r1]
matr_cell 4,3,2,2,fstp
fld st0
fcos
fmul dword[r1]
matr_cell 4,3,2,1,fstp
;st0 = angle
fadd dword[da]
fadd dword[da]
fadd dword[da]
fld st0
fsin
fmul dword[r1]
matr_cell 4,3,4,2,fstp
fcos
fmul dword[r1]
matr_cell 4,3,4,1,fstp
sub esp,48 ;12*4
call [glVertex3f] ;, r0*cos(angle), r0*sin(angle), width*0.5
call [glVertex3f] ;, r1*cos(angle), r1*sin(angle), width*0.5
call [glVertex3f] ;, r0*cos(angle), r0*sin(angle), width*0.5
call [glVertex3f] ;, r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5
inc dword[i]
jmp @b
@@:
call [glEnd]
; draw front sides of teeth
stdcall [glBegin], GL_QUADS
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fld dword[width]
fdiv st0,st2
matr_cell 4,3,1,3,fst
matr_cell 4,3,2,3,fst
matr_cell 4,3,3,3,fst
matr_cell 4,3,4,3,fstp
fld st0
fcos
fmul dword[r1]
matr_cell 4,3,1,1,fstp
fld st0
fsin
fmul dword[r1]
matr_cell 4,3,1,2,fstp
fadd dword[da] ;st0 = angle+da
fld st0
fcos
fmul dword[r2]
matr_cell 4,3,2,1,fstp
fld st0
fsin
fmul dword[r2]
matr_cell 4,3,2,2,fstp
fadd dword[da] ;st0 = angle+2*da
fld st0
fcos
fmul dword[r2]
matr_cell 4,3,3,1,fstp
fld st0
fsin
fmul dword[r2]
matr_cell 4,3,3,2,fstp
fadd dword[da] ;st0 = angle+3*da
fld st0
fcos
fmul dword[r1]
matr_cell 4,3,4,1,fstp
fsin
fmul dword[r1]
matr_cell 4,3,4,2,fstp
sub esp,48 ;12*4
call [glVertex3f];, r1*cos(angle), r1*sin(angle), width*0.5
call [glVertex3f];, r2*cos(angle+da), r2*sin(angle+da), width*0.5
call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5
call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5
inc dword[i]
jmp @b
@@:
call [glEnd]
stdcall [glNormal3f], 0.0, 0.0, -1.0
; draw back face
stdcall [glBegin], GL_QUAD_STRIP
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fld dword[width]
fdiv st0,st2
fchs
matr_cell 4,3,1,3,fst
matr_cell 4,3,2,3,fst
matr_cell 4,3,3,3,fst
matr_cell 4,3,4,3,fstp
fld st0
fsin
fld st0
fmul dword[r1]
matr_cell 4,3,1,2,fstp
fmul dword[r0]
matr_cell 4,3,2,2,fst
matr_cell 4,3,4,2,fstp
fld st0
fcos
fld st0
fmul dword[r1]
matr_cell 4,3,1,1,fstp
fmul dword[r0]
matr_cell 4,3,2,1,fst
matr_cell 4,3,4,1,fstp
;st0 = angle
fadd dword[da]
fadd dword[da]
fadd dword[da]
fld st0
fsin
fmul dword[r1]
matr_cell 4,3,3,2,fstp
fcos
fmul dword[r1]
matr_cell 4,3,3,1,fstp
sub esp,48 ;12*4
call [glVertex3f];, r1*cos(angle), r1*sin(angle), -width*0.5
call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
inc dword[i]
jmp @b
@@:
call [glEnd]
; draw back sides of teeth
stdcall [glBegin], GL_QUADS
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fld dword[width]
fdiv st0,st2
fchs
matr_cell 4,3,1,3,fst
matr_cell 4,3,2,3,fst
matr_cell 4,3,3,3,fst
matr_cell 4,3,4,3,fstp
fld st0
fcos
fmul dword[r1]
matr_cell 4,3,4,1,fstp
fld st0
fsin
fmul dword[r1]
matr_cell 4,3,4,2,fstp
fadd dword[da] ;st0 = angle+da
fld st0
fcos
fmul dword[r2]
matr_cell 4,3,3,1,fstp
fld st0
fsin
fmul dword[r2]
matr_cell 4,3,3,2,fstp
fadd dword[da] ;st0 = angle+2*da
fld st0
fcos
fmul dword[r2]
matr_cell 4,3,2,1,fstp
fld st0
fsin
fmul dword[r2]
matr_cell 4,3,2,2,fstp
fadd dword[da] ;st0 = angle+3*da
fld st0
fcos
fmul dword[r1]
matr_cell 4,3,1,1,fstp
fsin
fmul dword[r1]
matr_cell 4,3,1,2,fstp
sub esp,48 ;12*4
call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5
call [glVertex3f];, r2*cos(angle+da), r2*sin(angle+da), -width*0.5
call [glVertex3f];, r1*cos(angle), r1*sin(angle), -width*0.5
inc dword[i]
jmp @b
@@:
call [glEnd]
; draw outward faces of teeth
stdcall [glBegin], GL_QUAD_STRIP
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fld dword[width]
fdiv st0,st2
matr_cell 12,3, 1,3,fst
matr_cell 12,3, 4,3,fst
matr_cell 12,3, 7,3,fst
matr_cell 12,3,10,3,fst
fchs
matr_cell 12,3, 2,3,fst
matr_cell 12,3, 5,3,fst
matr_cell 12,3, 8,3,fst
matr_cell 12,3,11,3,fstp
fldz
matr_cell 12,3, 3,3,fst
matr_cell 12,3, 6,3,fst
matr_cell 12,3, 9,3,fst
matr_cell 12,3,12,3,fstp
fld st0
fsin
matr_cell 12,3, 6,2,fst
matr_cell 12,3,12,2,fst
fmul dword[r1]
matr_cell 12,3, 1,2,fst
matr_cell 12,3, 2,2,fstp
fld st0
fcos
matr_cell 12,3, 6,1,fst
matr_cell 12,3,12,1,fst
fmul dword[r1]
matr_cell 12,3, 1,1,fst
matr_cell 12,3, 2,1,fstp
fadd dword[da] ;st0 = angle+da
fld st0
fcos
fmul dword[r2]
matr_cell 12,3, 4,1,fst
matr_cell 12,3, 5,1,fst
matr_cell 12,3, 1,1,fsub
fstp dword[u]
fld st0
fsin
fmul dword[r2]
matr_cell 12,3, 4,2,fst
matr_cell 12,3, 5,2,fst
matr_cell 12,3, 1,2,fsub
fst dword[v]
fmul st0,st0
fld dword[u]
fmul st0,st0
faddp
fsqrt ;st0 = len
fld dword[u]
fdiv st0,st1
fchs
matr_cell 12,3, 3,2,fstp
fld dword[v]
fdiv st0,st1
matr_cell 12,3, 3,1,fstp
ffree st0 ;len
fincstp
fadd dword[da] ;st0 = angle+2*da
fld st0
fcos
fmul dword[r2]
matr_cell 12,3, 7,1,fst
matr_cell 12,3, 8,1,fstp
fld st0
fsin
fmul dword[r2]
matr_cell 12,3, 7,2,fst
matr_cell 12,3, 8,2,fstp
fadd dword[da] ;st0 = angle+3*da
fld st0
fcos
fmul dword[r1]
matr_cell 12,3,10,1,fst
matr_cell 12,3,11,1,fst
matr_cell 12,3, 7,1,fsub
fchs
matr_cell 12,3, 9,2,fstp ;-u
fsin
fmul dword[r1]
matr_cell 12,3,10,2,fst
matr_cell 12,3,11,2,fst
matr_cell 12,3, 7,2,fsub
matr_cell 12,3, 9,1,fstp ;v
sub esp,144 ;12*12
call [glVertex3f];, r1*cos(angle), r1*sin(angle), width*0.5
call [glVertex3f];, r1*cos(angle), r1*sin(angle), -width*0.5
;u = r2*cos(angle+da) - r1*cos(angle)
;v = r2*sin(angle+da) - r1*sin(angle)
;len = sqrt( u*u + v*v )
;u /= len
;v /= len
call [glNormal3f];, v, -u, 0.0
call [glVertex3f];, r2*cos(angle+da), r2*sin(angle+da), width*0.5
call [glVertex3f];, r2*cos(angle+da), r2*sin(angle+da), -width*0.5
call [glNormal3f];, cos(angle), sin(angle), 0.0
call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), width*0.5
call [glVertex3f];, r2*cos(angle+2*da), r2*sin(angle+2*da), -width*0.5
;u = r1*cos(angle+3*da) - r2*cos(angle+2*da)
;v = r1*sin(angle+3*da) - r2*sin(angle+2*da)
call [glNormal3f];, v, -u, 0.0
call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), width*0.5
call [glVertex3f];, r1*cos(angle+3*da), r1*sin(angle+3*da), -width*0.5
call [glNormal3f];, cos(angle), sin(angle), 0.0
inc dword[i]
jmp @b
@@:
finit
fld1
fld1
faddp
fld dword[width]
fdiv st0,st1
matr_cell 2,3,1,3,fst
fchs
matr_cell 2,3,2,3,fstp
fldz
matr_cell 2,3,1,2,fst
matr_cell 2,3,2,2,fstp
fldz
fcos
fmul dword[r1]
matr_cell 2,3,1,1,fst
matr_cell 2,3,2,1,fstp
sub esp,24
call [glVertex3f];, r1*cos(0), r1*sin(0), width*0.5
call [glVertex3f];, r1*cos(0), r1*sin(0), -width*0.5
call [glEnd]
stdcall [glShadeModel], GL_SMOOTH
; draw inside radius cylinder
stdcall [glBegin], GL_QUAD_STRIP
mov dword[i],0
@@:
cmp dword[i],ebx
jg @f
finit
fld1
fld1
faddp
fldpi
fmul st0,st1
fimul dword[i]
fidiv dword[teeth]
fst dword[angle] ;angle = i * 2.0*M_PI / teeth
fldz
matr_cell 3,3,1,3,fstp
fld dword[width]
fdiv st0,st2
matr_cell 3,3,3,3,fst
fchs
matr_cell 3,3,2,3,fstp
fld st0
fsin
fchs
matr_cell 3,3,1,2,fst
fchs
fmul dword[r0]
matr_cell 3,3,2,2,fst
matr_cell 3,3,3,2,fstp
fcos
fchs
matr_cell 3,3,1,1,fst
fchs
fmul dword[r0]
matr_cell 3,3,2,1,fst
matr_cell 3,3,3,1,fstp
sub esp,36 ;12*3
call [glNormal3f];, -cos(angle), -sin(angle), 0.0
call [glVertex3f];, r0*cos(angle), r0*sin(angle), -width*0.5
call [glVertex3f];, r0*cos(angle), r0*sin(angle), width*0.5
inc dword[i]
jmp @b
@@:
call [glEnd]
;ffree st0 ;2.0
;fincstp
ret
endp
;--------------------------------------------------
align 4
import_lib_tinygl:
macro E_LIB n
{
n dd sz_#n
}
include '../export.inc'
dd 0,0
macro E_LIB n
{
sz_#n db `n,0
}
include '../export.inc'
;--------------------------------------------------
system_path db '/sys/lib/'
name_tgl db 'tinygl.obj',0
err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0
head_f_i:
head_f_l db 'System error',0
err_message_import db 'Error on load import library tinygl.obj',0
;--------------------------------------------------
align 16
i_end:
rb 4096
stacktop:
cur_dir_path:
rb 4096
library_path:
rb 4096
mem:

View File

@ -1,9 +1,5 @@
if DEBUG
align 4
txt_gl_scal db 'glopScale',0
txt_gl_tran db 'glopTranslate',0
align 4
proc gl_print_matrix uses eax ebx ecx edi, m:dword, rows:dword
mov ecx,[rows]
@ -120,9 +116,6 @@ proc glopLoadIdentity uses eax ebx, context:dword, p:dword
add ebx,eax
stdcall gl_M4_Id,[ebx+offs_cont_matrix_stack_ptr]
if DEBUG ;glopLoadIdentity
stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
end if
gl_matrix_update eax,ebx
ret
endp
@ -291,9 +284,6 @@ endl
stdcall gl_M4_Rotate, ecx
jmp .end_sw
@@: ;default:
if DEBUG ;glopRotete
stdcall dbg_print,txt_sp,m_1
end if
; normalize vector
fld dword[u0]
@ -438,9 +428,6 @@ end if
shl ebx,2
add ebx,eax
stdcall gl_M4_MulLeft,dword[ebx+offs_cont_matrix_stack_ptr],ecx
if DEBUG ;glopRotete
stdcall gl_print_matrix,ecx,4
end if
gl_matrix_update eax,ebx
jmp .end_f
.f2:
@ -485,15 +472,6 @@ proc glopScale uses eax ebx ecx, context:dword, p:dword
ffree st0
fincstp
if DEBUG ;glopScale
pushad
stdcall dbg_print,txt_gl_scal,txt_nl
mov ebx,[eax+offs_cont_matrix_mode]
shl ebx,2
add ebx,eax
stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
popad
end if
gl_matrix_update eax,ebx
ret
endp
@ -532,15 +510,6 @@ proc glopTranslate uses eax ebx ecx, context:dword, p:dword
ffree st0
fincstp
if DEBUG ;glopTranslate
pushad
stdcall dbg_print,txt_gl_tran,txt_nl
mov ebx,[eax+offs_cont_matrix_mode]
shl ebx,2
add ebx,eax
stdcall gl_print_matrix,[ebx+offs_cont_matrix_stack_ptr],4
popad
end if
gl_matrix_update eax,ebx
ret
endp
@ -581,9 +550,9 @@ endl
fstp dword[B] ;B = (top+bottom) / (top-bottom)
fld dword[ebx+24]
fsub dword[ebx+20] ;st0 = (farp-near)
fldz
fsub dword[ebx+24]
fsub dword[ebx+20] ;st0 = -(farp+near)
fld dword[ebx+24]
fadd dword[ebx+20]
fchs ;st0 = -(farp+near)
fdiv st0,st1
fstp dword[C] ;C = -(farp+near) / (farp-near)
fld dword[ebx+24]
@ -592,6 +561,12 @@ endl
fchs ;st0 = -(2.0*farp*near)
fdiv st0,st1
fstp dword[D] ;D = -(2.0*farp*near) / (farp-near)
ffree st0
fincstp
ffree st0
fincstp
ffree st0
fincstp
mov ecx,ebp
sub ecx,sizeof.M4

View File

@ -587,13 +587,13 @@ pushad
cmp dword[n],3
jne .end_f
mov eax,[edx+offs_cont_vertex]
mov [esp-4],eax
mov [esp-12],eax
add eax,sizeof.GLVertex
mov [esp-8],eax
add eax,sizeof.GLVertex
mov [esp-12],eax
mov [esp-4],eax
sub esp,12
stdcall gl_draw_triangle, edx
stdcall gl_draw_triangle, edx ;v0,v1,v2
xor eax,eax
mov dword[n],eax
jmp .end_f
@ -611,22 +611,22 @@ pushad
mov eax,[edx+offs_cont_vertex]
bt dword[edx+offs_cont_vertex_cnt],0
jc .case_1
mov [esp-12],eax
mov [esp-4],eax
add eax,sizeof.GLVertex
mov [esp-8],eax
add eax,sizeof.GLVertex
mov [esp-4],eax
mov [esp-12],eax
sub esp,12
stdcall gl_draw_triangle, edx ;&v[2],&v[1],&v[0]
stdcall gl_draw_triangle, edx ;v2,v1,v0
jmp .end_f
.case_1:
mov [esp-4],eax
mov [esp-12],eax
add eax,sizeof.GLVertex
mov [esp-8],eax
add eax,sizeof.GLVertex
mov [esp-12],eax
mov [esp-4],eax
sub esp,12
stdcall gl_draw_triangle, edx ;&v[0],&v[1],&v[2]
stdcall gl_draw_triangle, edx ;v0,v1,v2
jmp .end_f
@@:
cmp dword[edx+offs_cont_begin_type],GL_TRIANGLE_FAN
@ -634,15 +634,15 @@ pushad
cmp dword[n],3
jne .end_f
mov eax,[edx+offs_cont_vertex]
mov [esp-4],eax
mov [esp-12],eax
add eax,sizeof.GLVertex
mov [esp-8],eax
mov edi,eax
add eax,sizeof.GLVertex
mov [esp-12],eax
mov [esp-4],eax
mov esi,eax
sub esp,12
stdcall gl_draw_triangle, edx
stdcall gl_draw_triangle, edx ;v0,v1,v2
mov ecx,(sizeof.GLVertex)/4 ;((...)/4) что-бы использовать movsd вместо movsb
rep movsd ;context.vertex[1] = context.vertex[2]
mov dword[n],2
@ -678,20 +678,20 @@ pushad
cmp dword[n],4
jne .end_f
mov eax,[edx+offs_cont_vertex]
mov [esp-4],eax
mov [esp-12],eax
mov edi,eax
add eax,sizeof.GLVertex
mov [esp-8],eax
add eax,sizeof.GLVertex
mov [esp-12],eax
mov [esp-4],eax
mov esi,eax
sub esp,12
stdcall gl_draw_triangle, edx ;v0,v1,v2
mov [esp-12],eax
mov [esp-4],eax
add eax,sizeof.GLVertex
mov [esp-8],eax
sub eax,2*sizeof.GLVertex
mov [esp-4],eax
mov [esp-12],eax
sub esp,12
stdcall gl_draw_triangle, edx ;v1,v3,v2
mov ecx,(sizeof.GLVertex)/2 ;((...)/2) копируем 2 вершины

View File

@ -445,7 +445,7 @@ endl
cmp esi,ebx
jge .cycle_4_end
cmp esi,ecx ;if (l!=j)
je .cycle_5_end
je .if_end
mov eax,esi
imul eax,ebx
add eax,ecx
@ -491,6 +491,7 @@ endl
.cycle_5_end:
ffree st0 ;t
fincstp
.if_end:
inc esi
jmp .cycle_4
.cycle_4_end: