| 1 | require "dokidoki.module" [[]] |
| 2 | |
| 3 | require "glfw" |
| 4 | import(require 'gl') |
| 5 | |
| 6 | kernel = require "dokidoki.kernel" |
| 7 | graphics = require "dokidoki.graphics" |
| 8 | sound = require "dokidoki.sound" |
| 9 | |
| 10 | function make_sprite_scene () |
| 11 | local time = 0 |
| 12 | local sprite = false |
| 13 | |
| 14 | local function handle_event (event) |
| 15 | if event.type == 'quit' or |
| 16 | event.type == 'key' and event.is_down and event.key == glfw.KEY_ESC then |
| 17 | kernel.abort_main_loop() |
| 18 | end |
| 19 | end |
| 20 | |
| 21 | local function update (dt) |
| 22 | time = time + dt |
| 23 | end |
| 24 | |
| 25 | local function init_graphics () |
| 26 | if not sprite then |
| 27 | sprite = graphics.sprite_from_image("rgba.png", nil, "center") |
| 28 | end |
| 29 | glClearColor(0.3 + math.cos(time/2) * 0.1, 0, 0.75, 0) |
| 30 | glClear(GL_COLOR_BUFFER_BIT) |
| 31 | glMatrixMode(GL_PROJECTION) |
| 32 | glLoadIdentity() |
| 33 | glOrtho(0, 640, 0, 480, 1, -1) |
| 34 | glMatrixMode(GL_MODELVIEW) |
| 35 | glLoadIdentity() |
| 36 | |
| 37 | glEnable(GL_BLEND) |
| 38 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
| 39 | end |
| 40 | |
| 41 | local function draw () |
| 42 | init_graphics() |
| 43 | glPushMatrix() |
| 44 | glTranslated(320, 240, 0) |
| 45 | glRotated(math.sin(time * math.pi) * 50, 0, 0, 1) |
| 46 | glColor3d(1, 1, 1) |
| 47 | sprite:draw() |
| 48 | glPopMatrix() |
| 49 | end |
| 50 | |
| 51 | return {handle_event = handle_event, update = update, draw = draw} |
| 52 | end |
| 53 | |
| 54 | kernel.set_ratio(640/480) |
| 55 | kernel.start_main_loop(make_sprite_scene()) |
| 56 |