Subversion Repositories Kolibri OS

Rev

Rev 6143 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. struct GLUquadricObj
  2.         DrawStyle   dd ? ; GLU_FILL, LINE, SILHOUETTE, or POINT
  3.         Orientation dd ? ; GLU_INSIDE or GLU_OUTSIDE
  4.         TextureFlag dd ? ; Generate texture coords?
  5.         Normals     dd ? ; GLU_NONE, GLU_FLAT, or GLU_SMOOTH
  6.         ErrorFunc   dd ? ; Error handler callback function
  7. ends
  8.  
  9. offs_qobj_DrawStyle equ 0
  10. offs_qobj_Orientation equ 4
  11. offs_qobj_TextureFlag equ 8
  12. offs_qobj_Normals equ 12
  13. offs_qobj_ErrorFunc equ 16
  14.  
  15. ;void drawTorus(float rc, int numc, float rt, int numt)
  16. ;{
  17. ;}
  18.  
  19. ;static void normal3f(GLfloat x, GLfloat y, GLfloat z )
  20. ;{
  21. ;}
  22.  
  23. ;void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar )
  24. ;{
  25. ;}
  26.  
  27. ;void gluLookAt(GLdouble eyex, GLdouble eyey, GLdouble eyez,
  28. ;         GLdouble centerx, GLdouble centery, GLdouble centerz,
  29. ;         GLdouble upx, GLdouble upy, GLdouble upz)
  30. ;{
  31. ;}
  32.  
  33. align 16
  34. gluNewQuadric:
  35.         stdcall gl_malloc, sizeof.GLUquadricObj
  36.         or eax,eax
  37.         jz @f
  38.                 mov dword[eax+offs_qobj_DrawStyle],GLU_FILL
  39.                 mov dword[eax+offs_qobj_Orientation],GLU_OUTSIDE
  40.                 mov dword[eax+offs_qobj_TextureFlag],GL_FALSE
  41.                 mov dword[eax+offs_qobj_Normals],GLU_SMOOTH
  42.                 mov dword[eax+offs_qobj_ErrorFunc],0 ;NULL
  43.         @@:
  44.         ret
  45.  
  46. align 16
  47. proc gluDeleteQuadric, state:dword
  48.         cmp dword[state],0
  49.         je @f
  50.                 stdcall gl_free,[state]
  51.         @@:
  52.         ret
  53. endp
  54.  
  55. ;
  56. ; Set the drawing style to be GLU_FILL, GLU_LINE, GLU_SILHOUETTE,
  57. ; or GLU_POINT.
  58. ;
  59. align 16
  60. proc gluQuadricDrawStyle uses eax ebx, qobj:dword, drawStyle:dword
  61.         mov eax,[qobj]
  62.         or eax,eax
  63.         jz .err_q
  64.         mov ebx,[drawStyle]
  65.         cmp ebx,GLU_FILL
  66.         je @f
  67.         cmp ebx,GLU_LINE
  68.         je @f
  69.         cmp ebx,GLU_SILHOUETTE
  70.         je @f
  71.         cmp ebx,GLU_POINT
  72.         je @f
  73.         jmp .err_q
  74. align 4
  75.         @@:
  76.                 mov dword[eax+offs_qobj_DrawStyle],ebx
  77.                 jmp @f
  78. align 4
  79.         .err_q:
  80.                 stdcall dbg_print,sz_gluQuadricDrawStyle,err_9
  81.         @@:
  82.         ret
  83. endp
  84.  
  85. ;
  86. ; Set the orientation to GLU_INSIDE or GLU_OUTSIDE.
  87. ;
  88. align 16
  89. proc gluQuadricOrientation uses eax ebx, qobj:dword, orientation:dword
  90.         mov eax,[qobj]
  91.         or eax,eax
  92.         jz .err_q
  93.         mov ebx,[orientation]
  94.         cmp ebx,GLU_INSIDE
  95.         je @f
  96.         cmp ebx,GLU_OUTSIDE
  97.         je @f
  98.         jmp .err_q
  99. align 4
  100.         @@:
  101.                 mov dword[eax+offs_qobj_Orientation],ebx
  102.                 jmp @f
  103. align 4
  104.         .err_q:
  105.                 stdcall dbg_print,sz_gluQuadricOrientation,err_9
  106.         @@:
  107.         ret
  108. endp
  109.  
  110. align 16
  111. proc gluQuadricTexture uses eax ebx, qobj:dword, texture:dword
  112.         mov eax,[qobj]
  113.         or eax,eax
  114.         jz .err_q
  115.         mov ebx,[texture]
  116.         cmp ebx,GL_TRUE
  117.         je @f
  118.         cmp ebx,GL_FALSE
  119.         je @f
  120.         @@:
  121.                 mov dword[eax+offs_qobj_TextureFlag],ebx
  122.                 jmp @f
  123. align 4
  124.         .err_q:
  125.                 stdcall dbg_print,sz_gluQuadricTexture,err_9
  126.         @@:
  127.         ret
  128. endp
  129.  
  130. align 16
  131. proc gluCylinder qobj:dword, baseRadius:dword, topRadius:dword, height:dword,\
  132.         slices:dword, stacks:dword
  133. locals
  134.         da dq ? ;double
  135.         r dq ? ;double
  136.         dr dq ? ;double
  137.         dz dq ? ;double
  138.         x dd ? ;float
  139.         y dd ? ;float
  140.         z dd ? ;float
  141.         nz dd ? ;float
  142.         nsign dd ? ;float
  143.         i dd ? ;GLint
  144.         j dd ? ;GLint
  145.         du dd ? ;float
  146.         dv dd ? ;float
  147.         tcx dd ? ;float
  148.         tcy dd ? ;float
  149.         x2 dd ? ;float
  150.         y2 dd ? ;float
  151. endl
  152. pushad
  153.         mov edx,[qobj]
  154.         fld1
  155.         cmp dword[edx+offs_qobj_Orientation],GLU_INSIDE
  156.         jne @f
  157.                 fchs
  158.         @@:
  159.         fstp dword[nsign]
  160.  
  161.         fldpi
  162.         fadd st0,st0
  163.         fidiv dword[slices]
  164.         fstp qword[da] ;da = 2.0*M_PI / slices
  165.         mov ebx,[topRadius]
  166.         fld qword[ebx]
  167.         mov ecx,[baseRadius]
  168.         fsub qword[ecx]
  169.         fld st0 ;copy: topRadius-baseRadius
  170.         fidiv dword[stacks]
  171.         fstp qword[dr] ;dr = (topRadius-baseRadius) / stacks
  172.         mov eax,[height]
  173.         fld qword[eax]
  174.         fidiv dword[stacks]
  175.         fstp qword[dz] ;dz = height / stacks
  176.         fchs
  177.         fdiv qword[eax]
  178.         fstp dword[nz] ;nz = (baseRadius-topRadius) / height ; Z component of normal vectors
  179.  
  180.         cmp dword[edx+offs_qobj_DrawStyle],GLU_POINT
  181.         jne .else0
  182.                 stdcall glBegin,GL_POINTS
  183.                 mov ebx,[slices]
  184.                 mov dword[i],0
  185. align 4
  186.                 .cycle_0: ;for (i=0;i<slices;i++)
  187.                         cmp [i],ebx
  188.                         jge .cycle_0_end
  189.                         fild dword[i]
  190.                         fmul qword[da]
  191.                         fld st0
  192.                         fcos
  193.                         fst dword[x] ;x = cos(i*da)
  194.                         fmul dword[nsign]
  195.                         fstp dword[esp-12]
  196.                         fsin
  197.                         fst dword[y] ;y = sin(i*da)
  198.                         fmul dword[nsign]
  199.                         fstp dword[esp-8]
  200.                         fld dword[nz]
  201.                         fmul dword[nsign]
  202.                         fstp dword[esp-4]
  203.                         sub esp,12
  204.                         call glNormal3f ;x*nsign, y*nsign, nz*nsign
  205.  
  206.                         mov dword[z],0.0
  207.                         mov ecx,[baseRadius]
  208.                         fld qword[ecx]
  209.                         fstp qword[r] ;r = baseRadius
  210.                         mov ecx,[stacks]
  211.                         inc ecx
  212. align 4
  213.                         .cycle_1: ;for (j=0;j<=stacks;j++)
  214.                                 mov eax,[z]
  215.                                 mov [esp-4],eax
  216.                                 fld qword[r]
  217.                                 fld st0
  218.                                 fmul dword[y]
  219.                                 fstp dword[esp-8]
  220.                                 fmul dword[x]
  221.                                 fstp dword[esp-12]
  222.                                 sub esp,12
  223.                                 call glVertex3f ;x*r, y*r, z
  224.                                 fld dword[z]
  225.                                 fadd qword[dz]
  226.                                 fstp dword[z] ;z += dz
  227.                                 fld qword[r]
  228.                                 fadd qword[dr]
  229.                                 fstp qword[r] ;r += dr
  230.                                 dec ecx
  231.                                 jnz .cycle_1
  232.                         inc dword[i]
  233.                         jmp .cycle_0
  234. align 4
  235.                 .cycle_0_end:
  236.                 call glEnd
  237.                 jmp .end_f
  238.         .else0:
  239.         cmp dword[edx+offs_qobj_DrawStyle],GLU_LINE
  240.         je @f
  241.         cmp dword[edx+offs_qobj_DrawStyle],GLU_SILHOUETTE
  242.         je .else2
  243.                 jmp .else1
  244.         @@:
  245.                 ; Draw rings
  246.                 mov dword[z],0.0
  247.                 mov ecx,[baseRadius]
  248.                 fld qword[ecx]
  249.                 fstp qword[r] ;r = baseRadius
  250.                 mov ecx,[stacks]
  251.                 inc ecx
  252. align 4
  253.                 .cycle_2: ;for (j=0;j<=stacks;j++)
  254.                         stdcall glBegin,GL_LINE_LOOP
  255.                         mov ebx,[slices]
  256.                         mov dword[i],0
  257. align 4
  258.                         .cycle_3: ;for (i=0;i<slices;i++)
  259.                                 cmp [i],ebx
  260.                                 jge .cycle_3_end
  261.                                 fild dword[i]
  262.                                 fmul qword[da]
  263.                                 fld st0
  264.                                 fcos
  265.                                 fst dword[x] ;x = cos(i*da)
  266.                                 fmul dword[nsign]
  267.                                 fstp dword[esp-12]
  268.                                 fsin
  269.                                 fst dword[y] ;y = sin(i*da)
  270.                                 fmul dword[nsign]
  271.                                 fstp dword[esp-8]
  272.                                 fld dword[nz]
  273.                                 fmul dword[nsign]
  274.                                 fstp dword[esp-4]
  275.                                 sub esp,12
  276.                                 call glNormal3f ;x*nsign, y*nsign, nz*nsign
  277.                                 mov eax,[z]
  278.                                 mov [esp-4],eax
  279.                                 fld qword[r]
  280.                                 fld st0
  281.                                 fmul dword[y]
  282.                                 fstp dword[esp-8]
  283.                                 fmul dword[x]
  284.                                 fstp dword[esp-12]
  285.                                 sub esp,12
  286.                                 call glVertex3f ;x*r, y*r, z
  287.                                 inc dword[i]
  288.                                 jmp .cycle_3
  289. align 4
  290.                         .cycle_3_end:
  291.                         call glEnd
  292.                         fld dword[z]
  293.                         fadd qword[dz]
  294.                         fstp dword[z] ;z += dz
  295.                         fld qword[r]
  296.                         fadd qword[dr]
  297.                         fstp qword[r] ;r += dr
  298.                         dec ecx
  299.                         jnz .cycle_2
  300.                         jmp .else2_end
  301. align 4
  302.                 .else2:
  303.                 ; draw one ring at each end
  304. ;     if (baseRadius!=0.0) {
  305.                         stdcall glBegin,GL_LINE_LOOP
  306. align 4
  307.                         .cycle_4: ;for (i=0;i<slices;i++)
  308. ;               {
  309. ;           x = cos(i*da);
  310. ;           y = sin(i*da);
  311. ;           normal3f( x*nsign, y*nsign, nz*nsign );
  312. ;           glVertex3f( x*baseRadius, y*baseRadius, 0.0 );
  313. ;        }
  314.                         call glEnd
  315.                         stdcall glBegin,GL_LINE_LOOP
  316. align 4
  317.                         .cycle_5: ;for (i=0;i<slices;i++)
  318. ;               {
  319. ;           x = cos(i*da);
  320. ;           y = sin(i*da);
  321. ;           normal3f( x*nsign, y*nsign, nz*nsign );
  322. ;           glVertex3f( x*topRadius, y*topRadius, height );
  323. ;        }
  324.                         call glEnd
  325. ;     }
  326.                 .else2_end:
  327.                 ; draw length lines
  328.                 stdcall glBegin,GL_LINES
  329.                 mov ebx,[slices]
  330.                 mov dword[i],0
  331. align 4
  332.                 .cycle_6: ;for (i=0;i<slices;i++)
  333.                         cmp [i],ebx
  334.                         jge .cycle_6_end
  335.                         fild dword[i]
  336.                         fmul qword[da]
  337.                         fld st0
  338.                         fcos
  339.                         fst dword[x] ;x = cos(i*da)
  340.                         fmul dword[nsign]
  341.                         fstp dword[esp-12]
  342.                         fsin
  343.                         fst dword[y] ;y = sin(i*da)
  344.                         fmul dword[nsign]
  345.                         fstp dword[esp-8]
  346.                         fld dword[nz]
  347.                         fmul dword[nsign]
  348.                         fstp dword[esp-4]
  349.                         sub esp,12
  350.                         call glNormal3f ;x*nsign, y*nsign, nz*nsign
  351.                         mov dword[esp-4],0.0
  352.                         mov ecx,[baseRadius]
  353.                         fld qword[ecx]
  354.                         fld st0
  355.                         fmul dword[y]
  356.                         fstp dword[esp-8]
  357.                         fmul dword[x]
  358.                         fstp dword[esp-12]
  359.                         sub esp,12
  360.                         call glVertex3f ;x*baseRadius, y*baseRadius, 0.0
  361.                         mov eax,[height]
  362.                         fld qword[eax]
  363.                         fstp dword[esp-4]
  364.                         mov ecx,[topRadius]
  365.                         fld qword[ecx]
  366.                         fld st0
  367.                         fmul dword[y]
  368.                         fstp dword[esp-8]
  369.                         fmul dword[x]
  370.                         fstp dword[esp-12]
  371.                         sub esp,12
  372.                         call glVertex3f ;x*topRadius, y*topRadius, height
  373.                         inc dword[i]
  374.                         jmp .cycle_6
  375. align 4
  376.                 .cycle_6_end:
  377.                 call glEnd
  378.                 jmp .end_f
  379. align 4
  380.         .else1:
  381.         cmp dword[edx+offs_qobj_DrawStyle],GLU_FILL
  382.         jne .end_f
  383.                 fld1
  384.                 fidiv dword[slices]
  385.                 fstp dword[du] ;du = 1.0 / slices
  386.                 fld1
  387.                 fidiv dword[stacks]
  388.                 fstp dword[dv] ;dv = 1.0 / stacks
  389.                 mov dword[tcx],0.0
  390.                 mov dword[tcy],0.0
  391.                 mov ebx,[slices]
  392.                 mov dword[i],0
  393. align 4
  394.                 .cycle_7: ;for (i=0;i<slices;i++)
  395.                         cmp [i],ebx
  396.                         jge .cycle_7_end
  397.                         fild dword[i]
  398.                         fmul qword[da]
  399.                         fld st0
  400.                         fcos
  401.                         fstp dword[y] ;y1 = cos(i*da)
  402.                         fsin
  403.                         fchs
  404.                         fstp dword[x] ;x1 = -sin(i*da)
  405.                         inc dword[i]
  406.                         fild dword[i]
  407.                         fmul qword[da]
  408.                         fld st0
  409.                         fcos
  410.                         fstp dword[y2] ;y2 = cos((i+1)*da)
  411.                         fsin
  412.                         fchs
  413.                         fstp dword[x2] ;x2 = -sin((i+1)*da)
  414.                         mov dword[z],0.0
  415.                         mov ecx,[baseRadius]
  416.                         fld qword[ecx]
  417.                         fstp qword[r] ;r = baseRadius
  418.                         mov dword[tcy],0.0
  419.                         stdcall glBegin,GL_QUAD_STRIP
  420.                         mov ecx,[stacks]
  421.                         inc ecx
  422. align 4
  423.                         .cycle_8: ;for (j=0;j<=stacks;j++)
  424.  
  425.                                 fld dword[nsign]
  426.                                 ftst
  427.                                 fstsw ax
  428.                                 sahf
  429.                                 jbe .else3
  430.                                         ;if (nsign>0.0)
  431.                                         fld st0
  432.                                         fmul dword[nz]
  433.                                         fstp dword[esp-4]
  434.                                         fld st0
  435.                                         fmul dword[y]
  436.                                         fstp dword[esp-8]
  437.                                         fmul dword[x]
  438.                                         fstp dword[esp-12]
  439.                                         sub esp,12
  440.                                         call glNormal3f ;x1*nsign, y1*nsign, nz*nsign
  441.                                         cmp dword[edx+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  442.                                         je @f
  443.                                                 stdcall glTexCoord2f, [tcx],[tcy]
  444.                                         @@:
  445.                                         mov eax,[z]
  446.                                         mov [esp-4],eax
  447.                                         fld qword[r]
  448.                                         fld st0
  449.                                         fmul dword[y]
  450.                                         fstp dword[esp-8]
  451.                                         fmul dword[x]
  452.                                         fstp dword[esp-12]
  453.                                         sub esp,12
  454.                                         call glVertex3f ;x1*r, y1*r, z
  455.                                         fld dword[nsign]
  456.                                         fld st0
  457.                                         fmul dword[nz]
  458.                                         fstp dword[esp-4]
  459.                                         fld st0
  460.                                         fmul dword[y2]
  461.                                         fstp dword[esp-8]
  462.                                         fmul dword[x2]
  463.                                         fstp dword[esp-12]
  464.                                         sub esp,12
  465.                                         call glNormal3f ;x2*nsign, y2*nsign, nz*nsign
  466.                                         cmp dword[edx+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  467.                                         je @f
  468.                                                 push dword[tcy]
  469.                                                 fld dword[tcx]
  470.                                                 fadd dword[du]
  471.                                                 fstp dword[esp-4]
  472.                                                 sub esp,4
  473.                                                 call glTexCoord2f ;tcx+du, tcy
  474.                                         @@:
  475.                                         mov eax,[z]
  476.                                         mov [esp-4],eax
  477.                                         fld qword[r]
  478.                                         fld st0
  479.                                         fmul dword[y2]
  480.                                         fstp dword[esp-8]
  481.                                         fmul dword[x2]
  482.                                         fstp dword[esp-12]
  483.                                         sub esp,12
  484.                                         call glVertex3f ;x2*r, y2*r, z
  485.                                         jmp .else3_end
  486.                                 .else3:
  487.                                         fld st0
  488.                                         fmul dword[nz]
  489.                                         fstp dword[esp-4]
  490.                                         fld st0
  491.                                         fmul dword[y2]
  492.                                         fstp dword[esp-8]
  493.                                         fmul dword[x2]
  494.                                         fstp dword[esp-12]
  495.                                         sub esp,12
  496.                                         call glNormal3f ;x2*nsign, y2*nsign, nz*nsign
  497.                                         cmp dword[edx+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  498.                                         je @f
  499.                                                 stdcall glTexCoord2f, [tcx],[tcy]
  500.                                         @@:
  501.                                         mov eax,[z]
  502.                                         mov [esp-4],eax
  503.                                         fld qword[r]
  504.                                         fld st0
  505.                                         fmul dword[y2]
  506.                                         fstp dword[esp-8]
  507.                                         fmul dword[x2]
  508.                                         fstp dword[esp-12]
  509.                                         sub esp,12
  510.                                         call glVertex3f ;x2*r, y2*r, z
  511.                                         fld dword[nsign]
  512.                                         fld st0
  513.                                         fmul dword[nz]
  514.                                         fstp dword[esp-4]
  515.                                         fld st0
  516.                                         fmul dword[y]
  517.                                         fstp dword[esp-8]
  518.                                         fmul dword[x]
  519.                                         fstp dword[esp-12]
  520.                                         sub esp,12
  521.                                         call glNormal3f ;x1*nsign, y1*nsign, nz*nsign
  522.                                         cmp dword[edx+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  523.                                         je @f
  524.                                                 push dword[tcy]
  525.                                                 fld dword[tcx]
  526.                                                 fadd dword[du]
  527.                                                 fstp dword[esp-4]
  528.                                                 sub esp,4
  529.                                                 call glTexCoord2f ;tcx+du, tcy
  530.                                         @@:
  531.                                         mov eax,[z]
  532.                                         mov [esp-4],eax
  533.                                         fld qword[r]
  534.                                         fld st0
  535.                                         fmul dword[y]
  536.                                         fstp dword[esp-8]
  537.                                         fmul dword[x]
  538.                                         fstp dword[esp-12]
  539.                                         sub esp,12
  540.                                         call glVertex3f ;x1*r, y1*r, z
  541.                                 .else3_end:
  542.                                 fld dword[z]
  543.                                 fadd qword[dz]
  544.                                 fstp dword[z] ;z += dz
  545.                                 fld qword[r]
  546.                                 fadd qword[dr]
  547.                                 fstp qword[r] ;r += dr
  548.                                 fld dword[tcy]
  549.                                 fadd dword[dv]
  550.                                 fstp dword[tcy] ;tcy += dv
  551.                                 dec ecx
  552.                                 jnz .cycle_8
  553.                         call glEnd
  554.                         fld dword[tcx]
  555.                         fadd dword[du]
  556.                         fstp dword[tcx] ;tcx += du
  557.                         jmp .cycle_7
  558. align 4
  559.                 .cycle_7_end:
  560.         .end_f:
  561. popad
  562.         ret
  563. endp
  564.  
  565. ; Disk (adapted from Mesa)
  566.  
  567. ;void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops )
  568. ;{
  569. ;}
  570.  
  571. ;
  572. ; Sphere (adapted from Mesa)
  573. ;
  574.  
  575. ;input:
  576. ; float radius, int slices, int stacks
  577. align 16
  578. proc gluSphere qobj:dword, radius:dword, slices:dword, stacks:dword
  579. locals
  580.         rho dd ? ;float
  581.         drho dd ?
  582.         theta dd ?
  583.         dtheta dd ?
  584.         x dd ? ;float
  585.         y dd ? ;float
  586.         z dd ? ;float
  587.         s dd ? ;float
  588.         t dd ? ;float
  589.         d_s dd ? ;float
  590.         d_t dd ? ;float
  591.         i dd ? ;int
  592.         j dd ? ;int
  593.         imax dd ? ;int
  594.         normals dd ? ;int
  595.         nsign dd ? ;float
  596. endl
  597. pushad
  598.  
  599.         mov eax,[qobj]
  600.         cmp dword[eax+offs_qobj_Normals],GLU_NONE ;if (qobj.Normals==GLU_NONE)
  601.         jne .els_0
  602.                 mov dword[normals],GL_FALSE
  603.                 jmp @f
  604. align 4
  605.         .els_0:
  606.                 mov dword[normals],GL_TRUE
  607.         @@:
  608.         cmp dword[eax+offs_qobj_Orientation],GLU_INSIDE ;if (qobj.Orientation==GLU_INSIDE)
  609.         jne .els_1
  610.                 mov dword[nsign],-1.0
  611.                 jmp @f
  612. align 4
  613.         .els_1:
  614.                 mov dword[nsign],1.0
  615.         @@:
  616.  
  617.         fldpi
  618.         fidiv dword[stacks]
  619.         fstp dword[drho]
  620.         fld1
  621.         fldpi
  622.         fscale
  623.         fidiv dword[slices]
  624.         fstp dword[dtheta]
  625.         ffree st0
  626.         fincstp
  627.  
  628.         cmp dword[eax+offs_qobj_DrawStyle],GLU_FILL ;if (qobj.DrawStyle==GLU_FILL)
  629.         jne .if_glu_line
  630.  
  631.         ; draw +Z end as a triangle fan
  632.         stdcall glBegin,GL_TRIANGLE_FAN
  633.         cmp dword[normals],GL_TRUE
  634.         jne @f
  635.                 stdcall glNormal3f, 0.0, 0.0, 1.0
  636.         @@:
  637.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  638.         je @f
  639.                 stdcall glTexCoord2f, 0.5,1.0
  640.         @@:
  641.         sub esp,4
  642.         fld dword[nsign]
  643.         fmul dword[radius]
  644.         fstp dword[esp]
  645.         stdcall glVertex3f, 0.0, 0.0 ;, nsign * radius
  646.         fld dword[drho]
  647.         fcos
  648.         fmul dword[nsign]
  649.         fstp dword[z] ;z = nsign * cos(drho)
  650.         mov dword[j],0
  651.         mov ecx,[slices]
  652. align 4
  653.         .cycle_0: ;for (j=0;j<=slices;j++)
  654.                 cmp dword[j],ecx
  655.                 jg .cycle_0_end
  656.                 fld dword[drho]
  657.                 fsin
  658.                 je @f
  659.                         fild dword[j]
  660.                         fmul dword[dtheta]
  661.                         jmp .t0_end
  662. align 4
  663.                 @@:
  664.                         fldz
  665.                 .t0_end:
  666.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  667.                 fsin
  668.                 fchs
  669.                 fmul st0,st1
  670.                 fstp dword[x] ;x = -sin(theta) * sin(drho)
  671.                 fld dword[theta]
  672.                 fcos
  673.                 fmulp
  674.                 fstp dword[y] ;y = cos(theta) * sin(drho)
  675.                 cmp dword[normals],GL_TRUE
  676.                 jne @f
  677.                         fld dword[nsign]
  678.                         fld dword[z]
  679.                         fmul st0,st1
  680.                         fstp dword[esp-4]
  681.                         fld dword[y]
  682.                         fmul st0,st1
  683.                         fstp dword[esp-8]
  684.                         fld dword[x]
  685.                         fmulp
  686.                         fstp dword[esp-12]
  687.                         sub esp,12
  688.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  689.                 @@:
  690.                 fld dword[radius]
  691.                 fld dword[z]
  692.                 fmul st0,st1
  693.                 fstp dword[esp-4]
  694.                 fld dword[y]
  695.                 fmul st0,st1
  696.                 fstp dword[esp-8]
  697.                 fld dword[x]
  698.                 fmulp
  699.                 fstp dword[esp-12]
  700.                 sub esp,12
  701.                 call glVertex3f ;x*radius, y*radius, z*radius
  702.                 inc dword[j]
  703.                 jmp .cycle_0
  704. align 4
  705.         .cycle_0_end:
  706.         call glEnd
  707.  
  708.         fld1
  709.         fidiv dword[slices]
  710.         fstp dword[d_s] ;1.0 / slices
  711.         fld1
  712.         fidiv dword[stacks]
  713.         fstp dword[d_t] ;1.0 / stacks
  714.         mov dword[t],1.0 ; because loop now runs from 0
  715.         mov ebx,[stacks]
  716.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  717.         je .els_2
  718.                 mov dword[i],0
  719.                 mov [imax],ebx
  720.                 jmp @f
  721. align 4
  722.         .els_2:
  723.                 mov dword[i],1
  724.                 dec ebx
  725.                 mov [imax],ebx
  726.         @@:
  727.  
  728.         ; draw intermediate stacks as quad strips
  729.         mov ebx,[imax]
  730. align 4
  731.         .cycle_1: ;for (i=imin;i<imax;i++)
  732.         cmp dword[i],ebx
  733.         jge .cycle_1_end
  734.         fild dword[i]
  735.         fmul dword[drho]
  736.         fstp dword[rho] ;rho = i * drho
  737.         stdcall glBegin,GL_QUAD_STRIP
  738.         mov dword[s],0.0
  739.         mov dword[j],0
  740. align 4
  741.         .cycle_2: ;for (j=0;j<=slices;j++)
  742.                 cmp dword[j],ecx
  743.                 jg .cycle_2_end
  744.                 fld dword[rho]
  745.                 fsin
  746.                 je @f
  747.                         fild dword[j]
  748.                         fmul dword[dtheta]
  749.                         jmp .t1_end
  750. align 4
  751.                 @@:
  752.                         fldz
  753.                 .t1_end:
  754.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  755.                 fsin
  756.                 fchs
  757.                 fmul st0,st1
  758.                 fstp dword[x] ;x = -sin(theta) * sin(rho)
  759.                 fld dword[theta]
  760.                 fcos
  761.                 fmulp
  762.                 fstp dword[y] ;y = cos(theta) * sin(rho)
  763.                 fld dword[rho]
  764.                 fcos
  765.                 fmul dword[nsign]
  766.                 fstp dword[z] ;z = nsign * cos(rho)
  767.                 cmp dword[normals],GL_TRUE
  768.                 jne @f
  769.                         fld dword[nsign]
  770.                         fld dword[z]
  771.                         fmul st0,st1
  772.                         fstp dword[esp-4]
  773.                         fld dword[y]
  774.                         fmul st0,st1
  775.                         fstp dword[esp-8]
  776.                         fld dword[x]
  777.                         fmulp
  778.                         fstp dword[esp-12]
  779.                         sub esp,12
  780.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  781.                 @@:
  782.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  783.                 je @f
  784.                         stdcall glTexCoord2f, [s],[t]
  785.                 @@:
  786.                 fld dword[radius]
  787.                 fld dword[z]
  788.                 fmul st0,st1
  789.                 fstp dword[esp-4]
  790.                 fld dword[y]
  791.                 fmul st0,st1
  792.                 fstp dword[esp-8]
  793.                 fld dword[x]
  794.                 fmulp
  795.                 fstp dword[esp-12]
  796.                 sub esp,12
  797.                 call glVertex3f ;x*radius, y*radius, z*radius
  798.                 fld dword[rho]
  799.                 fadd dword[drho]
  800.                 fsin ;st0 = sin(rho+drho)
  801.                 fld dword[theta]
  802.                 fsin
  803.                 fchs
  804.                 fmul st0,st1
  805.                 fstp dword[x] ;x = -sin(theta) * sin(rho+drho)
  806.                 fld dword[theta]
  807.                 fcos
  808.                 fmulp
  809.                 fstp dword[y] ;y = cos(theta) * sin(rho+drho)
  810.                 fld dword[rho]
  811.                 fadd dword[drho]
  812.                 fcos
  813.                 fmul dword[nsign]
  814.                 fstp dword[z] ;z = nsign * cos(rho+drho)
  815.                 cmp dword[normals],GL_TRUE
  816.                 jne @f
  817.                         fld dword[nsign]
  818.                         fld dword[z]
  819.                         fmul st0,st1
  820.                         fstp dword[esp-4]
  821.                         fld dword[y]
  822.                         fmul st0,st1
  823.                         fstp dword[esp-8]
  824.                         fld dword[x]
  825.                         fmulp
  826.                         fstp dword[esp-12]
  827.                         sub esp,12
  828.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  829.                 @@:
  830.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  831.                 je @f
  832.                         fld dword[t]
  833.                         fsub dword[d_t]
  834.                         fstp dword[esp-4]
  835.                         sub esp,4
  836.                         stdcall glTexCoord2f, [s] ;,t-dt
  837.                         fld dword[s]
  838.                         fadd dword[d_s]
  839.                         fstp dword[s]
  840.                 @@:
  841.                 fld dword[radius]
  842.                 fld dword[z]
  843.                 fmul st0,st1
  844.                 fstp dword[esp-4]
  845.                 fld dword[y]
  846.                 fmul st0,st1
  847.                 fstp dword[esp-8]
  848.                 fld dword[x]
  849.                 fmulp
  850.                 fstp dword[esp-12]
  851.                 sub esp,12
  852.                 call glVertex3f ;x*radius, y*radius, z*radius
  853.                 inc dword[j]
  854.                 jmp .cycle_2
  855. align 4
  856.                 .cycle_2_end:
  857.         call glEnd
  858.         fld dword[t]
  859.         fsub dword[d_t]
  860.         fstp dword[t]
  861.         inc dword[i]
  862.         jmp .cycle_1
  863. align 4
  864.         .cycle_1_end:
  865.  
  866.         ; draw -Z end as a triangle fan
  867.         stdcall glBegin,GL_TRIANGLE_FAN
  868.         cmp dword[normals],GL_TRUE
  869.         jne @f
  870.                 stdcall glNormal3f, 0.0, 0.0, -1.0
  871.         @@:
  872.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  873.         je @f
  874.                 stdcall glTexCoord2f, 0.5,0.0
  875.                 mov dword[s],1.0
  876.                 mov ebx,[d_t]
  877.                 mov [t],ebx
  878.         @@:
  879.         sub esp,4
  880.         fld dword[radius]
  881.         fchs
  882.         fmul dword[nsign]
  883.         fstp dword[esp]
  884.         stdcall glVertex3f, 0.0, 0.0 ;, -radius*nsign
  885.         fldpi
  886.         fsub dword[drho]
  887.         fst dword[rho]
  888.         fcos
  889.         fmul dword[nsign]
  890.         fstp dword[z] ;z = nsign * cos(rho)
  891.         mov [j],ecx
  892. align 4
  893.         .cycle_3: ;for (j=slices;j>=0;j--)
  894.                 cmp dword[j],0
  895.                 jl .cycle_3_end
  896.                 fld dword[rho]
  897.                 fsin
  898.                 je @f
  899.                         fild dword[j]
  900.                         fmul dword[dtheta]
  901.                         jmp .t2_end
  902. align 4
  903.                 @@:
  904.                         fldz
  905.                 .t2_end:
  906.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  907.                 fsin
  908.                 fchs
  909.                 fmul st0,st1
  910.                 fstp dword[x] ;x = -sin(theta) * sin(rho)
  911.                 fld dword[theta]
  912.                 fcos
  913.                 fmulp
  914.                 fstp dword[y] ;y = cos(theta) * sin(rho)
  915.                 cmp dword[normals],GL_TRUE
  916.                 jne @f
  917.                         fld dword[nsign]
  918.                         fld dword[z]
  919.                         fmul st0,st1
  920.                         fstp dword[esp-4]
  921.                         fld dword[y]
  922.                         fmul st0,st1
  923.                         fstp dword[esp-8]
  924.                         fld dword[x]
  925.                         fmul st0,st1
  926.                         fstp dword[esp-12]
  927.                         sub esp,12
  928.                         ffree st0
  929.                         fincstp
  930.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  931.                 @@:
  932.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  933.                 je @f
  934.                         stdcall glTexCoord2f, [s],[t]
  935.                         fld dword[s]
  936.                         fsub dword[d_s]
  937.                         fstp dword[s]
  938.                 @@:
  939.                 fld dword[radius]
  940.                 fld dword[z]
  941.                 fmul st0,st1
  942.                 fstp dword[esp-4]
  943.                 fld dword[y]
  944.                 fmul st0,st1
  945.                 fstp dword[esp-8]
  946.                 fld dword[x]
  947.                 fmulp
  948.                 fstp dword[esp-12]
  949.                 sub esp,12
  950.                 call glVertex3f ;x*radius, y*radius, z*radius
  951.                 dec dword[j]
  952.                 jmp .cycle_3
  953. align 4
  954.         .cycle_3_end:
  955.         call glEnd
  956.         jmp .end_f
  957.  
  958. align 4
  959.         .if_glu_line:
  960.         cmp dword[eax+offs_qobj_DrawStyle],GLU_LINE ;if (qobj.DrawStyle==GLU_LINE)
  961.         je @f
  962.         cmp dword[eax+offs_qobj_DrawStyle],GLU_SILHOUETTE ;if (qobj.DrawStyle==GLU_SILHOUETTE)
  963.         je @f
  964.         jmp .if_glu_point
  965. align 4
  966.         @@:
  967.  
  968.         ; draw stack lines
  969.         mov dword[i],1
  970.         mov ebx,[stacks]
  971.         mov ecx,[slices]
  972. align 4
  973.         .cycle_4: ;for (i=1;i<stacks;i++)
  974.                 cmp dword[i],ebx
  975.                 jge .cycle_4_end
  976.                 ; stack line at i==stacks-1 was missing here
  977.  
  978.                 fild dword[i]
  979.                 fmul dword[drho]
  980.                 fstp dword[rho] ;rho = i * drho
  981.                 stdcall glBegin,GL_LINE_LOOP
  982.                 mov dword[j],0
  983. align 4
  984.                 .cycle_5: ;for (j=0;j<slices;j++)
  985.                         cmp dword[j],ecx
  986.                         jge .cycle_5_end
  987.                         fild dword[j]
  988.                         fmul dword[dtheta]
  989.                         fst dword[theta] ;theta = j * dtheta;
  990.                         fcos
  991.                         fld dword[rho]
  992.                         fsin
  993.                         fxch ;толкаем sin(rho) в st1
  994.                         fmul st0,st1
  995.                         fstp dword[x] ;x = cos(theta) * sin(rho)
  996.                         fld dword[theta]
  997.                         fsin
  998.                         fmulp ;множим на sin(rho) ранее записанный в st1
  999.                         fstp dword[y] ;y = sin(theta) * sin(rho)
  1000.                         fld dword[rho]
  1001.                         fcos
  1002.                         fstp dword[z] ;z = cos(rho)
  1003.                         cmp dword[normals],GL_TRUE
  1004.                         jne @f
  1005.                                 fld dword[nsign]
  1006.                                 fld dword[z]
  1007.                                 fmul st0,st1
  1008.                                 fstp dword[esp-4]
  1009.                                 fld dword[y]
  1010.                                 fmul st0,st1
  1011.                                 fstp dword[esp-8]
  1012.                                 fld dword[x]
  1013.                                 fmulp
  1014.                                 fstp dword[esp-12]
  1015.                                 sub esp,12
  1016.                                 stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  1017.                         @@:
  1018.                         fld dword[radius]
  1019.                         fld dword[z]
  1020.                         fmul st0,st1
  1021.                         fstp dword[esp-4]
  1022.                         fld dword[y]
  1023.                         fmul st0,st1
  1024.                         fstp dword[esp-8]
  1025.                         fld dword[x]
  1026.                         fmulp
  1027.                         fstp dword[esp-12]
  1028.                         sub esp,12
  1029.                         call glVertex3f ;x*radius, y*radius, z*radius
  1030.                         inc dword[j]
  1031.                         jmp .cycle_5
  1032. align 4
  1033.                 .cycle_5_end:
  1034.                 call glEnd
  1035.                 inc dword[i]
  1036.                 jmp .cycle_4
  1037. align 4
  1038.         .cycle_4_end:
  1039.  
  1040.         ; draw slice lines
  1041.         mov dword[j],0
  1042. align 4
  1043.         .cycle_6: ;for (j=0;j<slices;j++)
  1044.                 cmp dword[j],ecx
  1045.                 jge .cycle_6_end
  1046.                 fild dword[j]
  1047.                 fmul dword[dtheta]
  1048.                 fstp dword[theta] ;theta = j * dtheta;
  1049.                 stdcall glBegin,GL_LINE_STRIP
  1050.                 mov dword[i],0
  1051. align 4
  1052.                 .cycle_7: ;for (i=0;i<=stacks;i++)
  1053.                         cmp dword[i],ebx
  1054.                         jg .cycle_7_end
  1055.                         fild dword[i]
  1056.                         fmul dword[drho]
  1057.                         fst dword[rho] ;rho = i * drho
  1058.                         fsin
  1059.                         fld dword[theta]
  1060.                         fcos
  1061.                         fmul st0,st1
  1062.                         fstp dword[x] ;x = cos(theta) * sin(rho)
  1063.                         fld dword[theta]
  1064.                         fsin
  1065.                         fmulp
  1066.                         fstp dword[y] ;y = sin(theta) * sin(rho)
  1067.                         fld dword[rho]
  1068.                         fcos
  1069.                         fstp dword[z] ;z = cos(rho)
  1070.                         cmp dword[normals],GL_TRUE
  1071.                         jne @f
  1072.                                 fld dword[nsign]
  1073.                                 fld dword[z]
  1074.                                 fmul st0,st1
  1075.                                 fstp dword[esp-4]
  1076.                                 fld dword[y]
  1077.                                 fmul st0,st1
  1078.                                 fstp dword[esp-8]
  1079.                                 fld dword[x]
  1080.                                 fmulp
  1081.                                 fstp dword[esp-12]
  1082.                                 sub esp,12
  1083.                                 stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  1084.                         @@:
  1085.                         fld dword[radius]
  1086.                         fld dword[z]
  1087.                         fmul st0,st1
  1088.                         fstp dword[esp-4]
  1089.                         fld dword[y]
  1090.                         fmul st0,st1
  1091.                         fstp dword[esp-8]
  1092.                         fld dword[x]
  1093.                         fmulp
  1094.                         fstp dword[esp-12]
  1095.                         sub esp,12
  1096.                         call glVertex3f ;x*radius, y*radius, z*radius
  1097.                         inc dword[i]
  1098.                         jmp .cycle_7
  1099. align 4
  1100.                 .cycle_7_end:
  1101.                 call glEnd
  1102.                 inc dword[j]
  1103.                 jmp .cycle_6
  1104. align 4
  1105.         .cycle_6_end:
  1106.         jmp .end_f
  1107.  
  1108. align 4
  1109.         .if_glu_point:
  1110.         cmp dword[eax+offs_qobj_DrawStyle],GLU_POINT ;if (qobj.DrawStyle==GLU_POINT)
  1111.         jne .end_f
  1112.  
  1113.         ; top and bottom-most points
  1114.         stdcall glBegin,GL_POINTS
  1115.         cmp dword[normals],GL_TRUE
  1116.         jne @f
  1117.                 stdcall glNormal3f, 0.0,0.0,dword[nsign]
  1118.         @@:
  1119.         stdcall glVertex3f, 0.0,0.0,dword[radius]
  1120.         cmp dword[normals],GL_TRUE
  1121.         jne @f
  1122.                 sub esp,4
  1123.                 fld dword[nsign]
  1124.                 fchs
  1125.                 fstp dword[esp]
  1126.                 stdcall glNormal3f, 0.0,0.0 ;,-nsign
  1127.         @@:
  1128.         sub esp,4
  1129.         fld dword[radius]
  1130.         fchs
  1131.         fstp dword[esp]
  1132.         stdcall glVertex3f, 0.0,0.0 ;,-radius
  1133.  
  1134.         ; loop over stacks
  1135.         mov dword[i],1
  1136.         mov ebx,[stacks]
  1137.         mov ecx,[slices]
  1138. align 4
  1139.         .cycle_8: ;for (i=1;i<stacks;i++)
  1140.                 cmp dword[i],ebx
  1141.                 jge .cycle_8_end
  1142.                 fild dword[i]
  1143.                 fmul dword[drho]
  1144.                 fstp dword[rho] ;rho = i * drho
  1145.  
  1146.                 mov dword[j],0
  1147. align 4
  1148.                 .cycle_9: ;for (j=0;j<slices;j++)
  1149.                         cmp dword[j],ecx
  1150.                         jge .cycle_9_end
  1151.                         fild dword[j]
  1152.                         fmul dword[dtheta]
  1153.                         fst dword[theta] ;theta = j * dtheta;
  1154.                         fcos
  1155.                         fld dword[rho]
  1156.                         fsin
  1157.                         fxch ;толкаем sin(rho) в st1
  1158.                         fmul st0,st1
  1159.                         fstp dword[x] ;x = cos(theta) * sin(rho)
  1160.                         fld dword[theta]
  1161.                         fsin
  1162.                         fmulp ;множим на sin(rho) ранее записанный в st1
  1163.                         fstp dword[y] ;y = sin(theta) * sin(rho)
  1164.                         fld dword[rho]
  1165.                         fcos
  1166.                         fstp dword[z] ;z = cos(rho)
  1167.                         cmp dword[normals],GL_TRUE
  1168.                         jne @f
  1169.                                 fld dword[nsign]
  1170.                                 fld dword[z]
  1171.                                 fmul st0,st1
  1172.                                 fstp dword[esp-4]
  1173.                                 fld dword[y]
  1174.                                 fmul st0,st1
  1175.                                 fstp dword[esp-8]
  1176.                                 fld dword[x]
  1177.                                 fmulp
  1178.                                 fstp dword[esp-12]
  1179.                                 sub esp,12
  1180.                                 stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  1181.                         @@:
  1182.                         fld dword[radius]
  1183.                         fld dword[z]
  1184.                         fmul st0,st1
  1185.                         fstp dword[esp-4]
  1186.                         fld dword[y]
  1187.                         fmul st0,st1
  1188.                         fstp dword[esp-8]
  1189.                         fld dword[x]
  1190.                         fmulp
  1191.                         fstp dword[esp-12]
  1192.                         sub esp,12
  1193.                         call glVertex3f ;x*radius, y*radius, z*radius
  1194.                         inc dword[j]
  1195.                         jmp .cycle_9
  1196. align 4
  1197.                 .cycle_9_end:
  1198.                 inc dword[i]
  1199.                 jmp .cycle_8
  1200. align 4
  1201.         .cycle_8_end:
  1202.         call glEnd
  1203.  
  1204.         .end_f:
  1205. popad
  1206.         ret
  1207. endp
  1208.