• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Cherokee Lakes

SDL Image Not loading transparent images.

2 posts in this topic

EDIT: I have figured out that it is SDL_DisplayFormat that is causing the issue. Now to just figure out what to do about it.....

 

EDIT 2: SDL_DisplayFormatAlpha fixed the issue. It carries over the alpha value of the image, hence making it transparent. I am not sure whether I should delete this post since it is solved,or if maybe I should leave it up for another beginner who has the same issue? maybe a moderator can help me out.

 

 

I am following this tutorial: http://www.sdltutorials.com/sdl-coordinates-and-blitting. The only difference is I am using the SDL_Image extension to SDL so I can load in .png files. I have used the exact code as the author of the tutorial, except I use IMG_Load("whatever file") instead of SDL_LoadBMP so that I can have transparent images. The images however are not transparent when I blit them to the screen. Yes, they actual images files themself are transparent.One problem I thought might be the issue is that I am using SDL_BlitSurface. I'm not sure if there is another function I need to use with IMG_Load to make the images transparent, but I don't believe so. Below I have the code I am using. If someone could help me out I'd really appreciate it!. Thanks!!

 

The code below is the function that loads in my image. I thought maybe SDL_DisplayFormat might be the problem, but I have not found anything info on Google agreeing with this. 

SDL_Surface* CSurface::OnLoad(char* File){

    SDL_Surface* Surf_Temp = NULL;//The variable that temporarily stores the image when it is loaded in
    SDL_Surface* Surf_Return = NULL;//The variable where the modified image from Surf_Temp will be stored

    //Loads an image in or returns NULL if no image is loaded
    if ((Surf_Temp = IMG_Load(File)) == NULL){
        return NULL;
    }

    Surf_Return = SDL_DisplayFormat(Surf_Temp);//Formats the image in Surf_Return to match the display
    SDL_FreeSurface(Surf_Temp);//Frees the temporary variable Surf_Temp from memory since it is no longer needed

    return Surf_Return;//The function returns the image in Surf_Return
}




Below is the code that blits the image onto the screen:
 
 
 bool CSurface::OnDraw(SDL_Surface* Surf_Dest, SDL_Surface* Surf_Src, int X, int Y){
    if (Surf_Dest == NULL || Surf_Src == NULL){
        return false;
    }

    SDL_Rect DestR;

    DestR.x = X;
    DestR.y = Y;

    SDL_BlitSurface(Surf_Src, NULL, Surf_Dest, &DestR);

    return true;
}
Edited by CherokeeLakes94
1

Share this post


Link to post
Share on other sites

Leave the post up because it might save someone else a headache. That's the whole point of this site. smile.png

 

Edit the title and put [solved] at the beginning, and then only people who are interested in the solution will click through.

 

- Eck

0

Share this post


Link to post
Share on other sites


Edit the title and put [solved] at the beginning, and then only people who are interested in the solution will click through.

We actively discourage this. Sometimes, the OP may believe an issue is solved, but their solution might be poor, or might be outright wrong (e.g. relying on undefined behaviour that happens to "work").

 

A simple follow up reply, mentioning the correct solution, is good. I personally don't like when people edit the original post, but provided such edits are clearly marked, like here, it isn't necessarily a bad thing.

 

In this case, the solution appears to be broadly correct. But to treat this as an example, I might point out that failing to optimise the surface for display doesn't have to be treated as a fatal error, the unoptimised surface could be used (possibly a warning could be logged too):

SDL_Surface* CSurface::OnLoad(char* File){
    SDL_Surface *loaded = IMG_Load(File);
    if(loaded) {
        SDL_Surface *optimised = SDL_DisplayFormatAlpha(loaded);
        if(optimised) {
            SDL_FreeSurface(loaded);
            return optimised;
        }
        return loaded;
    }
    return nullptr;
}
0

Share this post


Link to post
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
Sign in to follow this  
Followers 0