Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

SDL UDF


  • Please log in to reply
89 replies to this topic

#41 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 10 August 2009 - 06:38 PM

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.







#42 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 24 October 2009 - 05:06 PM

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.

#43 destroyhim

destroyhim

    Seeker

  • Active Members
  • 11 posts

Posted 17 November 2009 - 12:50 AM

The download link is broke! Please fix it, this looks awesome!

#44 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 17 November 2009 - 02:42 AM

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 :)

#45 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 01 December 2009 - 02:22 PM

Any way to set a transparent color, like pink?

#46 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 01 December 2009 - 04:30 PM

Any way to set a transparent color, like pink?

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

AutoIt         
#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? :)

#47 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 01 December 2009 - 05:18 PM

Oh, you got a new version I see.
I'll check the example when I get home, thanks for your time :)

#48 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 01 December 2009 - 05:59 PM

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)

AutoIt         
#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()


#49 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 01 December 2009 - 06:38 PM

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

AutoIt         
#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

#50 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 01 December 2009 - 06:54 PM

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, 01 December 2009 - 06:57 PM.

*GERMAN* Posted Image [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

#51 monoceres

monoceres

    idiot, slow down

  • MVPs
  • 4,047 posts

Posted 01 December 2009 - 06:59 PM

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!


#52 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 01 December 2009 - 07:03 PM

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

#53 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 01 December 2009 - 09:55 PM

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

Edited by Zisly, 01 December 2009 - 09:55 PM.


#54 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 01 December 2009 - 10:42 PM

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 :)

#55 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 01 December 2009 - 11:32 PM

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, 01 December 2009 - 11:32 PM.


#56 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 02 December 2009 - 09:51 PM

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, 02 December 2009 - 09:51 PM.


#57 Minikori

Minikori

    I like to cut people in my freetime

  • Active Members
  • PipPipPipPipPipPip
  • 527 posts

Posted 02 December 2009 - 10:10 PM

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.

They already have a punishment system for abuse.

... and his his name is Valik.

www.minikori.com

#58 AdmiralClaws

AdmiralClaws

    Where is the fish?

  • Active Members
  • PipPipPipPipPipPip
  • 4,697 posts

Posted 02 December 2009 - 11:02 PM

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 :)

#59 Minikori

Minikori

    I like to cut people in my freetime

  • Active Members
  • PipPipPipPipPipPip
  • 527 posts

Posted 03 December 2009 - 03:14 AM

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.

They already have a punishment system for abuse.

... and his his name is Valik.

www.minikori.com

#60 Zisly

Zisly

    Universalist

  • Active Members
  • PipPipPipPipPip
  • 252 posts

Posted 03 December 2009 - 02:49 PM

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! :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users