Any tutorial SDL examples

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
Post Reply
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Any tutorial SDL examples

Post by BasicCoder2 »

Hi,

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()
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Any tutorial SDL examples

Post by TJF »

Where will you get those old (2005) binaries from?

Have a look at
(Examples included.)
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Any tutorial SDL examples

Post by BasicCoder2 »

TJF wrote:Where will you get those old (2005) binaries from?
Much of the nomenclature used is unclear to me. I assume binaries means compiled exe code as opposed to source code?
Kind of a messy set of posts. I was kinda hoping for a proper tutorial designed for the absolute beginner to get up to speed using FreeBasic and SDL.

My goal is to write identical programs in FreeBasic and C++ that use the SDL as I wanted to get back into some C++ programming.
Many years ago I used DevCPP and was able to set up the SDL environment using something called a DevPac. It seems CODE::BLOCKS is the current choice and I haven't been able to set it up to run SDL programs. For some reason best known to the developers setting these things up is a nightmare for the beginner although no doubt simple if you know what is going on under the hood. It is so annoying that a beginner has to go through so many hoops just to install a development environment.
sean_vn
Posts: 283
Joined: Aug 06, 2012 8:26

Re: Any tutorial SDL examples

Post by sean_vn »

Got to agree with you about how difficult it is to get started with any programming language these days. It used to be that you clicked on the IDE icon and stated typing, pressed compile and finish.
TJF
Posts: 3809
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: Any tutorial SDL examples

Post by TJF »

BasicCoder2 wrote:I assume binaries means compiled exe code as opposed to source code?
That's the terminology I use. Some code gets compiled and linked to be startet as an executable. Other code gets compiled and linked to be loaded as a run-time library (.dll). But I may be wrong, I'm not a native speaker.
sean_vn wrote:It used to be that you clicked on the IDE icon and stated typing, pressed compile and finish.
That's still how it is today, when you're talking about coding for one system on that system.

We're talking about SDL here, which is cross-platform and multi target development.
Coolman
Posts: 294
Joined: Nov 05, 2010 15:09

Re: Any tutorial SDL examples

Post by Coolman »

I agree that it should work immediately. time is precious and should be used to code ... if you do not want to take your head, here is a package that allows you to compile examples of static and do nothing more. the necessary libraries are available in the directory ...

static libraries, have been totally downloaded here : https://www.libsdl.org/projects/

I modified some files ... exe files generated are totally independent. Example renderer continues to crash. for compilation. using the console mode. I used FreeBasic Version 1.01.0 win32 ...

SDL2.zip : http://dl.free.fr/brm3SyHF6

MD5:2AD18CCCE462F513FBD0A2C9B4A12DE3
justfree
Posts: 18
Joined: May 12, 2014 2:42

Re: Any tutorial SDL examples

Post by justfree »

Got to agree with you about how difficult it is to get started with any programming language these days. It used to be that you clicked on the IDE icon and stated typing, pressed compile and finish.
Same feeling here, greed has pushed IT into quagmire of languages, classes, frameworks without any way out. I think it all began With OOP. It opened up freedom for social irresponsibility. Now every castle has its own king of object framework all doing the same "hello world" in different ways. And, all say buy ours! Ours is better!
Post Reply