| 1 | require "dokidoki.module" [[]] |
| 2 | |
| 3 | require 'glfw' |
| 4 | import(require 'gl') |
| 5 | |
| 6 | kernel = require "dokidoki.kernel" |
| 7 | graphics = require "dokidoki.graphics" |
| 8 | default_font = require "dokidoki.default_font" |
| 9 | |
| 10 | function make_sprite_scene () |
| 11 | local font_map = false |
| 12 | |
| 13 | local function handle_event (event) |
| 14 | if event.type == 'quit' or |
| 15 | event.type == 'key' and event.is_down and event.key == glfw.KEY_ESC then |
| 16 | kernel.abort_main_loop() |
| 17 | end |
| 18 | end |
| 19 | |
| 20 | local function update (dt) |
| 21 | end |
| 22 | |
| 23 | local function init_graphics () |
| 24 | if not font_map then |
| 25 | font_map = default_font.load() |
| 26 | end |
| 27 | glClearColor(0, 0, 0, 0) |
| 28 | glClear(GL_COLOR_BUFFER_BIT) |
| 29 | glMatrixMode(GL_PROJECTION) |
| 30 | glLoadIdentity() |
| 31 | glOrtho(0, 640, 0, 480, 1, -1) |
| 32 | glMatrixMode(GL_MODELVIEW) |
| 33 | glLoadIdentity() |
| 34 | |
| 35 | glEnable(GL_BLEND) |
| 36 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
| 37 | end |
| 38 | |
| 39 | local function draw () |
| 40 | init_graphics() |
| 41 | |
| 42 | glPushMatrix() |
| 43 | glTranslated(320, 240, 0) |
| 44 | glScaled(2, 2, 2) |
| 45 | glColor3d(1, 1, 1) |
| 46 | local fps = math.floor(kernel.get_framerate()+0.5) |
| 47 | graphics.draw_text(font_map, |
| 48 | "Yay it works!\n\n" .. fps .. " fps") |
| 49 | glPopMatrix() |
| 50 | end |
| 51 | |
| 52 | return {handle_event = handle_event, update = update, draw = draw} |
| 53 | end |
| 54 | |
| 55 | kernel.set_ratio(640/480) |
| 56 | kernel.set_video_mode(640, 480) |
| 57 | kernel.start_main_loop(make_sprite_scene(math.acos(-1))) |
| 58 |