main.lua
local function main()
-- Initialize SDL video
if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) then
print( "Couldn't initialize SDL: " .. SDL_GetError() )
return 1
end
-- Set the window caption
SDL_WM_SetCaption( "SDLFW - Hello World", nil )
-- Create a new window
local screen = SDL_SetVideoMode( 512, 384, 16, SDL_SWSURFACE )
if ( screen == nil ) then
print( "Unable to set the video mode: " .. SDL_GetError() )
SDL_Quit()
return 1
end
-- Get the global event
local event = SDLFW_GetGlobalEvent()
-- While the user hasn't quit
local done = false
while ( done == false ) do
-- While there's an event to handle
if ( SDL_PollEvent(event) ) then
-- If the user has X out the window
if ( event.type == SDL_QUIT ) then done = true end
end
-- Swaps screen buffers
SDL_Flip( screen )
-- Wait a specified number of milliseconds before returning
SDL_Delay( 1 )
end
-- Make sure SDL cleans up before exit
SDL_Quit()
return 0
end
main()
|