I'm transliterating the SDL code from this page into a NewLisp program:
http://lazyfoo.net/SDL_tutorials/lesson02/index.php
I'm using NewLisp 9.1.1, SDL 1.2.8 and the SDL.lsp import file from http://www.turtle.dds.nl/newlisp/SDL.lsp
However, for whatever reason, I can't get the bitmaps to load. Before, when I had a "home-grown" SDL/gl mix (ripped from the teapot example), I could see the top half of the "hello_world.bmp", but no background image.
Note that I supplied two functions which are defined with C macros in the SDL include files -- SDL_LoadBMP and SDL_BlitSurface.
Any thoughts?
Thanks!
Here's the code:
Code: Select all
; l002.lsp
; jrlf 2007-08-10
; Surface loading and blitting.
; http://lazyfoo.net/SDL_tutorials/lesson02/index.php
; Load SDL library.
(load "SDL.lsp")
(context 'SDL)
(define (SDL_LoadBMP filename)
(SDL:SDL_LoadBMP_RW (SDL:SDL_RWFromFile filename "rb") 1))
(define (SDL_BlitSurface src srcrect dst dstrect)
(SDL_UpperBlit src srcrect dst dstrect))
(context 'MAIN)
; Screen attributes.
(constant 'screen_width 640)
(constant 'screen_height 480)
(constant 'screen_bpp 32)
(define (load_image filename)
(let ((loaded (SDL:SDL_LoadBMP filename))
(optimized nil))
(if loaded (begin
(setq optimized (SDL:SDL_DisplayFormat loaded))
(SDL:SDL_FreeSurface loaded)
))
optimized))
(define (apply_surface x y from to)
(SDL:SDL_BlitSurface from "" to (pack "u u lu lu" x y 0 0))
)
(if (< (SDL:SDL_Init SDL:SDL_INIT_EVERYTHING) 0)
(begin (println "Could not initialize SDL!") (exit)))
(if (< (setq screen (SDL:SDL_SetVideoMode screen_width screen_height
screen_bpp SDL:SDL_SWSURFACE)) 0)
(begin (println "Couldn't initialize the screen!") (exit)))
(SDL:SDL_WM_SetCaption "Hello World" "")
(setq message (load_image "hello_world.bmp")
background (load_image "background.bmp")
)
(apply_surface 0 0 background screen)
(apply_surface 180 140 message screen)
(if (< (SDL:SDL_Flip screen) 0)
(begin
(println "Couldn't flip screen!") (exit)))
(SDL:SDL_Delay 2000)
(SDL:SDL_FreeSurface message)
(SDL:SDL_FreeSurface background)
(SDL:SDL_Quit)
(exit)