Jump to content

SDL UDF


Recommended Posts

great job with this, its coming along greatly! i really consider using this from now on as a replacement of gdi+.

tho running your png in gui example, ive come to an issue. where would i be able to specify were on the gui to draw the image

Please see the example called: "SDL Example Video Bitmaps Pixels.au3" and/or check SDL_BlitSurface in your favourite helpfile for details on the second and forth parameters.
Link to comment
Share on other sites

  • 2 months later...

Great news everybody, I just uploaded SDL UDF v14½.

So what's new?

Well there's 2 new libraries:

SDL_mixer for audio (music, sound effects) and SDL_ttf for drawing truetype fonts. Neither of them are 100% complete (see the table in post1) but the basics work, and the rest should just be a question of time.

SDL_mixer is BTW totally AWESOME for sound effects, it completely owns everything else in AutoIt.

So what's more?

_SDL_SetTimer() has finally been "fixed". Also events have been implemented. Again not 100% complete, but basics work.

I also "fixed" a common memory-error-crash-thingy that's been around forever, but apparantly no one else noticed.

There are also two new examples:

SDL Example get image w,h.au3 (get width and height of an image)

SDL Example image viewer.au3 (shows an image with basic auto-zoom)

I haven't created any examples for events, mixer or ttf, but I am hoping to amend that with one or two games I will release soon.

Download is as usual in the first second post.

Link to comment
Share on other sites

  • 4 weeks later...

It seems the whole webpage is down. I have no idea why.

As a temporary solution, I uploaded the zip to my webpage. http://hem.passagen.se/amax/autoit/SDL v14½.zip

I will try to find a more permanent solution later, it's like 4 AM here and i am really sleepy :)

Link to comment
Share on other sites

  • 2 weeks later...

Any way to set a transparent color, like pink?

I am not very good at transparency stuff, but maybe like this?

#Include "SDL.au3"
#include "SDL_gfx.au3"
#include "SDL_sge.au3"
#include "SDL_sprig.au3"

_SDL_Init($_SDL_INIT_VIDEO)

$Surface = _SDL_SetVideoMode(640, 480, 24, $_SDL_SWSURFACE)     ;Software surfaces doesn't need to be locked ;)

$Bitmap = _SDL_LoadBMP("image.bmp")

_SDL_BlitSurface($Bitmap, 0, $Surface, 0)

Switch InputBox("title", "Please write 1 for SDL, 2 for gfx, 3 for sge or 4 for sprig")
    Case 1
        $Surface2 = _SDL_CreateRGBSurface($_SDL_SWSURFACE, 320, 240, 24, 0, 0, 0, 0)
        _SDL_SetAlpha($Surface2, $_SDL_SRCALPHA, 128)
        _SDL_FillRect($Surface2, _SDL_Rect_Create(0, 0, 320, 240), _SDL_MapRGB($Surface2, 0xff, 0xc0, 0xcb))
        _SDL_BlitSurface($Surface2, 0, $Surface, 0)
        _SDL_FreeSurface($Surface2)
    Case 2
        _SDL_Startup_gfx()
        _SDL_boxRGBA($Surface, 0, 0, 320, 240, 0xff, 0xc0, 0xcb, 128)
        _SDL_Shutdown_gfx()
    Case 3
        _SDL_Startup_sge()
        _sge_FilledRectAlpha($Surface, 0, 0, 320, 240, _SDL_MapRGB($Surface, 0xff, 0xc0, 0xcb), 128)
        _SDL_Shutdown_sge()
    Case 4
        _SDL_Startup_sprig()
        _SPG_RectFilledBlend($Surface, 0, 0, 320, 240, _SDL_MapRGB($Surface, 0xff, 0xc0, 0xcb), 128)
        _SDL_Shutdown_sprig()
EndSwitch

_SDL_FreeSurface($Bitmap)

_SDL_Flip($Surface)

Sleep(10000)

_SDL_Quit()

Or did you mean something else? :)

Link to comment
Share on other sites

While I am at it, here's an example for handling events, in the easy way. It listens to all joystick events, uses 0% cpu and doesn't miss anything (as long as you don't fill the event queue)

#Include "SDL.au3"

_SDL_Init(BitOR($_SDL_INIT_JOYSTICK, $_SDL_INIT_VIDEO))     ;Remember that events ate initialized by SDL_INIT_VIDEO

$Joystick = _SDL_JoystickOpen(0)
_CW($Joystick)

ConsoleWrite(_SDL_JoystickEventState($_SDL_QUERY) & @CRLF)      ;Are joystick event polling enabled?

For $X = $_SDL_NOEVENT To $_SDL_NUMEVENTS -1        ;Listening to events we are not interested in seems lika a waste to me
    _SDL_EventState($X, $_SDL_IGNORE)
Next
_SDL_EventState($_SDL_JOYAXISMOTION, $_SDL_ENABLE)
_SDL_EventState($_SDL_JOYBALLMOTION, $_SDL_ENABLE)
_SDL_EventState($_SDL_JOYHATMOTION, $_SDL_ENABLE)
_SDL_EventState($_SDL_JOYBUTTONDOWN, $_SDL_ENABLE)
_SDL_EventState($_SDL_JOYBUTTONUP, $_SDL_ENABLE)
_SDL_EventState($_SDL_QUIT, $_SDL_ENABLE)

ConsoleWrite(_SDL_JoystickEventState($_SDL_QUERY) & @CRLF)      ;Are joystick event polling enabled?

While 1
    $tRet = _SDL_PollEventEasy()
    Select
        Case $tRet = 0          ;If no event then Sleep (like GUIGetMsg works!)
            Sleep(10)
        Case $tRet[0] = $_SDL_JOYAXISMOTION
            _BumpDump($tRet)        ;Dump array contents to console (see helpfile or source-code to see what is what)
        Case $tRet[0] = $_SDL_JOYBALLMOTION
            _BumpDump($tRet)
        Case $tRet[0] = $_SDL_JOYHATMOTION
            _BumpDump($tRet)
        Case $tRet[0] = $_SDL_JOYBUTTONDOWN
            _BumpDump($tRet)
        Case $tRet[0] = $_SDL_JOYBUTTONUP
            _BumpDump($tRet)
        Case $tRet[0] = $_SDL_QUIT
            MsgBox(0, "Exiting now", "But you will not see this message ;) (most of the time anyway)")      ;Don't ask me about this, I'm just as confused as you :S
            ExitLoop
        Case Else           ;Never happens (we put ignore on everything "else" a few lines up)
            ConsoleWrite($tRet[0] & @CRLF)
    EndSelect
WEnd

;This like never happens
ConsoleWrite("I am exiting now, bye!" & @CRLF)

_SDL_JoystickClose($Joystick)
_SDL_Quit()
Link to comment
Share on other sites

I am not very good at transparency stuff, but maybe like this?

#Include "SDL.au3"
#include "SDL_gfx.au3"
#include "SDL_sge.au3"
#include "SDL_sprig.au3"

_SDL_Init($_SDL_INIT_VIDEO)

$Surface = _SDL_SetVideoMode(640, 480, 24, $_SDL_SWSURFACE)     ;Software surfaces doesn't need to be locked ;)

$Bitmap = _SDL_LoadBMP("image.bmp")

_SDL_BlitSurface($Bitmap, 0, $Surface, 0)

Switch InputBox("title", "Please write 1 for SDL, 2 for gfx, 3 for sge or 4 for sprig")
    Case 1
        $Surface2 = _SDL_CreateRGBSurface($_SDL_SWSURFACE, 320, 240, 24, 0, 0, 0, 0)
        _SDL_SetAlpha($Surface2, $_SDL_SRCALPHA, 128)
        _SDL_FillRect($Surface2, _SDL_Rect_Create(0, 0, 320, 240), _SDL_MapRGB($Surface2, 0xff, 0xc0, 0xcb))
        _SDL_BlitSurface($Surface2, 0, $Surface, 0)
        _SDL_FreeSurface($Surface2)
    Case 2
        _SDL_Startup_gfx()
        _SDL_boxRGBA($Surface, 0, 0, 320, 240, 0xff, 0xc0, 0xcb, 128)
        _SDL_Shutdown_gfx()
    Case 3
        _SDL_Startup_sge()
        _sge_FilledRectAlpha($Surface, 0, 0, 320, 240, _SDL_MapRGB($Surface, 0xff, 0xc0, 0xcb), 128)
        _SDL_Shutdown_sge()
    Case 4
        _SDL_Startup_sprig()
        _SPG_RectFilledBlend($Surface, 0, 0, 320, 240, _SDL_MapRGB($Surface, 0xff, 0xc0, 0xcb), 128)
        _SDL_Shutdown_sprig()
EndSwitch

_SDL_FreeSurface($Bitmap)

_SDL_Flip($Surface)

Sleep(10000)

_SDL_Quit()

Or did you mean something else? :)

Nope, didn't mean that, sorry for explaining badly.

What I want is, to make it make the pink color transparent

Ex; Posted Image

Link to comment
Share on other sites

Nope, didn't mean that, sorry for explaining badly.

What I want is, to make it make the pink color transparent

Ex; Posted Image

Do you think of something like step 3) here?

3) How to tell SDL which color to make transparent

So how can we specify what color SDL can treat as transparent? Well, when we load an image we can add a little code to take care of this:

if( compatible_image != NULL ) {

// specify a colour that will be used to signify 'transparent' pixels

Uint32 colorkey = SDL_MapRGB( compatible_image->format, 0, 0, 0); // choose black

// now tell SDL to remeber our choice

SDL_SetColorKey( compatible_image, SDL_RLEACCEL | SDL_SRCCOLORKEY, colorkey);

// SDL_RLEACCEL is run lenght encoded acceleration to speed up the colorkeying

// SDL_SRCCOLORKEY tells SDL that this color key applies to the source image

}

In the SDL_MapRGB function we can tell SDL three numbers that form a color with Red, Green and Blue parts. Hence black, which is no color at all really, is red=0,green=0 and blue=0.

The other two SDL_RLEACCEL and SDL_SRCCOLORKEY specify how the images will be drawn. Its a bit outside the scope of this HOWTO to go into details of RLE but a good five minutes on Google typing in run length encoding will get you a good explanation if you really want one. Its basically that the image surface gets optimized so that the whole color keying process gets done faster.

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

I've been using SDL pretty much the last couple of weeks (altough in C++). And transparency is a bitch before you understand how SDL handles it.

There are 3 types of transparency in SDL, color keys (like in the above pink example), per-surface alpha, and per pixel alpha.

The annoying thing is that you cannot mix these (well you can if you use a custom blitter like in sdl_gfx), this usually is the problem people have when it comes to transparency troubles.

At the moment I'm doing manual blitting and alpha settings, it's slower but I like the control.

Googling for specific problem usually turns up good stuff.

Broken link? PM me and I'll send you the file!

Link to comment
Share on other sites

Oh, you need to set the colorkey with:

_SDL_SetColorKey($hSurface, $_SDL_SRCCOLORKEY, _SDL_MapRGB($hSurface, 0xFF, 0x00, 0xFF))

If you have 24/32 bit colors you can remove the MapRGB and input the color directly.

Here's a good tutorial you may want to read: The Ins and Outs (and Overlays) of Alpha-blending

Link to comment
Share on other sites

I went with simply making the png pics transparent with photophiltre ;)

That work good too although it should blit a little slower than the colorkeying :)
Link to comment
Share on other sites

That work good too although it should blit a little slower than the colorkeying :)

How much slower? ;)

Well I might check it out again tomorrow or something, I'm so tired today that I simply gave up trying to make it work with colokeying, most of the time nothing happened and sometimes I managed to crash the program B)

If you could make a working example (nothing complex, just something that works) I would be very grateful

Edited by Zisly
Link to comment
Share on other sites

How much slower? :)

No idea (I read about in on the internetz), haven't really tested that myself, but you do know how to use TimerInit/TimerDiff, right? B)

Well I might check it out again tomorrow or something, I'm so tired today that I simply gave up trying to make it work with colokeying, most of the time nothing happened and sometimes I managed to crash the program ;)

If you could make a working example (nothing complex, just something that works) I would be very grateful

Try adding this after $Loaded1 is declared in "SDL Example SDL_image.au3", all the white in the excel table will be black! B)

_SDL_SetColorKey($Loaded1, $_SDL_SRCCOLORKEY, 0xFFFFFF)
Edited by AdmiralAlkex
Link to comment
Share on other sites

The site you have the download at seems to be down or something, do you want me to host it on my website?

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

The site you have the download at seems to be down or something, do you want me to host it on my website?

The link at post #44 works for me, try that. As for a permanent solution, can you provide download statistics and FTP login? I can't take the risk that you are abducted by aliens and I can't get a new version online :)
Link to comment
Share on other sites

The link at post #44 works for me, try that. As for a permanent solution, can you provide download statistics and FTP login? I can't take the risk that you are abducted by aliens and I can't get a new version online :)

No, I can just upload it and people can use a straight link to it, no stats or login. But it's meant to temporary.

I'll try that link you mentioned now.

For those who are asking questions, look in the help file first. I'm tired of people asking stupid questions about how to do things when 10 seconds in the help file could solve their problem.[quote name='JRowe' date='24 January 2010 - 05:58 PM' timestamp='1264381100' post='766337'][quote name='beerman' date='24 January 2010 - 03:28 PM' timestamp='1264372082' post='766300']They already have a punishment system for abuse.[/quote]... and his his name is Valik.[/quote]www.minikori.com

Link to comment
Share on other sites

No idea (I read about in on the internetz), haven't really tested that myself, but you do know how to use TimerInit/TimerDiff, right? B)

Try adding this after $Loaded1 is declared in "SDL Example SDL_image.au3", all the white in the excel table will be black! B)

_SDL_SetColorKey($Loaded1, $_SDL_SRCCOLORKEY, 0xFFFFFF)

Ok, now I feel stupid ;), anyway it works, thanks! :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...