Jump to content

  • Log In with Google      Sign In   
  • Create Account


SDL multiple layer - why doesn't this work?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 ZwodahS   Members   -  Reputation: 481

Like
0Likes
Like

Posted 21 March 2013 - 07:08 AM

Hi , i was playing around with SDL but I couldn't get a surface to be blit onto another surface.

 

Here is the code

 

#include <iostream>

#include "SDL/SDL.h"
#include "SDL/SDL_image.h"


int main(int argc , char * argv[])
{
    if(SDL_Init(SDL_INIT_EVERYTHING)==-1)
    {   
        return -1; 
    }   
    SDL_WM_SetCaption("Testing",NULL);
        
    SDL_Surface* _screen = SDL_SetVideoMode(500,500,32,SDL_SWSURFACE);

    SDL_Surface* img = IMG_LoadPNG_RW(SDL_RWFromFile("img/blocks.png","rb"));

    SDL_Surface* f1 = SDL_CreateRGBSurface(SDL_SWSURFACE,500,500,32,0x000000ff,0x0000ff00,0x00ff0000,0xff000000);

    std::cout << SDL_BlitSurface(img,NULL,f1,NULL) << std::endl;

    std::cout << SDL_BlitSurface(f1,NULL,_screen,NULL) << std::endl;

    SDL_Flip(_screen);
    SDL_Delay(3000);

}

 

 

I tried many things but it still doesn't work.


I think i am missing something here but I am not sure what.


Check out my blog at zwodahs.github.io and zwodahs.itch.io/


Sponsor:

#2 Dante12129   Members   -  Reputation: 1036

Like
0Likes
Like

Posted 21 March 2013 - 04:43 PM

How come you don't free the surfaces or quit SDL?



#3 amrazek111   Members   -  Reputation: 692

Like
1Likes
Like

Posted 21 March 2013 - 06:28 PM

Is your image loaded successfully?  Right after img would be a good place to display SDL_GetError() if img turns out to be NULL.

 

Also: Don't assume you know the underlying pixel format.  For instance, on my computer your masks are wrong.  Just use the screen's format.

SDL_Surface* img = IMG_Load("blocks.png");



    if (!img) {

        std::cout << "Error: " << SDL_GetError() << std::endl;

        return -2;

    }

SDL_Surface* f1 = SDL_CreateRGBSurface(SDL_SWSURFACE,500,500,32,_screen->format->Rmask,

                                                                    _screen->format->Gmask,

                                                                    _screen->format->Bmask,

                                                                    _screen->format->Amask);


After that, blitting with the alpha transparency worked fine for me.



#4 ZwodahS   Members   -  Reputation: 481

Like
0Likes
Like

Posted 21 March 2013 - 09:00 PM

thanks a lot. The mask fixed it. I took the mask format from the documentation. Once again, thanks alot :P


Check out my blog at zwodahs.github.io and zwodahs.itch.io/


#5 Khatharr   Crossbones+   -  Reputation: 2958

Like
0Likes
Like

Posted 21 March 2013 - 09:49 PM

How come you don't free the surfaces or quit SDL?

 

It's not production code. He's just concept testing. When the program exits it will release the resources.


void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS