Qbasicnews.com
October 15, 2019, 10:46:34 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: TUTORIAL: SDL Basics with FreeBASIC  (Read 12856 times)
BastetFurry
Forum Regular
**
Posts: 136



WWW
« on: February 09, 2005, 06:46:38 AM »

SDL Basics with FreeBASIC - Tutorial 1

In this tutorial you will learn to set up SDL and get an image on the screen,
pretty cool, uh?
Ok, it is just to teach you the basics of SDL.

So, have a look at this little piece of code:

Code:

'$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.
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()


In the next issue i will tell you how to move objects and achive transparency.

So Long, The Werelion!
Logged

color=red]Look at you, Hacker. A pathetic creature of meat and bone, panting and sweating as you run through my corridors. How can you challenge a perfect, immortal machine?" - Shodan, AI at Citadel Station orbiting Earth[/color]
aetherfox
Been there, done that
*****
Posts: 1071



WWW
« Reply #1 on: February 09, 2005, 09:32:34 AM »

Nice!

Simple, pretty clean code.
This will be good Cheesy
Can't wait for the next coming editions.
Logged

~''i|~thrFx~|i''~-  
avinash.vora - http://www.avinashv.net
na_th_an
*/-\*
*****
Posts: 8244



WWW
« Reply #2 on: February 09, 2005, 10:25:17 AM »

Pete needs articles for QB Express... Why don't you submit this or a series of these?
Logged

SCUMM (the band) on Myspace!
ComputerEmuzone Games Studio
underBASIC, homegrown musicians
[img]http://www.ojodepez-fanzine.net/almacen/yoghourtslover.png[/i
BastetFurry
Forum Regular
**
Posts: 136



WWW
« Reply #3 on: February 09, 2005, 11:59:45 AM »

Quote from: "na_th_an"
Pete needs articles for QB Express... Why don't you submit this or a series of these?


He can add it if he likes, ill do the next one this evening, i still need to fetch newspapers around. Something has to feed my needs in computers Wink
Logged

color=red]Look at you, Hacker. A pathetic creature of meat and bone, panting and sweating as you run through my corridors. How can you challenge a perfect, immortal machine?" - Shodan, AI at Citadel Station orbiting Earth[/color]
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #4 on: February 10, 2005, 03:45:56 AM »

Well, you can PM him about this and I bet he would be glad to put in in his mag. :*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
BastetFurry
Forum Regular
**
Posts: 136



WWW
« Reply #5 on: February 10, 2005, 05:09:39 AM »

Quote from: "relsoft"
Well, you can PM him about this and I bet he would be glad to put in in his mag. :*)


[X] Done!
Logged

color=red]Look at you, Hacker. A pathetic creature of meat and bone, panting and sweating as you run through my corridors. How can you challenge a perfect, immortal machine?" - Shodan, AI at Citadel Station orbiting Earth[/color]
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!