SDL2 package (version 2.0.1)

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

SDL2 package (version 2.0.1)

Postby TJF » Nov 05, 2013 7:20

The library SDL (Simple DirectMedia Layer) is a cross-platform development library designed to provide low level access to audio, keyboard, mouse, joystick, and graphics hardware via OpenGL and Direct3D. It is used by video playback software, emulators, and popular games including Valve's award winning catalog and many Humble Bundle games. SDL officially supports Windows and Linux (and others).

Here's an FreeBasic up-date for the current version 2.0.1, including some examples and headers for SDL2-2.0.1, SDL2_mixer-2.0.0 and SDL2_image-2.0.0.

Overview of new features in SDL 2.0:
  • Full 3D hardware acceleration
  • Support for OpenGL 3.0+ in various profiles (core, compatibility, debug, robust, etc)
  • Support for OpenGL ES
  • Support for multiple windows
  • Support for multiple displays
  • Support for multiple audio devices
  • Android and iOS support
  • Simple 2D rendering API that can use Direct3D, OpenGL, OpenGL ES, or software rendering behind the scenes
  • Force Feedback available on Windows, Mac OS X and Linux
  • XInput and XAudio2 support for Windows
  • Atomic operations (not supported for FB yet)
  • Power management (exposes battery life remaining, etc)
  • Shaped windows
  • 32-bit audio (int and float)
  • Simplified Game Controller API (the Joystick API is still here, too!)
  • Touch support (multitouch, gestures, etc)
  • Better fullscreen support
  • Better keyboard support (scancodes vs keycodes, etc).
  • Message boxes
  • Clipboard support
  • Basic Drag'n'Drop support
  • Proper unicode input and IME support
  • A really powerful assert macro (not supported for FB yet)
  • zlib license instead of LGPL.
  • Lots of old annoyances from 1.2 are gone
  • Many other things!

Download

[Edit]
Added-a: SDL2_mixer-2.0.0 and SDL2_image-2.0.0
Added-b: SDL2_win32_statick_linking.bi, bugfixes (macros)
[/Edit]
Last edited by TJF on Nov 22, 2013 11:30, edited 3 times in total.
Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 05, 2013 8:35

Hello TJF !

It sounds very interesting, but I couldn't manage to compile examples.

Command executed:
"P:\FreeBASIC\fbc.exe" "P:\FreeBASIC\examples\graphics\SDL2\GLContext.bas"

Compiler output:
P:\FreeBASIC\inc\SDL2\SDL2.bi(459) error 23: File not found, "iconv.bi" in '#INCLUDE ONCE "iconv.bi" '__HEADERS__: iconv.h'

Results:
Compilation failed

System:
FBIde: 0.4.6
fbc: FreeBASIC Compiler - Version 0.90.1 (07-17-2013) for win32
OS: Windows XP (build 2600, Service Pack 3)
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 05, 2013 9:31

Sorry, I thought the file is already in the FB distribution.

Save this code as
    .../FreeBasic/inc/iconv.bi

Code: Select all

#IFNDEF _ICONV_H
#DEFINE _ICONV_H 1

' file not found: features.h

#DEFINE __need_size_t
#INCLUDE ONCE "crt/stddef.bi"

TYPE AS ANY PTR iconv_t

EXTERN iconv_open AS FUNCTION CDECL(BYVAL AS CONST ZSTRING PTR, BYVAL AS CONST ZSTRING PTR) AS iconv_t
EXTERN iconv AS FUNCTION CDECL(BYVAL AS iconv_t, BYVAL AS ZSTRING PTR PTR, BYVAL AS size_t PTR, BYVAL AS ZSTRING PTR PTR, BYVAL AS size_t PTR) AS size_t
EXTERN iconv_close AS FUNCTION CDECL(BYVAL AS iconv_t) AS INTEGER

#ENDIF

and try again.
Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 05, 2013 9:43

Thank you for iconv.bi.

Now I get another error.

Compiler output:
P:\FreeBASIC\bin\win32\ld.exe: cannot find -lSDL2
Last edited by Roland Chastain on Nov 05, 2013 11:01, edited 1 time in total.
Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 05, 2013 11:00

I downloaded SDL2 runtime binaries (from here), pasted SDL2.dll into examples folder and now it runs.
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 05, 2013 11:54

Did you compile and run Renderer.bas? Does it 'segfault' when executing on your box?
Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 05, 2013 13:59

TJF wrote:Did you compile and run Renderer.bas? Does it 'segfault' when executing on your box?


When I run Renderer.exe, I get a Windows error message (under Windows XP 32 and also under Windows 8 64).
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 05, 2013 14:04

Thanks for testing and reporting! I guess it's line 29?

    SDL_RenderCopy(renderer, bitmapTex, NULL, NULL)

Maybe somebody is keen on using a debugger and can check what's wrong.

It may be related to SDL_RENDER_DISABLED (must not be define when compiling SDL2, otherwise no renderer support). Example from source code:

Code: Select all

SDL_Renderer *
SDL_CreateSoftwareRenderer(SDL_Surface * surface)
{
#if !SDL_RENDER_DISABLED
    SDL_Renderer *renderer;

    renderer = SW_CreateRendererForSurface(surface);

    if (renderer) {
        renderer->magic = &renderer_magic;
        renderer->scale.x = 1.0f;
        renderer->scale.y = 1.0f;

        SDL_RenderSetViewport(renderer, NULL);
    }
    return renderer;
#else
    SDL_SetError("SDL not built with rendering support");
    return NULL;
#endif /* !SDL_RENDER_DISABLED */
}

But SDL_CreateSoftwareRenderer() doesn't return NULL ?!
much love
Posts: 6
Joined: Nov 06, 2013 21:40

Re: SDL2 package (version 2.0.1)

Postby much love » Nov 06, 2013 21:47

I just signed up to thank you for the updated headers! I've been looking for them for a few weeks now. I even tried to do it myself, but I was completely lost haha. :)
The renderer example works fine for me, by the way.
Also, would it be too bold to ask if there is any chance to get the updated versions of SDL_image and SDL_mixer too?
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 08, 2013 6:52

Hello much love, welcome to the forum!

much love wrote:The renderer example works fine for me, by the way.

Thanks for feedback! Would you mind to give some information about your system (OS, graphics card, OpenGL version)?

much love wrote:Also, would it be too bold to ask if there is any chance to get the updated versions of SDL_image and SDL_mixer too?

I'll see what I can do, but it may take some time.
much love
Posts: 6
Joined: Nov 06, 2013 21:40

Re: SDL2 package (version 2.0.1)

Postby much love » Nov 08, 2013 9:13

Yeah, sure:

Windows 7 SP1 32-bit
AMD Radeon HD 7640G
OpenGL 4.2
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 10, 2013 12:46

I added headers and examples for

  • SDL2_mixer-2.0.0
  • SDL2_image-2.0.0

Also, I added the missing iconv.bi header.

Download:

Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 10, 2013 17:25

Hello TJF !

The image example is easy to run.

Code: Select all

@echo off
showimage sdl.bmp
pause


But I was less lucky with music. With a .wma file I get strange result, and with an .mp3 file I don't get anything.

Code: Select all

@echo off
playmus farandole.wma
pause


Code: Select all

@echo off
playmus marche.mp3
pause


I know I should read documentation about SDL, but would you mind giving us quick indications about command parameters and supported formats ?
TJF
Posts: 3503
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: SDL2 package (version 2.0.1)

Postby TJF » Nov 11, 2013 6:37

Hello Roland,

playmus runs fine here (Ubuntu-12.04, fbc-0.24). I guess you're facing an installation issue.

Sorry, I don't understand what this code means (stuff for your IDE)?
Roland Chastain wrote:

Code: Select all

@echo off
playmus farandole.wma
pause


When you start the program from the command line you'll get an error message if anything fails. Just execute

    playmus farandole.wma
to play the music file. Or execute

    playmus
to get a hint on how to use it (or see line 146).

Additionally, I included the code line 171 to 178 (to the original code)

Code: Select all

' By uncommenting check for several decoders support
'var flags = MIX_INIT_OGG OR MIX_INIT_MP3 OR MIX_INIT_MOD OR MIX_INIT_FLAC
'var initted = Mix_Init(flags)
'if (initted and flags) <> flags then
  'printf(!"Mix_Init: Failed to init required decoder support!\n")
  'printf(!"Mix_Init: %s\n", Mix_GetError())
  'CleanUp(3)
'end if

to test which audio decoders are supported on the system. You can uncomment these lines and test each of the ORed flags separately to check for certain decoders.
Roland Chastain
Posts: 858
Joined: Nov 24, 2011 19:49
Location: France
Contact:

Re: SDL2 package (version 2.0.1)

Postby Roland Chastain » Nov 11, 2013 17:27

Thank you for your answer, TJF.

TJF wrote:Sorry, I don't understand what this code means (stuff for your IDE)?

Code: Select all

@echo off
playmus farandole.wma
pause


It's simply a .bat file to run playmus.exe.

TJF wrote:When you start the program from the command line you'll get an error message if anything fails.


I don't get an error message. I get the message "Playing farandole.wma". But instead of music I hear a noise. (When I play the same file with Windows Media Player, I hear the music.)

TJF wrote:You can uncomment these lines and test each of the ORed flags separately to check for certain decoders.


Ok, I will do that. Thank you again.

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 2 guests