Merge pull request #242 from fowlmouth/patch-3
Update examples/sdlex.nim
This commit is contained in:
commit
9ef0c53597
1 changed files with 41 additions and 15 deletions
|
|
@ -1,26 +1,52 @@
|
||||||
# Test the SDL interface:
|
# Test the SDL interface:
|
||||||
|
|
||||||
import
|
import
|
||||||
SDL
|
sdl, sdl_image, colors
|
||||||
|
|
||||||
var
|
var
|
||||||
screen, greeting: PSurface
|
screen, greeting: PSurface
|
||||||
r: TRect
|
r: TRect
|
||||||
|
event: TEvent
|
||||||
|
bgColor = colChocolate.int32
|
||||||
|
|
||||||
if Init(INIT_VIDEO) == 0:
|
if init(INIT_VIDEO) != 0:
|
||||||
screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
quit "SDL failed to initialize!"
|
||||||
if screen == nil:
|
|
||||||
write(stdout, "screen is nil!\n")
|
screen = SetVideoMode(640, 480, 16, SWSURFACE or ANYFORMAT)
|
||||||
else:
|
if screen.isNil:
|
||||||
greeting = LoadBmp("backgrnd.bmp")
|
quit($sdl.getError())
|
||||||
if greeting == nil:
|
|
||||||
write(stdout, "greeting is nil!")
|
greeting = IMG_load("tux.png")
|
||||||
r.x = 0'i16
|
if greeting.isNil:
|
||||||
r.y = 0'i16
|
echo "Failed to load tux.png"
|
||||||
discard blitSurface(greeting, nil, screen, addr(r))
|
|
||||||
discard flip(screen)
|
|
||||||
Delay(3000)
|
|
||||||
else:
|
else:
|
||||||
write(stdout, "SDL_Init failed!\n")
|
## convert the image to alpha and free the old one
|
||||||
|
var s = greeting.displayFormatAlpha()
|
||||||
|
swap(greeting, s)
|
||||||
|
s.freeSurface()
|
||||||
|
|
||||||
|
r.x = 0
|
||||||
|
r.y = 0
|
||||||
|
|
||||||
|
block game_loop:
|
||||||
|
while true:
|
||||||
|
|
||||||
|
while pollEvent(addr event) > 0:
|
||||||
|
case event.kind
|
||||||
|
of QUITEV:
|
||||||
|
break game_loop
|
||||||
|
of KEYDOWN:
|
||||||
|
if EvKeyboard(addr event).keysym.sym == K_ESCAPE:
|
||||||
|
break game_loop
|
||||||
|
else:
|
||||||
|
discard
|
||||||
|
|
||||||
|
discard fillRect(screen, nil, bgColor)
|
||||||
|
discard blitSurface(greeting, nil, screen, addr r)
|
||||||
|
discard flip(screen)
|
||||||
|
|
||||||
|
greeting.freeSurface()
|
||||||
|
screen.freeSurface()
|
||||||
sdl.Quit()
|
sdl.Quit()
|
||||||
|
|
||||||
|
## fowl wuz here 10/2012
|
||||||
Loading…
Add table
Add a link
Reference in a new issue