[SDL] Loading bitmaps with transparency? (Torsten Giebl)

Leo M. Cabrera leo28c at gmail.com
Mon Mar 5 19:01:55 PST 2007


1982?!  I wasn't born 'till like 7 years after that... xD

Anyway, the "Click on the thumbnails to enlarge." doesn't work on 
Firefox... :-/
(Wee, I owned an old person programmer!) Just kidding. :-P

Patricia Curtis wrote:
>
>
> On 3/5/07, *sdl-request at lists.libsdl.org 
> <mailto:sdl-request at lists.libsdl.org>* <sdl-request at lists.libsdl.org 
> <mailto:sdl-request at lists.libsdl.org>> wrote:
>
>     Send SDL mailing list submissions to
>            sdl at lists.libsdl.org <mailto:sdl at lists.libsdl.org>
>
>     To subscribe or unsubscribe via the World Wide Web, visit
>            http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>     or, via email, send a message with subject or body 'help' to
>            sdl-request at lists.libsdl.org
>     <mailto:sdl-request at lists.libsdl.org>
>
>     You can reach the person managing the list at
>            sdl-owner at lists.libsdl.org <mailto:sdl-owner at lists.libsdl.org>
>
>     When replying, please edit your Subject line so it is more specific
>     than "Re: Contents of SDL digest..."
>     Hi 
>
>      I don't want to get into an argument of coding styles as this is 
> not the place, but i do know about errors and catching them, I just 
> showed you a very simplistic version, just to get you going. sorry for 
> the confusion, by the way i have been coding since 1982  and in that 
> time i have written 27 games, check www.unboxedgames.com 
> <http://www.unboxedgames.com> for the list and i think you will be 
> pleasantly surprised.
>  
> Trish
>  
>  
>
>     Today's Topics:
>
>       1. Re: Loading bitmaps with transparency? (Torsten Giebl)
>          (Bill Kendrick)
>       2. Re: Loading bitmaps with transparency? (Torsten Giebl)
>          (Leo M. Cabrera)
>       3. Re: Flickering and division by zero in Windows
>          (Andre de Leiradella)
>       4. Universal binary crashing on iMac (Core2Duo) system (Lijith P)
>       5. How to create an GDK window inside SDL? (Serjan Pruis)
>       6. Re: How to create an GDK window inside SDL? (Torsten Giebl)
>       7. Problem with not using fullscreen. (Chris Rajula)
>
>
>     ----------------------------------------------------------------------
>
>
>     Message: 1
>     Date: Sun, 4 Mar 2007 15:00:24 -0800
>     From: Bill Kendrick <nbs at sonic.net <mailto:nbs at sonic.net>>
>     Subject: Re: [SDL] Loading bitmaps with transparency? (Torsten Giebl)
>     To: "A list for developers using the SDL library. (includes
>            SDL-announce)"  <sdl at lists.libsdl.org
>     <mailto:sdl at lists.libsdl.org>>
>     Message-ID: <20070304230024.GE30220 at sonic.net
>     <mailto:20070304230024.GE30220 at sonic.net>>
>     Content-Type: text/plain; charset=us-ascii
>
>     On Sun, Mar 04, 2007 at 03:30:42PM +0700, Patricia Curtis wrote:
>     > Its simple to use transparency just save your images as a PNG-24
>     which will
>     > give you 255 levels of transparency and you don't have to do the
>     colour
>     > keying either.
>     >
>     > SDL_Surface * gLoadedImage =
>     SDL_DisplayFormatAlpha(IMG_Load("SomePNG.png"
>     > ));
>
>     Bad coding style.  If IMG_Load() fails for some reason (file not
>     found,
>     corrupted file, out of memory, etc.), you'll be sending a NULL ptr to
>     SDL_DisplayFormatAlpha().  I imagine that'd cause a segfault
>     (aka SDL parachute launch).
>
>     Always check for NULL and for errors!
>
>
>     Of course, if I recall, they wanted to literally load Windows
>     BitMaP (.bmp)
>     files, as they were in an environment where SDL_Image library (and
>     hence
>     IMG_Load(), and hence PNG support) was unavailable.
>
>     So for that, use BMP with a color-key.
>
>     --
>     -bill!
>     bill at newbreedsoftware.com <mailto:bill at newbreedsoftware.com>
>     http://www.newbreedsoftware.com/
>
>
>     ------------------------------
>
>     Message: 2
>     Date: Sun, 04 Mar 2007 18:06:03 -0800
>     From: "Leo M. Cabrera" < leo28c at gmail.com <mailto:leo28c at gmail.com>>
>     Subject: Re: [SDL] Loading bitmaps with transparency? (Torsten Giebl)
>     To: "A list for developers using the SDL library. (includes
>            SDL-announce)"  < sdl at lists.libsdl.org
>     <mailto:sdl at lists.libsdl.org>>
>     Message-ID: <45EB7B0B.1090206 at gmail.com
>     <mailto:45EB7B0B.1090206 at gmail.com>>
>     Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>     >
>     > Bad coding style.  If IMG_Load() fails for some reason (file not
>     found,
>     > corrupted file, out of memory, etc.), you'll be sending a NULL
>     ptr to
>     > SDL_DisplayFormatAlpha().  I imagine that'd cause a segfault
>     > (aka SDL parachute launch).
>     Ha, yes, I do the same thing... *embarrass*
>
>     I always say; "I'll do this now, then I'll add error checking
>     whenever I
>     finish the proggy..."
>
>     But when I finish it, I forget... gotta improve that. xD
>
>
>     Bill Kendrick wrote:
>     > On Sun, Mar 04, 2007 at 03:30:42PM +0700, Patricia Curtis wrote:
>     >
>     >> Its simple to use transparency just save your images as a
>     PNG-24 which will
>     >> give you 255 levels of transparency and you don't have to do
>     the colour
>     >> keying either.
>     >>
>     >> SDL_Surface * gLoadedImage =
>     SDL_DisplayFormatAlpha(IMG_Load("SomePNG.png"
>     >> ));
>     >>
>     >
>     > Bad coding style.  If IMG_Load() fails for some reason (file not
>     found,
>     > corrupted file, out of memory, etc.), you'll be sending a NULL
>     ptr to
>     > SDL_DisplayFormatAlpha().  I imagine that'd cause a segfault
>     > (aka SDL parachute launch).
>     >
>     > Always check for NULL and for errors!
>     >
>     >
>     > Of course, if I recall, they wanted to literally load Windows
>     BitMaP (.bmp)
>     > files, as they were in an environment where SDL_Image library
>     (and hence
>     > IMG_Load(), and hence PNG support) was unavailable.
>     >
>     > So for that, use BMP with a color-key.
>     >
>     >
>
>
>
>     ------------------------------
>
>     Message: 3
>     Date: Sun, 04 Mar 2007 20:40:18 -0300
>     From: Andre de Leiradella < leiradella at bigfoot.com
>     <mailto:leiradella at bigfoot.com>>
>     Subject: Re: [SDL] Flickering and division by zero in Windows
>     To: sdl at lists.libsdl.org <mailto:sdl at lists.libsdl.org>
>     Message-ID: < 45EB58E2.1010005 at bigfoot.com
>     <mailto:45EB58E2.1010005 at bigfoot.com>>
>     Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>
>     > -- set the video mode
>     > local screen = image_lib.set_video(800, 600)
>     > -- load and resize the background
>     > local background = image_lib.load('background.png')
>     > background = background.resize(screen.width, screen.height)
>     > -- evaluates a half-transparent black color
>     > local transparent = image_lib.color(0, 0, 0, 128)
>     > -- loop until the user presses the left mouse button
>     > while true do
>     >     -- query the mouse
>     >     x, y, left = input_lib.mouse()
>     >     -- blit the background to the screen, covering all pixels
>     >     background.blit(screen, 0, 0)
>     >     -- fill a square with the half-transparent black
>     >     screen.filled_rect(10, 10, screen.width - 10, screen.width - 10,
>     > transparent)
>     >     -- update the screen
>     >     screen.update()
>     >     -- if left mouse button was pressed, break the loop
>     >     if left then
>     >        break
>     >     end
>     > end
>     >
>
>     I have found the problem. Blame me, I was setting up a one-second,
>     repeating timer that was calling SDL_UpdateRect. When I removed the
>     SDL_UpdateRect from the timer the flickering went away.
>
>     Sorry for the noise...
>
>     Andre
>
>
>     ------------------------------
>
>     Message: 4
>     Date: Mon, 5 Mar 2007 12:23:48 +0530
>     From: "Lijith P" <lijithstar at gmail.com <mailto:lijithstar at gmail.com>>
>     Subject: [SDL] Universal binary crashing on iMac (Core2Duo) system
>     To: sdl at libsdl.org <mailto:sdl at libsdl.org>
>     Message-ID:
>            <bfd660b30703042253k5dfb6b34we1357743e105d69 at mail.gmail.com
>     <mailto:bfd660b30703042253k5dfb6b34we1357743e105d69 at mail.gmail.com>>
>     Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>     HI,
>
>     I am trying to built a universal binary application using xcode
>     2.3 and sdl
>
>     framework..
>
>     The application works finely on the ppc.. But when i try to run the
>
>     application on an  iMac (core2Duo) system , the application is
>     crashing at
>
>     randomly..  But when i disable one cpu , the application is running
>
>     properly..
>
>     My application has  a main thread and a helper thread...
>
>     Is there any way to schedule multiple threads in a single processor on
>     a dual core
>     system..
>
>     Valuable suggestion regarding this are most welcome..
>
>     Regards
>     Lijith
>
>
>     ------------------------------
>
>     Message: 5
>     Date: Mon, 5 Mar 2007 12:11:26 +0100
>     From: Serjan Pruis <serjan at quicknet.nl <mailto:serjan at quicknet.nl>>
>     Subject: [SDL] How to create an GDK window inside SDL?
>     To: "A list for developers using the SDL library. (includes
>            SDL-announce)"  <sdl at lists.libsdl.org
>     <mailto:sdl at lists.libsdl.org>>
>     Message-ID: <200703051211.26588.serjan at quicknet.nl
>     <mailto:200703051211.26588.serjan at quicknet.nl>>
>     Content-Type: text/plain;  charset="iso-8859-1"
>
>     Hi,
>
>     I'm trying to add an GTK/GDK window to my application,
>     Does any one already done this?
>     I am able to create a Xwindow with a window id so that i can give
>     the window id to mplayer so it can run in a window in my app.
>     But i also want to play flash files in my window and so i guess i
>     need a GDK
>     window.
>
>     Thanks in advance.
>     Serjan
>
>
>     ------------------------------
>
>     Message: 6
>     Date: Mon, 5 Mar 2007 14:53:31 +0100
>     From: "Torsten Giebl" <wizard at syntheticsw.com
>     <mailto:wizard at syntheticsw.com>>
>     Subject: Re: [SDL] How to create an GDK window inside SDL?
>     To: "A list for developers using the SDL library. (includes
>            SDL-announce)"  <sdl at lists.libsdl.org
>     <mailto:sdl at lists.libsdl.org>>
>     Message-ID:
>            <
>     ce432aba0703050553g7598f309tc7167ae5ff4cf82a at mail.gmail.com
>     <mailto:ce432aba0703050553g7598f309tc7167ae5ff4cf82a at mail.gmail.com>>
>     Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
>     Hello !
>
>
>     > I'm trying to add an GTK/GDK window to my application,
>     > Does any one already done this?
>     > I am able to create a Xwindow with a window id so that i can give
>     > the window id to mplayer so it can run in a window in my app.
>     > But i also want to play flash files in my window and so i guess
>     i need a GDK
>     > window.
>
>
>     Sam Lantinga has done something like this :
>
>     http://www.libsdl.org/projects/gtk-demo/
>
>
>     CU
>
>
>     ------------------------------
>
>     Message: 7
>     Date: Mon, 5 Mar 2007 15:45:41 +0100
>     From: "Chris Rajula" <superrajula at gmail.com
>     <mailto:superrajula at gmail.com>>
>     Subject: [SDL] Problem with not using fullscreen.
>     To: sdl at lists.libsdl.org <mailto:sdl at lists.libsdl.org>
>     Message-ID:
>            <630acb5b0703050645k6ba6d1dxccb7a71b538a5541 at mail.gmail.com
>     <mailto:630acb5b0703050645k6ba6d1dxccb7a71b538a5541 at mail.gmail.com>>
>     Content-Type: text/plain; charset="iso-8859-1"
>
>     Hello there!
>
>     I have written a small testing-program that uses OpenGL and creates a
>     window, but I have a small problem, namely that I can't get it not
>     to use
>     fullscreen.
>     Using the program to draw a circle or whatever works just fine,
>     but I can't
>     get it to create a windowed window...
>
>     I have the program divided into three separate files. One
>     program-file, one
>     class-file and one file containing the functions for the class.
>     I appreciate any help.
>
>     Thank you.
>
>     /Chris
>
>     Here we go:
>     window.h:
>     #ifndef _draw_h
>     #define _draw_h
>
>     class window{
>            private:
>                    int height;
>                    int width;
>                    int depth;
>                    bool debug;
>                    bool fullscreen;
>            public:
>                    window();
>                    window(int w, int h, int d, bool fs);
>                    void SDLInit();
>                    void Event();
>                    ~window();
>     };
>
>     #endif
>
>     window.cpp:
>     #ifdef WIN32
>     #include <windows.h>
>     #endif
>
>     #include <iostream>
>     #include <SDL.h>
>     #include <GL/gl.h>
>     #include <GL/glu.h>
>     #include "window.h"
>
>     window::window(){
>            debug = 1;
>            width = 640;
>            height = 480;
>            depth = 32;
>            fullscreen = false;
>            if(debug == 1)
>                    std::cout << "Height, width, and depth specified.\n";
>     }
>
>     window::window(int w,int h,int d,bool fs){
>            if(fs == true) fullscreen = true;
>            else fullscreen = false;
>            if(h == 0) h = 1;
>            if(w == 0) w = 1;
>            if(d == 0) d = 32;
>            width = w;
>            height = h;
>            depth = d;
>            if(debug == 1)
>                    std::cout << "Height, width, and depth specifically
>     specified.\n";
>     }
>
>
>     void window::SDLInit(){
>            int error;
>            // Just initialize everything and check for errors. Keep it
>     simple,
>     stupid. FIXME Check the error flag.
>            error = SDL_Init(SDL_INIT_EVERYTHING);
>            // std::cout << SDL_GetError();
>            // I keep getting "Failed loading DPMSDisable:
>     /usr/lib/libX11.so.6:
>     undefined symbol" here.
>            // It has something to do with SDLinitializing video, but I
>     don't
>     think it's a problem.
>
>            // Here we set the different attributes for the drawing
>     context.
>            SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);    // Double
>     buffering.
>     (Draw on offscreen buffer, then move to screen.)
>            SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, depth);  // Depth of the
>     buffer.
>            // Be sure to allocate space for the different colors to 8
>     bits,
>     since we use a depth of 32 bits. FIXME (8/colour for 32bit depth!)
>            SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);                // Red
>     colour.
>            SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);      // Green
>     colour.
>            SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);               //
>     Blue
>     colour.
>            SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);      //
>     Transparency.
>            // Creating an SDL surface.
>            Uint32 flags;   // Used for choosing how the drawing
>     context should
>     act.
>            if(fullscreen == true) flags = SDL_OPENGL | SDL_FULLSCREEN;
>            else flags = SDL_OPENGL;
>            SDL_Surface* drawContext;
>            // Create the OpenGL draw context.
>            drawContext = SDL_SetVideoMode(width,height,depth,flags);
>     }
>
>     void window::Event(){
>            SDL_Event event;
>            bool exit = false;
>            while((!exit) && (SDL_WaitEvent(&event))) {
>                    switch(event.type) {
>                            case SDL_KEYDOWN:
>                                    exit = true;
>                            break;
>                            case SDL_MOUSEBUTTONDOWN:
>                                    exit = true;
>                            break;
>                    }
>            }
>     }
>
>     window::~window(){
>            SDL_Quit();
>     }
>
>     test.cpp:
>     #include <iostream>
>     #include "window.h"
>
>     int main(int argc, char *argv[]){
>            bool fs = true;
>            window window;
>            //window window(100,100,32,fs);
>            window.SDLInit();
>            // The main function should here call some different stuff.
>            // Preferences();
>            // It should enable or disable antialiasing and such, and read
>     values from a file of user preferences.
>            // It should also call a specific first-run-function to set the
>     initial values for the user.
>            window.Event();
>            return 0;
>     }
>     -------------- next part --------------
>     An HTML attachment was scrubbed...
>     URL:
>     http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20070305/deb73c87/attachment.html
>
>     ------------------------------
>
>     _______________________________________________
>     SDL mailing list
>     SDL at lists.libsdl.org <mailto:SDL at lists.libsdl.org>
>     http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>     <http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org>
>
>
>     End of SDL Digest, Vol 3, Issue 10
>     **********************************
>
>
>
>
> -- 
> In a time of universal deceit, telling the truth is a revolutionary act.
>
> Trish & Thy also Available on
>
> Skype tranmaithy63,
> ------------------------------------------------------------------------
>
> _______________________________________________
> SDL mailing list
> SDL at lists.libsdl.org
> http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
>   



More information about the SDL mailing list