2 single: RingOpenGL と RingAllegro の用法 (3D グラフィックス); はじめに
4 ====================================================
5 RingOpenGL と RingAllegro の用法 (3D グラフィックス)
6 ====================================================
9 RingOpenGL と RingAllegro の用法を学びます。
13 pair: RingOpenGL と RingAllegro の用法 (3D グラフィックス); 3D 立方体とテクスチャ
23 load "gamelib.ring" # RingAllegro ライブラリ
24 load "opengl21lib.ring" # RingOpenGL ライブラリ
26 #==============================================================
29 func al_game_start # al_run_main() から呼び出されます。
30 main() # main 関数本体を呼び出します。
31 #==============================================================
40 class GraphicsApp from GraphicsAppBase
52 bitmap = al_load_bitmap("ring.bmp")
53 texture = al_get_opengl_texture(bitmap)
57 al_destroy_bitmap(bitmap)
64 glViewport(0, 0, w, h)
65 glMatrixMode(GL_PROJECTION)
68 gluPerspective(45,ratio,1,100)
69 glMatrixMode(GL_MODELVIEW)
72 glEnable(GL_TEXTURE_2D)
73 glShadeModel(GL_SMOOTH)
74 glClearColor(0.0, 0.0, 0.0, 0.5)
76 glEnable(GL_DEPTH_TEST)
77 glEnable(GL_CULL_FACE)
78 glDepthFunc(GL_LEQUAL)
79 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
81 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
83 glTranslatef(0.0,0.0,-5.0)
85 glRotatef(xrot,1.0,0.0,0.0)
86 glRotatef(yrot,0.0,1.0,0.0)
87 glRotatef(zrot,0.0,0.0,1.0)
89 glBindTexture(GL_TEXTURE_2D, texture)
93 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
94 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
95 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
96 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
98 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
99 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
100 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
101 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
103 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
104 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, 1.0, 1.0)
105 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, 1.0, 1.0)
106 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
108 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, -1.0, -1.0)
109 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, -1.0, -1.0)
110 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
111 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
113 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
114 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
115 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
116 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
118 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
119 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
120 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
121 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
129 class GraphicsAppBase
131 display event_queue ev timeout
144 Key = [false,false,false,false]
146 TITLE = "Graphics Application"
158 al_init_image_addon()
159 al_set_new_display_flags(ALLEGRO_OPENGL)
160 display = al_create_display(SCREEN_W,SCREEN_H)
161 al_set_Window_title(display,TITLE)
162 al_clear_to_color(al_map_rgb(0,0,0))
163 event_queue = al_create_event_queue()
164 al_register_event_source(event_queue,
165 al_get_display_event_source(display))
166 ev = al_new_allegro_event()
167 timeout = al_new_allegro_timeout()
168 al_init_timeout(timeout, 0.06)
169 timer = al_create_timer(1.0 / FPS)
170 al_register_event_source(event_queue,
171 al_get_timer_event_source(timer))
172 al_start_timer(timer)
174 al_register_event_source(event_queue,
175 al_get_mouse_event_source())
176 al_install_keyboard()
177 al_register_event_source(event_queue,
178 al_get_keyboard_event_source())
183 al_init_timeout(timeout, 0.06)
184 al_wait_for_event_until(event_queue, ev, timeout)
185 switch al_get_allegro_event_type(ev)
186 on ALLEGRO_EVENT_DISPLAY_CLOSE
188 on ALLEGRO_EVENT_TIMER
190 on ALLEGRO_EVENT_MOUSE_AXES
191 mouse_x = al_get_allegro_event_mouse_x(ev)
192 mouse_y = al_get_allegro_event_mouse_y(ev)
193 on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
194 mouse_x = al_get_allegro_event_mouse_x(ev)
195 mouse_y = al_get_allegro_event_mouse_y(ev)
196 on ALLEGRO_EVENT_MOUSE_BUTTON_UP
198 on ALLEGRO_EVENT_KEY_DOWN
199 switch al_get_allegro_event_keyboard_keycode(ev)
207 key[KEY_RIGHT] = true
209 on ALLEGRO_EVENT_KEY_UP
210 switch al_get_allegro_event_keyboard_keycode(ev)
214 key[KEY_DOWN] = false
216 key[KEY_LEFT] = false
218 key[KEY_RIGHT] = false
219 on ALLEGRO_KEY_ESCAPE
223 if redraw and al_is_event_queue_empty(event_queue)
234 al_destroy_timer(timer)
235 al_destroy_allegro_event(ev)
236 al_destroy_allegro_timeout(timeout)
237 al_destroy_event_queue(event_queue)
238 al_destroy_display(display)
245 func destroyResources
249 .. image:: ringcube3d.png
253 pair: RingOpenGL と RingAllegro の用法 (3D グラフィックス); 複数の立方体
263 load "gamelib.ring" # RingAllegro ライブラリ
264 load "opengl21lib.ring" # RingOpenGL ライブラリ
266 #==============================================================
269 func al_game_start # al_run_main() により呼び出されます。
270 main() # main 関数本体を呼び出します。
271 #==============================================================
281 class GraphicsApp from GraphicsAppBase
285 bitmap bitmap2 bitmap3
286 texture texture2 texture3
297 bitmap = al_load_bitmap("sky1.jpg")
298 texture = al_get_opengl_texture(bitmap)
300 bitmap2 = al_load_bitmap("sky2.jpg")
301 texture2 = al_get_opengl_texture(bitmap2)
303 bitmap3 = al_load_bitmap("sky3.jpg")
304 texture3 = al_get_opengl_texture(bitmap3)
306 func destroyResources
308 al_destroy_bitmap(bitmap)
309 al_destroy_bitmap(bitmap2)
310 al_destroy_bitmap(bitmap3)
321 glViewport(0, 0, w, h)
322 glMatrixMode(GL_PROJECTION)
324 gluPerspective(-nPerspective,ratio,1,nPerspective)
325 glMatrixMode(GL_MODELVIEW)
327 glEnable(GL_TEXTURE_2D)
328 glShadeModel(GL_SMOOTH)
329 glClearColor(0.0, 0.0, 0.0, 0.5)
331 glEnable(GL_DEPTH_TEST)
332 glEnable(GL_CULL_FACE)
333 glDepthFunc(GL_LEQUAL)
334 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
335 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
338 cube(5,-3.4,-5,:sky1)
343 cube(-5,0.5,-5,:sky2)
355 func cube(x,y,z,nTexture)
358 glRotatef(xrot,1.0,0.0,0.0)
359 glRotatef(yrot,0.0,1.0,0.0)
360 glRotatef(zrot,0.0,0.0,1.0)
363 func drawcube(cTexture)
367 glBindTexture(GL_TEXTURE_2D, texture)
369 glBindTexture(GL_TEXTURE_2D, texture2)
371 glBindTexture(GL_TEXTURE_2D, texture3)
377 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
378 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
379 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
380 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
382 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
383 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
384 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
385 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
387 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
388 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, 1.0, 1.0)
389 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, 1.0, 1.0)
390 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
392 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, -1.0, -1.0)
393 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, -1.0, -1.0)
394 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
395 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
398 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
399 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
400 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
401 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
404 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
405 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
406 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
407 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
411 class GraphicsAppBase
413 display event_queue ev timeout
426 Key = [false,false,false,false]
428 TITLE = "Graphics Application"
440 al_init_image_addon()
441 al_set_new_display_flags(ALLEGRO_OPENGL)
442 display = al_create_display(SCREEN_W,SCREEN_H)
443 al_set_Window_title(display,TITLE)
444 al_clear_to_color(al_map_rgb(0,0,0))
445 event_queue = al_create_event_queue()
446 al_register_event_source(event_queue,
447 al_get_display_event_source(display))
448 ev = al_new_allegro_event()
449 timeout = al_new_allegro_timeout()
450 al_init_timeout(timeout, 0.06)
451 timer = al_create_timer(1.0 / FPS)
452 al_register_event_source(event_queue,
453 al_get_timer_event_source(timer))
454 al_start_timer(timer)
456 al_register_event_source(event_queue,
457 al_get_mouse_event_source())
458 al_install_keyboard()
459 al_register_event_source(event_queue,
460 al_get_keyboard_event_source())
465 al_init_timeout(timeout, 0.06)
466 al_wait_for_event_until(event_queue, ev, timeout)
467 switch al_get_allegro_event_type(ev)
468 on ALLEGRO_EVENT_DISPLAY_CLOSE
470 on ALLEGRO_EVENT_TIMER
472 on ALLEGRO_EVENT_MOUSE_AXES
473 mouse_x = al_get_allegro_event_mouse_x(ev)
474 mouse_y = al_get_allegro_event_mouse_y(ev)
475 on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
476 mouse_x = al_get_allegro_event_mouse_x(ev)
477 mouse_y = al_get_allegro_event_mouse_y(ev)
478 on ALLEGRO_EVENT_MOUSE_BUTTON_UP
480 on ALLEGRO_EVENT_KEY_DOWN
481 switch al_get_allegro_event_keyboard_keycode(ev)
489 key[KEY_RIGHT] = true
491 on ALLEGRO_EVENT_KEY_UP
492 switch al_get_allegro_event_keyboard_keycode(ev)
496 key[KEY_DOWN] = false
498 key[KEY_LEFT] = false
500 key[KEY_RIGHT] = false
501 on ALLEGRO_KEY_ESCAPE
505 if redraw and al_is_event_queue_empty(event_queue)
516 al_destroy_timer(timer)
517 al_destroy_allegro_event(ev)
518 al_destroy_allegro_timeout(timeout)
519 al_destroy_event_queue(event_queue)
520 al_destroy_display(display)
527 func destroyResources
532 .. image:: manycubes.png
536 pair: RingOpenGL と RingAllegro の用法 (3D グラフィックス); TicTacToe 3D ゲーム
548 load "gamelib.ring" # RingAllegro ライブラリ
549 load "opengl21lib.ring" # RingOpenGL ライブラリ
551 #==============================================================
554 func al_game_start # al_run_main() により呼び出されます。
555 main() # main 関数本体を呼び出します。
556 #==============================================================
563 class TicTacToe3D from GameLogic
566 TITLE = "TicTacToe 3D"
568 oBackground = new GameBackground
569 oGameSound = new GameSound
570 oGameCube = new GameCube
571 oGameOver = new GameOver
572 oGameInterface = new GameInterface
575 oGameOver.loadresources()
576 oGameSound.loadresources()
577 oBackGround.loadresources()
578 oGameCube.loadresources()
580 func destroyResources
581 oGameOver.destroyResources()
582 oGameSound.destroyResources()
583 oBackGround.destroyResources()
584 oGameCube.destroyResources()
588 oGameInterface.update(self)
591 oGameInterface.MouseClickEvent(self)
602 glViewport(0, 0, w, h)
603 glMatrixMode(GL_PROJECTION)
605 gluPerspective(-120,ratio,1,120)
606 glMatrixMode(GL_MODELVIEW)
608 glEnable(GL_TEXTURE_2D)
609 glShadeModel(GL_SMOOTH)
610 glClearColor(0.0, 0.0, 0.0, 0.5)
612 glEnable(GL_DEPTH_TEST)
613 glEnable(GL_CULL_FACE)
614 glDepthFunc(GL_LEQUAL)
615 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)
619 aGameMap = oGame.aGameMap
620 cube( 5 , -3 , -5 , aGameMap[1][1] )
621 cube( 0 , -3 , -5 , aGameMap[1][2] )
622 cube( -5 , -3 , -5 , aGameMap[1][3] )
623 cube( 5 , 1 , -5 , aGameMap[2][1] )
624 cube( 0 , 1 , -5 , aGameMap[2][2] )
625 cube( -5 , 1 , -5 , aGameMap[2][3] )
626 cube( 5 , 5 , -5 , aGameMap[3][1] )
627 cube( 0 , 5 , -5 , aGameMap[3][2] )
628 cube( -5 , 5 , -5 , aGameMap[3][3] )
632 func MouseClickEvent oGame
634 aBtn = Point2Button(Mouse_X,Mouse_Y)
637 if nRow != 0 and nCol != 0
638 if aGameMap[nRow][nCol] = :n
639 aGameMap[nRow][nCol] = cActivePlayer
646 Class GameLogic from GraphicsAppBase
654 aGameButtons = [ # x1,y1,x2,y2
655 [176,88,375,261], # [1,1]
656 [423,88,591,261], # [1,2]
657 [645,88,876,261], # [1,3]
658 [176,282,375,428], # [2,1]
659 [423,282,591,428], # [2,2]
660 [645,282,876,428], # [2,3]
661 [176,454,375,678], # [3,1]
662 [423,454,591,678], # [3,2]
663 [645,454,876,678] # [3,3]
668 func point2button x,y
671 for t = 1 to len(aGameButtons)
672 rect = aGameButtons[t]
673 if x >= rect[1] and x <= rect[3] and
674 y >= rect[2] and y <= rect[4]
676 on 1 nRow = 1 nCol = 1
677 on 2 nRow = 1 nCol = 2
678 on 3 nRow = 1 nCol = 3
679 on 4 nRow = 2 nCol = 1
680 on 5 nRow = 2 nCol = 2
681 on 6 nRow = 2 nCol = 3
682 on 7 nRow = 3 nCol = 1
683 on 8 nRow = 3 nCol = 2
684 on 9 nRow = 3 nCol = 3
691 func ChangeActivePlayer()
692 if cActivePlayer = :x
717 nStatus = CheckWinner(aList)
721 on 1 Player1Win(this)
722 on 2 Player2Win(this)
740 if lst[v]!=0 and lst[v+1]!=0 and lst[v+2]!=0
741 if lst[v]=lst[v+1] and lst[v+1]=lst[v+2]
748 if lst[h]!=0 and lst[h+3]!=0 and lst[h+6]!=0
749 if lst[h]=lst[h+3] and lst[h+3]=lst[h+6]
755 if lst[1]!=0 and lst[5]!=0 and lst[9]!=0
756 if lst[1]=lst[5] and lst[5]=lst[9] return lst[1] ok
758 if lst[3]!=0 and lst[5]!=0 and lst[7]!=0
759 if lst[3]=lst[5] and lst[5]=lst[7] return lst[3] ok
764 if lst[i]=0 tie=false exit ok
766 if tie=true return 3 ok return 0
775 font = al_load_ttf_font("font/pirulen.ttf",54,0 )
776 bitmap = al_load_bitmap("image/ballon.png")
778 func destroyResources
779 al_destroy_bitmap(bitmap)
780 al_destroy_font(font)
782 func Player1Win oGame
783 showMsg(oGame,80,430,"Good job X you won!")
785 func Player2Win oGame
786 showMsg(oGame,80,430,"Good job O you won!")
789 showMsg(oGame,150,430,"Oh no it's a tie!")
791 func ShowMsg oGame,x,y,cMsg
796 newdisplay = al_create_display(SCREEN_W,SCREEN_H)
797 al_set_window_title(newdisplay,TITLE)
798 al_clear_to_color(al_map_rgb(255,255,255))
799 al_draw_bitmap(this.bitmap,200,50,1)
800 al_draw_text(this.font,
801 al_map_rgb(0,0,255), x,y,
802 ALLEGRO_ALIGN_LEFT,cMsg)
805 al_destroy_display(newdisplay)
806 al_set_target_backbuffer(display)
811 bitmap bitmap2 bitmap3
812 textureX textureO textureN
819 bitmap = al_load_bitmap("image/o.png")
820 textureO = al_get_opengl_texture(bitmap)
821 bitmap2 = al_load_bitmap("image/x.png")
822 textureX = al_get_opengl_texture(bitmap2)
823 bitmap3 = al_load_bitmap("image/empty.png")
824 textureN = al_get_opengl_texture(bitmap3)
826 func destroyResources
827 al_destroy_bitmap(bitmap)
828 al_destroy_bitmap(bitmap2)
829 al_destroy_bitmap(bitmap3)
831 func cube(x,y,z,nTexture)
834 glRotatef(xrot,1.0,0.0,0.0)
835 glRotatef(yrot,0.0,1.0,0.0)
836 glRotatef(zrot,0.0,0.0,1.0)
837 setCubeTexture(nTexture)
840 func setCubeTexture cTexture
843 glBindTexture(GL_TEXTURE_2D, textureX)
845 glBindTexture(GL_TEXTURE_2D, textureO)
847 glBindTexture(GL_TEXTURE_2D, textureN)
858 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
859 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
860 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
861 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
863 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
864 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
865 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
866 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
868 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
869 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, 1.0, 1.0)
870 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, 1.0, 1.0)
871 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
873 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, -1.0, -1.0)
874 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, -1.0, -1.0)
875 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
876 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
879 glTexCoord2f(1.0, 0.0) glVertex3f( 1.0, -1.0, -1.0)
880 glTexCoord2f(1.0, 1.0) glVertex3f( 1.0, 1.0, -1.0)
881 glTexCoord2f(0.0, 1.0) glVertex3f( 1.0, 1.0, 1.0)
882 glTexCoord2f(0.0, 0.0) glVertex3f( 1.0, -1.0, 1.0)
885 glTexCoord2f(0.0, 0.0) glVertex3f(-1.0, -1.0, -1.0)
886 glTexCoord2f(1.0, 0.0) glVertex3f(-1.0, -1.0, 1.0)
887 glTexCoord2f(1.0, 1.0) glVertex3f(-1.0, 1.0, 1.0)
888 glTexCoord2f(0.0, 1.0) glVertex3f(-1.0, 1.0, -1.0)
917 al_draw_bitmap(bitmap,nBackX,nBackY,1)
922 if (nBackY = -350) or (nBackY = 0)
924 if nBackMotion > len(aBackMotionList)
927 nBackDiffx = aBackMotionList[nBackMotion][1]
928 nBackDiffy = aBackMotionList[nBackMotion][2]
932 bitmap = al_load_bitmap("image/back.jpg")
934 func destroyResources
935 al_destroy_bitmap(bitmap)
943 sample = al_load_sample( "sound/music1.wav" )
944 sampleid = al_new_allegro_sample_id()
945 al_play_sample(sample, 1.0, 0.0,1.0,ALLEGRO_PLAYMODE_LOOP,sampleid)
947 func destroyResources
948 al_destroy_allegro_sample_id(sampleid)
949 al_destroy_sample(sample)
952 class GraphicsAppBase
954 display event_queue ev timeout
964 Key = [false,false,false,false]
967 TITLE = "Graphics Application"
968 PRINT_MOUSE_XY = False
980 al_init_image_addon()
982 al_init_acodec_addon()
983 al_reserve_samples(1)
984 al_set_new_display_flags(ALLEGRO_OPENGL)
985 display = al_create_display(SCREEN_W,SCREEN_H)
986 al_set_window_title(display,TITLE)
987 al_clear_to_color(al_map_rgb(0,0,0))
988 event_queue = al_create_event_queue()
989 al_register_event_source(event_queue,
990 al_get_display_event_source(display))
991 ev = al_new_allegro_event()
992 timeout = al_new_allegro_timeout()
993 al_init_timeout(timeout, 0.06)
994 timer = al_create_timer(1.0 / FPS)
995 al_register_event_source(event_queue,
996 al_get_timer_event_source(timer))
997 al_start_timer(timer)
999 al_register_event_source(event_queue,
1000 al_get_mouse_event_source())
1001 al_install_keyboard()
1002 al_register_event_source(event_queue,
1003 al_get_keyboard_event_source())
1007 al_init_timeout(timeout, 0.06)
1008 al_wait_for_event_until(event_queue, ev, timeout)
1009 switch al_get_allegro_event_type(ev)
1010 on ALLEGRO_EVENT_DISPLAY_CLOSE
1012 on ALLEGRO_EVENT_TIMER
1014 on ALLEGRO_EVENT_MOUSE_AXES
1015 mouse_x = al_get_allegro_event_mouse_x(ev)
1016 mouse_y = al_get_allegro_event_mouse_y(ev)
1018 see "x = " + mouse_x + nl
1019 see "y = " + mouse_y + nl
1021 on ALLEGRO_EVENT_MOUSE_ENTER_DISPLAY
1022 mouse_x = al_get_allegro_event_mouse_x(ev)
1023 mouse_y = al_get_allegro_event_mouse_y(ev)
1024 on ALLEGRO_EVENT_MOUSE_BUTTON_UP
1026 on ALLEGRO_EVENT_KEY_DOWN
1027 switch al_get_allegro_event_keyboard_keycode(ev)
1031 key[KEY_DOWN] = true
1033 key[KEY_LEFT] = true
1034 on ALLEGRO_KEY_RIGHT
1035 key[KEY_RIGHT] = true
1037 on ALLEGRO_EVENT_KEY_UP
1038 switch al_get_allegro_event_keyboard_keycode(ev)
1042 key[KEY_DOWN] = false
1044 key[KEY_LEFT] = false
1045 on ALLEGRO_KEY_RIGHT
1046 key[KEY_RIGHT] = false
1047 on ALLEGRO_KEY_ESCAPE
1051 if redraw and al_is_event_queue_empty(event_queue)
1061 al_destroy_timer(timer)
1062 al_destroy_allegro_event(ev)
1063 al_destroy_allegro_timeout(timeout)
1064 al_destroy_event_queue(event_queue)
1065 al_destroy_display(display)
1072 func destroyResources
1074 func MouseClickEvent
1083 .. image:: tictactoe3d.png
1086 :alt: TicTacToe 3D ゲーム
1090 pair: RingOpenGL と RingAllegro の用法 (3D グラフィックス); その他の 3D サンプル
1093 ====================
1095 サンプルは ring/samples/3D フォルダにあります。
1097 このスクリーンショットはトップダウン - 多層立方体のサンプルです。
1099 .. image:: more3dsamples.jpg
1102 このスクリーンショットはカメラのサンプルです。
1104 .. image:: more3dsamples2.jpg
1107 このスクリーンショットはカメラと背景のサンプルです。
1111 .. image:: cameraandbackground.png