Subversion Repositories Kolibri OS

Rev

Rev 6108 | 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 4
  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 4
  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. ;void gluQuadricDrawStyle(GLUquadricObj *obj, int style)
  56. ;{
  57. ;}
  58.  
  59. ;void gluCylinder(GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius, GLdouble height, GLint slices, GLint stacks )
  60. ;{
  61. ;}
  62.  
  63. ; Disk (adapted from Mesa)
  64.  
  65. ;void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius, GLint slices, GLint loops )
  66. ;{
  67. ;}
  68.  
  69. ;
  70. ; Sphere (adapted from Mesa)
  71. ;
  72.  
  73. ;input:
  74. ; float radius, int slices, int stacks
  75. align 4
  76. proc gluSphere qobj:dword, radius:dword, slices:dword, stacks:dword
  77. locals
  78.         rho dd ? ;float
  79.         drho dd ?
  80.         theta dd ?
  81.         dtheta dd ?
  82.         x dd ? ;float
  83.         y dd ? ;float
  84.         z dd ? ;float
  85.         s dd ? ;float
  86.         t dd ? ;float
  87.         d_s dd ? ;float
  88.         d_t dd ? ;float
  89.         i dd ? ;int
  90.         j dd ? ;int
  91.         imax dd ? ;int
  92.         normals dd ? ;int
  93.         nsign dd ? ;float
  94. endl
  95. pushad
  96.  
  97.         mov eax,[qobj]
  98.         cmp dword[eax+offs_qobj_Normals],GLU_NONE ;if (qobj.Normals==GLU_NONE)
  99.         jne .els_0
  100.                 mov dword[normals],GL_FALSE
  101.                 jmp @f
  102.         .els_0:
  103.                 mov dword[normals],GL_TRUE
  104.         @@:
  105.         cmp dword[eax+offs_qobj_Orientation],GLU_INSIDE ;if (qobj.Orientation==GLU_INSIDE)
  106.         jne .els_1
  107.                 mov dword[nsign],-1.0
  108.                 jmp @f
  109.         .els_1:
  110.                 mov dword[nsign],1.0
  111.         @@:
  112.  
  113.         fldpi
  114.         fidiv dword[stacks]
  115.         fstp dword[drho]
  116.         fld1
  117.         fldpi
  118.         fscale
  119.         fidiv dword[slices]
  120.         fstp dword[dtheta]
  121.         ffree st0
  122.         fincstp
  123.  
  124.         ; draw +Z end as a triangle fan
  125.         stdcall glBegin,GL_TRIANGLE_FAN
  126.         cmp dword[normals],GL_TRUE
  127.         jne @f
  128.                 stdcall glNormal3f, 0.0, 0.0, 1.0
  129.         @@:
  130.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  131.         je @f
  132. ;glTexCoord2f(0.5,0.0)
  133.         @@:
  134.         sub esp,4
  135.         fld dword[nsign]
  136.         fmul dword[radius]
  137.         fstp dword[esp]
  138.         stdcall glVertex3f, 0.0, 0.0 ;, nsign * radius
  139.         fld dword[drho]
  140.         fcos
  141.         fmul dword[nsign]
  142.         fstp dword[z] ;z = nsign * cos(drho)
  143.         mov dword[j],0
  144.         mov ecx,[slices]
  145. align 4
  146.         .cycle_0: ;for (j=0;j<=slices;j++)
  147.                 cmp dword[j],ecx
  148.                 jg .cycle_0_end
  149.                 fld dword[drho]
  150.                 fsin
  151.                 je @f
  152.                         fild dword[j]
  153.                         fmul dword[dtheta]
  154.                         jmp .t0_end
  155.                 @@:
  156.                         fldz
  157.                 .t0_end:
  158.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  159.                 fsin
  160.                 fchs
  161.                 fmul st0,st1
  162.                 fstp dword[x] ;x = -sin(theta) * sin(drho)
  163.                 fld dword[theta]
  164.                 fcos
  165.                 fmulp
  166.                 fstp dword[y] ;y = cos(theta) * sin(drho)
  167.                 cmp dword[normals],GL_TRUE
  168.                 jne @f
  169.                         fld dword[nsign]
  170.                         fld dword[z]
  171.                         fmul st0,st1
  172.                         fstp dword[esp-4]
  173.                         fld dword[y]
  174.                         fmul st0,st1
  175.                         fstp dword[esp-8]
  176.                         fld dword[x]
  177.                         fmul st0,st1
  178.                         fstp dword[esp-12]
  179.                         sub esp,12
  180.                         ffree st0
  181.                         fincstp
  182.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  183.                 @@:
  184.                 fld dword[radius]
  185.                 fld dword[z]
  186.                 fmul st0,st1
  187.                 fstp dword[esp-4]
  188.                 fld dword[y]
  189.                 fmul st0,st1
  190.                 fstp dword[esp-8]
  191.                 fld dword[x]
  192.                 fmul st0,st1
  193.                 fstp dword[esp-12]
  194.                 sub esp,12
  195.                 ffree st0
  196.                 fincstp
  197.                 call glVertex3f ;x*radius, y*radius, z*radius
  198.                 inc dword[j]
  199.                 jmp .cycle_0
  200.         .cycle_0_end:
  201.         stdcall glEnd
  202.  
  203.         fld1
  204.         fidiv dword[slices]
  205.         fstp dword[d_s] ;1.0 / slices
  206.         fld1
  207.         fidiv dword[stacks]
  208.         fstp dword[d_t] ;1.0 / stacks
  209.         mov dword[t],1.0 ; because loop now runs from 0
  210.         mov ebx,[stacks]
  211.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  212.         je .els_2
  213.                 mov dword[i],0
  214.                 mov [imax],ebx
  215.                 jmp @f
  216.         .els_2:
  217.                 mov dword[i],1
  218.                 dec ebx
  219.                 mov [imax],ebx
  220.         @@:
  221.  
  222.         ; draw intermediate stacks as quad strips
  223.         mov ebx,[imax]
  224. align 4
  225.         .cycle_1: ;for (i=imin;i<imax;i++)
  226.         cmp dword[i],ebx
  227.         jge .cycle_1_end
  228.         fild dword[i]
  229.         fmul dword[drho]
  230.         fstp dword[rho] ;rho = i * drho
  231.         stdcall glBegin,GL_QUAD_STRIP
  232.         mov dword[s],0.0
  233.         mov dword[j],0
  234. align 4
  235.         .cycle_2: ;for (j=0;j<=slices;j++)
  236.                 cmp dword[j],ecx
  237.                 jg .cycle_2_end
  238.                 fld dword[rho]
  239.                 fsin
  240.                 je @f
  241.                         fild dword[j]
  242.                         fmul dword[dtheta]
  243.                         jmp .t1_end
  244.                 @@:
  245.                         fldz
  246.                 .t1_end:
  247.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  248.                 fsin
  249.                 fchs
  250.                 fmul st0,st1
  251.                 fstp dword[x] ;x = -sin(theta) * sin(rho)
  252.                 fld dword[theta]
  253.                 fcos
  254.                 fmulp
  255.                 fstp dword[y] ;y = cos(theta) * sin(rho)
  256.                 fld dword[rho]
  257.                 fcos
  258.                 fmul dword[nsign]
  259.                 fstp dword[z] ;z = nsign * cos(rho)
  260.                 cmp dword[normals],GL_TRUE
  261.                 jne @f
  262.                         fld dword[nsign]
  263.                         fld dword[z]
  264.                         fmul st0,st1
  265.                         fstp dword[esp-4]
  266.                         fld dword[y]
  267.                         fmul st0,st1
  268.                         fstp dword[esp-8]
  269.                         fld dword[x]
  270.                         fmul st0,st1
  271.                         fstp dword[esp-12]
  272.                         sub esp,12
  273.                         ffree st0
  274.                         fincstp
  275.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  276.                 @@:
  277.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  278.                 je @f
  279. ;glTexCoord2f(s,1-t)
  280.                 @@:
  281.                 fld dword[radius]
  282.                 fld dword[z]
  283.                 fmul st0,st1
  284.                 fstp dword[esp-4]
  285.                 fld dword[y]
  286.                 fmul st0,st1
  287.                 fstp dword[esp-8]
  288.                 fld dword[x]
  289.                 fmul st0,st1
  290.                 fstp dword[esp-12]
  291.                 sub esp,12
  292.                 ffree st0
  293.                 fincstp
  294.                 call glVertex3f ;x*radius, y*radius, z*radius
  295.                 fld dword[rho]
  296.                 fadd dword[drho]
  297.                 fsin ;st0 = sin(rho+drho)
  298.                 fld dword[theta]
  299.                 fsin
  300.                 fchs
  301.                 fmul st0,st1
  302.                 fstp dword[x] ;x = -sin(theta) * sin(rho+drho)
  303.                 fld dword[theta]
  304.                 fcos
  305.                 fmulp
  306.                 fstp dword[y] ;y = cos(theta) * sin(rho+drho)
  307.                 fld dword[rho]
  308.                 fadd dword[drho]
  309.                 fcos
  310.                 fmul dword[nsign]
  311.                 fstp dword[z] ;z = nsign * cos(rho+drho)
  312.                 cmp dword[normals],GL_TRUE
  313.                 jne @f
  314.                         fld dword[nsign]
  315.                         fld dword[z]
  316.                         fmul st0,st1
  317.                         fstp dword[esp-4]
  318.                         fld dword[y]
  319.                         fmul st0,st1
  320.                         fstp dword[esp-8]
  321.                         fld dword[x]
  322.                         fmul st0,st1
  323.                         fstp dword[esp-12]
  324.                         sub esp,12
  325.                         ffree st0
  326.                         fincstp
  327.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  328.                 @@:
  329.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  330.                 je @f
  331. ;glTexCoord2f(s,1-(t-dt))
  332.                         fld dword[s]
  333.                         fadd dword[d_s]
  334.                         fstp dword[s]
  335.                 @@:
  336.                 fld dword[radius]
  337.                 fld dword[z]
  338.                 fmul st0,st1
  339.                 fstp dword[esp-4]
  340.                 fld dword[y]
  341.                 fmul st0,st1
  342.                 fstp dword[esp-8]
  343.                 fld dword[x]
  344.                 fmul st0,st1
  345.                 fstp dword[esp-12]
  346.                 sub esp,12
  347.                 ffree st0
  348.                 fincstp
  349.                 call glVertex3f ;x*radius, y*radius, z*radius
  350.                 inc dword[j]
  351.                 jmp .cycle_2
  352.                 .cycle_2_end:
  353.         stdcall glEnd
  354.         fld dword[t]
  355.         fsub dword[d_t]
  356.         fstp dword[t]
  357.         inc dword[i]
  358.         jmp .cycle_1
  359.         .cycle_1_end:
  360.  
  361.         ; draw -Z end as a triangle fan
  362.         stdcall glBegin,GL_TRIANGLE_FAN
  363.         cmp dword[normals],GL_TRUE
  364.         jne @f
  365.                 stdcall glNormal3f, 0.0, 0.0, -1.0
  366.         @@:
  367.         cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  368.         je @f
  369. ;glTexCoord2f(0.5,1.0)
  370.                 mov dword[s],1.0
  371.                 mov ebx,[d_t]
  372.                 mov [t],ebx
  373.         @@:
  374.         sub esp,4
  375.         fld dword[radius]
  376.         fchs
  377.         fmul dword[nsign]
  378.         fstp dword[esp]
  379.         stdcall glVertex3f, 0.0, 0.0 ;, -radius*nsign
  380.         fldpi
  381.         fsub dword[drho]
  382.         fst dword[rho]
  383.         fcos
  384.         fmul dword[nsign]
  385.         fstp dword[z] ;z = nsign * cos(rho)
  386.         mov [j],ecx
  387.         .cycle_3: ;for (j=slices;j>=0;j--)
  388.                 cmp dword[j],0
  389.                 jl .cycle_3_end
  390.                 fld dword[rho]
  391.                 fsin
  392.                 je @f
  393.                         fild dword[j]
  394.                         fmul dword[dtheta]
  395.                         jmp .t2_end
  396.                 @@:
  397.                         fldz
  398.                 .t2_end:
  399.                 fst dword[theta] ;theta = (j==slices) ? 0.0 : j * dtheta
  400.                 fsin
  401.                 fchs
  402.                 fmul st0,st1
  403.                 fstp dword[x] ;x = -sin(theta) * sin(rho)
  404.                 fld dword[theta]
  405.                 fcos
  406.                 fmulp
  407.                 fstp dword[y] ;y = cos(theta) * sin(rho)
  408.                 cmp dword[normals],GL_TRUE
  409.                 jne @f
  410.                         fld dword[nsign]
  411.                         fld dword[z]
  412.                         fmul st0,st1
  413.                         fstp dword[esp-4]
  414.                         fld dword[y]
  415.                         fmul st0,st1
  416.                         fstp dword[esp-8]
  417.                         fld dword[x]
  418.                         fmul st0,st1
  419.                         fstp dword[esp-12]
  420.                         sub esp,12
  421.                         ffree st0
  422.                         fincstp
  423.                         stdcall glNormal3f ;x*nsign, y*nsign, z*nsign
  424.                 @@:
  425.                 cmp dword[eax+offs_qobj_TextureFlag],0 ;if (qobj.TextureFlag)
  426.                 je @f
  427. ;glTexCoord2f(s,1-t)
  428.                         fld dword[s]
  429.                         fsub dword[d_s]
  430.                         fstp dword[s]
  431.                 @@:
  432.                 fld dword[radius]
  433.                 fld dword[z]
  434.                 fmul st0,st1
  435.                 fstp dword[esp-4]
  436.                 fld dword[y]
  437.                 fmul st0,st1
  438.                 fstp dword[esp-8]
  439.                 fld dword[x]
  440.                 fmul st0,st1
  441.                 fstp dword[esp-12]
  442.                 sub esp,12
  443.                 ffree st0
  444.                 fincstp
  445.                 call glVertex3f ;x*radius, y*radius, z*radius
  446.                 dec dword[j]
  447.                 jmp .cycle_3
  448.         .cycle_3_end:
  449.         stdcall glEnd
  450. popad
  451.         ret
  452. endp
  453.