| 1 |
require "dokidoki.module" [[]] |
| 2 |
|
| 3 |
require "SDL" |
| 4 |
import(require 'gl') |
| 5 |
|
| 6 |
kernel = require "dokidoki.kernel" |
| 7 |
graphics = require "dokidoki.graphics" |
| 8 |
|
| 9 |
function make_texture_scene () |
| 10 |
local time = 0 |
| 11 |
local tex = 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 |
time = time + dt |
| 22 |
end |
| 23 |
|
| 24 |
local function init_graphics () |
| 25 |
if not tex then |
| 26 |
local image = string.char( |
| 27 |
255, 0, 0, 255, |
| 28 |
0, 255, 0, 255, |
| 29 |
255, 255, 255, 255, |
| 30 |
|
| 31 |
0, 0, 255, 255, |
| 32 |
0, 0, 0, 0, |
| 33 |
255, 255, 255, 255, |
| 34 |
|
| 35 |
0, 0, 0, 255, |
| 36 |
0, 0, 0, 255, |
| 37 |
128, 128, 128, 255) |
| 38 |
|
| 39 |
|
| 40 |
tex = graphics.texture_from_string(image, 3, 3, 4) |
| 41 |
end |
| 42 |
glClearColor(0.3 + math.cos(time/2) * 0.1, 0, 0.75, 0) |
| 43 |
glClear(GL_COLOR_BUFFER_BIT) |
| 44 |
glMatrixMode(GL_PROJECTION) |
| 45 |
glLoadIdentity() |
| 46 |
glOrtho(0, 640, 0, 480, 1, -1) |
| 47 |
glMatrixMode(GL_MODELVIEW) |
| 48 |
glLoadIdentity() |
| 49 |
|
| 50 |
glEnable(GL_BLEND) |
| 51 |
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) |
| 52 |
end |
| 53 |
|
| 54 |
local function draw () |
| 55 |
init_graphics() |
| 56 |
tex:enable() |
| 57 |
glPushMatrix() |
| 58 |
glTranslated(320, 240, 0) |
| 59 |
glColor3d(1, 1, 1) |
| 60 |
glBegin(GL_QUADS) |
| 61 |
glTexCoord2d(0, 1) glVertex2d(-200, -200) |
| 62 |
glTexCoord2d(1, 1) glVertex2d( 200, -200) |
| 63 |
glTexCoord2d(1, 0) glVertex2d( 200, 200) |
| 64 |
glTexCoord2d(0, 0) glVertex2d(-200, 200) |
| 65 |
glEnd() |
| 66 |
glPopMatrix() |
| 67 |
tex:disable() |
| 68 |
end |
| 69 |
|
| 70 |
return {handle_event = handle_event, update = update, draw = draw} |
| 71 |
end |
| 72 |
|
| 73 |
kernel.set_ratio(640/480) |
| 74 |
kernel.start_main_loop(make_texture_scene()) |
| 75 |
|