Subversion Repositories Kolibri OS

Rev

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

  1. use32
  2.         org 0x0
  3.         db 'MENUET01'
  4.         dd 0x1
  5.         dd start
  6.         dd i_end
  7.         dd mem,stacktop
  8.         dd 0,cur_dir_path
  9.  
  10. include '../../../../../../programs/proc32.inc'
  11. include '../../../../../../programs/macros.inc'
  12. include '../../../../../../programs/develop/libraries/box_lib/load_lib.mac'
  13. include '../../../../../../programs/dll.inc'
  14. include '../opengl_const.inc'
  15.  
  16. @use_library
  17.  
  18. align 4
  19. start:
  20.         load_library name_tgl, cur_dir_path, library_path, system_path, \
  21.                 err_message_found_lib, head_f_l, import_lib_tinygl, err_message_import, head_f_i
  22.         cmp eax,-1
  23.         jz button.exit
  24.  
  25.         mcall 40,0x27
  26.  
  27. stdcall [kosglMakeCurrent], 10,10,300,225,ctx1
  28. stdcall [glEnable], GL_DEPTH_TEST
  29. stdcall [gluNewQuadric]
  30. mov [qObj],eax
  31.  
  32. stdcall [glClearColor], 0.5,0.5,0.5,0.0
  33. stdcall [glShadeModel], GL_SMOOTH
  34.  
  35. call draw_3d
  36.  
  37. align 4
  38. red_win:
  39.         call draw_window
  40.  
  41. align 4
  42. still:
  43.         mcall 10
  44.         cmp al,1
  45.         jz red_win
  46.         cmp al,2
  47.         jz key
  48.         cmp al,3
  49.         jz button
  50.         jmp still
  51.  
  52. align 4
  53. draw_window:
  54.         pushad
  55.         mcall 12,1
  56.  
  57.         mov edx,0x33ffffff ;0x73ffffff
  58.         mcall 0,(50 shl 16)+330,(30 shl 16)+275,,,caption
  59.         stdcall [kosglSwapBuffers]
  60.  
  61.         mcall 12,2
  62.         popad
  63.         ret
  64.  
  65. align 4
  66. key:
  67.         mcall 2
  68.  
  69.         cmp ah,27 ;Esc
  70.         je button.exit
  71.  
  72.         cmp ah,61 ;+
  73.         jne @f
  74.             fld dword[scale]
  75.             fadd dword[delt_sc]
  76.             fstp dword[scale]
  77.             call draw_3d
  78.             stdcall [kosglSwapBuffers]
  79.         @@:
  80.         cmp ah,45 ;-
  81.         jne @f
  82.             fld dword[scale]
  83.             fsub dword[delt_sc]
  84.             fstp dword[scale]
  85.             call draw_3d
  86.             stdcall [kosglSwapBuffers]
  87.         @@:
  88.         cmp ah,178 ;Up
  89.         jne @f
  90.                 fld dword[angle_y]
  91.                 fadd dword[delt_size]
  92.                 fstp dword[angle_y]
  93.                 call draw_3d
  94.                 stdcall [kosglSwapBuffers]
  95.         @@:
  96.         cmp ah,177 ;Down
  97.         jne @f
  98.                 fld dword[angle_y]
  99.                 fsub dword[delt_size]
  100.                 fstp dword[angle_y]
  101.                 call draw_3d
  102.                 stdcall [kosglSwapBuffers]
  103.         @@:
  104.         cmp ah,176 ;Left
  105.         jne @f
  106.                 fld dword[angle_z]
  107.                 fadd dword[delt_size]
  108.                 fstp dword[angle_z]
  109.                 call draw_3d
  110.                 stdcall [kosglSwapBuffers]
  111.         @@:
  112.         cmp ah,179 ;Right
  113.         jne @f
  114.                 fld dword[angle_z]
  115.                 fsub dword[delt_size]
  116.                 fstp dword[angle_z]
  117.                 call draw_3d
  118.                 stdcall [kosglSwapBuffers]
  119.         @@:
  120.  
  121.         jmp still
  122.  
  123. align 4
  124. button:
  125.         mcall 17
  126.         cmp ah,1
  127.         jne still
  128. .exit:
  129.         stdcall [gluDeleteQuadric], [qObj]
  130.         mcall -1
  131.  
  132.  
  133. align 4
  134. caption db 'Test gluSphere, [Esc] - exit, [<-],[->],[Up],[Down] - rotate',0
  135. align 4
  136. ctx1 db 28 dup (0) ;TinyGLContext or KOSGLContext
  137. ;sizeof.TinyGLContext = 28
  138.  
  139. align 4
  140. draw_3d:
  141. stdcall [glClear], GL_COLOR_BUFFER_BIT + GL_DEPTH_BUFFER_BIT ;очистим буфер цвета и глубины
  142.  
  143. stdcall [glColor3f], 1.0, 1.0, 0.0
  144.  
  145. stdcall [glPushMatrix]
  146.         call SetLight
  147.  
  148.         stdcall [glTranslatef], 0.0,0.0,0.5
  149.         stdcall [glScalef], [scale], [scale], [scale]
  150.  
  151.         stdcall [glRotatef], [angle_z],0.0,0.0,1.0
  152.         stdcall [glRotatef], [angle_y],0.0,1.0,0.0
  153.         stdcall [gluSphere], [qObj], 1.0, 16,16
  154.  
  155.         stdcall [glColor3f], 1.0, 0.0, 0.0
  156.         stdcall [glTranslatef], -1.6,0.0,0.0
  157.         stdcall [gluSphere], [qObj], 0.55, 8,8
  158.  
  159.         stdcall [glColor3f], 0.0, 0.0, 1.0
  160.         stdcall [glTranslatef], 3.2,0.0,0.0
  161.         stdcall [gluSphere], [qObj], 0.55, 8,8
  162. stdcall [glPopMatrix]
  163. ret
  164.  
  165. align 4
  166. SetLight:
  167.     stdcall [glLightfv], GL_LIGHT0, GL_POSITION, light_position
  168.     stdcall [glLightfv], GL_LIGHT0, GL_SPOT_DIRECTION, light_dir
  169.  
  170.     stdcall [glLightfv], GL_LIGHT0, GL_DIFFUSE, white_light
  171.     stdcall [glLightfv], GL_LIGHT0, GL_SPECULAR, white_light
  172.  
  173.         stdcall [glEnable], GL_COLOR_MATERIAL
  174.         stdcall [glColorMaterial], GL_FRONT, GL_AMBIENT_AND_DIFFUSE
  175.         stdcall [glMaterialfv], GL_FRONT, GL_SPECULAR, mat_specular
  176.         stdcall [glMaterialf], GL_FRONT, GL_SHININESS, mat_shininess
  177.     stdcall [glLightModelfv], GL_LIGHT_MODEL_AMBIENT, lmodel_ambient
  178.  
  179.         stdcall [glEnable],GL_LIGHTING
  180.         stdcall [glEnable],GL_LIGHT0
  181. ret
  182.  
  183. qObj dd 0
  184.  
  185. scale dd 0.4
  186. delt_sc dd 0.05
  187. angle_z dd 0.0
  188. angle_y dd 0.0
  189. delt_size dd 3.0
  190.  
  191. light_position dd 0.0, 0.0, 2.0, 1000.0 ; Расположение источника [0][1][2], чем ближе [3] к 0, тем ярче свет
  192. light_dir dd 0.0,0.0,0.0 ;направление лампы
  193. mat_specular dd 0.3, 0.3, 0.3, 1.0 ; Цвет блика
  194. mat_shininess dd 3.0 ; Размер блика (обратная пропорция)
  195. white_light dd 0.8, 0.8, 0.8, 1.0 ; Цвет и интенсивность освещения, генерируемого источником
  196. lmodel_ambient dd 0.2, 0.2, 0.2, 1.0 ; Параметры фонового освещения
  197.  
  198. ;--------------------------------------------------
  199. align 4
  200. import_lib_tinygl:
  201.  
  202. macro E_LIB n
  203. {
  204.         n dd sz_#n
  205. }
  206. include '../export.inc'
  207.         dd 0,0
  208. macro E_LIB n
  209. {
  210.         sz_#n db `n,0
  211. }
  212. include '../export.inc'
  213.  
  214. ;--------------------------------------------------
  215. system_path db '/sys/lib/'
  216. name_tgl db 'tinygl.obj',0
  217. err_message_found_lib db 'Sorry I cannot load library tinygl.obj',0
  218. head_f_i:
  219. head_f_l db 'System error',0
  220. err_message_import db 'Error on load import library tinygl.obj',0
  221. ;--------------------------------------------------
  222.  
  223. i_end:
  224.         rb 1024
  225. stacktop:
  226. cur_dir_path:
  227.         rb 4096
  228. library_path:
  229.         rb 4096
  230. mem:
  231.