| 1 | require "dokidoki.module" [[]] |
| 2 | |
| 3 | require "glfw" |
| 4 | import(require "gl") |
| 5 | |
| 6 | kernel = require "dokidoki.kernel" |
| 7 | graphics = require "dokidoki.graphics" |
| 8 | |
| 9 | function make_spinner_scene () |
| 10 | local rotation = 0 |
| 11 | |
| 12 | local function handle_event (event) |
| 13 | if event.type == 'quit' or |
| 14 | event.type == 'key' and event.is_down and event.key == glfw.KEY_ESC then |
| 15 | kernel.abort_main_loop() |
| 16 | end |
| 17 | end |
| 18 | |
| 19 | local function update (dt) |
| 20 | rotation = rotation + dt * 45 |
| 21 | end |
| 22 | |
| 23 | local function init_graphics () |
| 24 | glClearColor(0, 0, 0.25, 0) |
| 25 | glClear(GL_COLOR_BUFFER_BIT) |
| 26 | glMatrixMode(GL_PROJECTION) |
| 27 | glLoadIdentity() |
| 28 | glOrtho(0, 300, 0, 300, 1, -1) |
| 29 | glMatrixMode(GL_MODELVIEW) |
| 30 | glLoadIdentity() |
| 31 | end |
| 32 | |
| 33 | local function draw () |
| 34 | init_graphics() |
| 35 | glPushMatrix() |
| 36 | glTranslated(150, 150, 0) |
| 37 | glRotated(rotation, 0, 0, 1) |
| 38 | glScaled(100, 100, 100) |
| 39 | glColor3d(0.5, 0.25, 1) |
| 40 | glBegin(GL_QUADS) |
| 41 | glVertex2d(-1, -1) |
| 42 | glVertex2d( 1, -1) |
| 43 | glVertex2d( 1, 1) |
| 44 | glVertex2d(-1, 1) |
| 45 | glEnd() |
| 46 | glPopMatrix() |
| 47 | end |
| 48 | |
| 49 | return {handle_event = handle_event, update = update, draw = draw} |
| 50 | end |
| 51 | |
| 52 | kernel.set_video_mode(300, 300) |
| 53 | kernel.set_ratio(1) |
| 54 | kernel.start_main_loop(make_spinner_scene()) |
| 55 |