-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
82 lines (72 loc) · 1.36 KB
/
main.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
local sdl = require 'sdl2'
local ffi = require 'ffi'
local SCREEN_WIDTH = 640
local SCREEN_HEIGHT = 480
local gWindow = nil
local gScreenSurface = nil
local gHelloWorld = nil
function initSDLWindow()
gWindow = sdl.createWindow(
"SDL Tutorial",
sdl.WINDOWPOS_CENTERED,
sdl.WINDOWPOS_CENTERED,
SCREEN_WIDTH,
SCREEN_HEIGHT,
sdl.WINDOW_SHOWN
)
if gWindow then
return true
else
print('teste')
return false
end
end
function init()
if sdl.init(sdl.INIT_VIDEO) < 0 then
print 'SDL_INIT mau sucedido'
return false
end
if not initSDLWindow() then
return false
end
gScreenSurface = sdl.getWindowSurface( gWindow )
return true
end
function loadMedia()
gHelloWorld = sdl.loadBMP('example_merged.bmp')
if not gHelloWorld then
print('Unable to load File')
return false
end
return true
end
function close()
sdl.freeSurface( gHelloWorld )
gHelloWorld = nil
sdl.destroyWindow(gWindow)
gWindow = nil
sdl.quit()
end
function main()
if not init() then
print 'failed to initialize'
return
end
if not loadMedia() then
print 'failed to load media'
return
end
local quit = false
local e = ffi.new('SDL_Event')
sdl.blitSurface(gHelloWorld, nil, gScreenSurface, nil)
sdl.updateWindowSurface(gWindow)
while not quit do
while sdl.pollEvent(e) ~= 0 do
if e.type == sdl.QUIT then
quit = true
end
end
end
close()
end
main()