I am currently interested in using SDL with FreeBasic and wondered if there is some good tutorial material available?
What I found at,
http://forum.qbasicnews.com/index.php?topic=8254.0
is the code below but it fails to compile with error:
C:\FreeBasic\SDL_Programs\SDL_1.bas(77) error 40: Variable not declared, SDL_MOUSEDOWN in 'case SDL_MOUSEDOWN:'
Registration to the forum has been disabled.
I seem to remember you now have to email personally to register?
Code: Select all
#include "SDL\SDL.bi"
#include "SDL\SDL_image.bi"
' Surfaces are the A and O of SDL.
' You place your backgrounds, your sprites and everything else that has
' something to do with graphics inside a surface.
' This will hold the screen
dim shared video as SDL_Surface ptr
' This will hold our picture
dim shared temppic as SDL_Surface ptr
' Here goes the event holder
dim event as SDL_Event
' We initiasize SDL and we only need video. If this tells me anything but zero
' then we can not continiue
if SDL_Init(SDL_INIT_VIDEO) <> 0 then
print "FATAL: Couldnt init SDL"
end 1
end if
' We set up the display mode. We wont do fullscreen, if you like then OR the
' options with SDL_FULLSCREEN to get it.
' SDL_HWSURFACE means that this surface is hold in video ram.
' If you want it to be in system ram then exchange SDL_HWSURFACE with
' SDL_SWSURFACE
' SDL_DOUBLEBUF tells SDL to create two pages.
video = SDL_SetVideoMode (800, 600, 24, SDL_HWSURFACE OR SDL_DOUBLEBUF)
' If the surface holds nothing then the display is not created, then get out of
' here.
if video = NULL then
print "FATAL: Couldnt init SDL with vidmode 800x600x24"
end 2
end if
' Now we load the Picture to be displayed into system memory
' You can load bmp, pnm, xpm, xcf, pcx, gif, jpg, tif, png and lbm
' I stick with png because gif is patented and just 256 colors thick and the
' others are just too bloated or destroy information in the picture.
dim as string picfile
temppic = IMG_Load("testpic.png")
' If this is empty then something went wrong
if temppic = 0 then
print "Could not load file: "; picfile
end 3
end if
' We blit the image to the screen.
' SDL_BlutSurface has the parameters
' (start,startcoordinates,destination, destinationcoordinates)
' Where coordinates is a simple SDL_Rect structure.
SDL_BlitSurface(temppic,NULL,video,NULL)
' With this command we flip the video ram locations so that our painting gets
' visible.
SDL_Flip(video)
' We dont need temppic anymore so get rid of it
SDL_FreeSurface(temppic)
do
' We grab the newest event from the event stack.
' I havent tryed it, but AFAIK you can even grab Win32 events like WM_CLOSE
' this way ;)
SDL_PollEvent(@event)
' We just want the type of the event
select case event.type
' Has a key been pressed?
case SDL_KEYDOWN:
exit do
' Has a mousebutton been pressed?
case SDL_MOUSEDOWN:
exit do
' In both cases we just get out of here
end select
loop
' And as we dont asume that the compiler calls it, old C habbid ;), we assure
' that it is done and SDL gets deinitialised
SDL_Quit()