Blit Images

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Blit Images

theatron
Im tring to blit an image on the screen that says "hello sdl" but its not working, i honestly dont know why, heres the code







Code:

#include
#include
#include
#include
#include
using namespace std;

SDL_Window *window = NULL;
SDL_Surface *scr_s = NULL;
SDL_Surface *img = NULL;

bool init();
bool load();
void close();

int main(int argc, char *args[])
{
        if(!init())
        {
           if(!load())
           {


           }
        }
        else
        {
            SDL_UpdateWindowSurface(window);
            ng
        }

    return 0;
}

 bool init()
    {
       if(SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            printf("SDL IS NOT WORKING!!");
        }
        else
        {
         window  = SDL_CreateWindow("Application",10,20,800,600,SDL_WINDOW_SHOWN);
          img = SDL_LoadBMP("IMG.bmp");
          SDL_BlitSurface(img,NULL,scr_s,NULL);
          scr_s = SDL_GetWindowSurface(window);
         SDL_UpdateWindowSurface(window);
         SDL_Delay(1000);
        }
    }
bool load()
{


}
void close()
{
    SDL_FreeSurface(img);
    img = NULL;
    SDL_DestroyWindow(window);
    SDL_Quit();
}


Its a very simple program.
thanks

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: Blit Images

PHilip RUshik

You aren't getting the surface for the screen until after your blit.
Switch the order of these and it should work:

SDL_BlitSurface(img,NULL,scr_
s,NULL);
  scr_s = SDL_GetWindowSurface(window);



--Phil


On Wed, Mar 12, 2014 at 10:14 AM, theatron <[hidden email]> wrote:
Im tring to blit an image on the screen that says "hello sdl" but its not working, i honestly dont know why, heres the code



Code:


#include
#include
#include
#include
#include
using namespace std;

SDL_Window *window = NULL;
SDL_Surface *scr_s = NULL;
SDL_Surface *img = NULL;

bool init();
bool load();
void close();

int main(int argc, char *args[])
{
        if(!init())
        {
           if(!load())
           {


           }
        }
        else
        {
            SDL_UpdateWindowSurface(window);
            ng
        }

    return 0;
}

 bool init()
    {
       if(SDL_Init(SDL_INIT_VIDEO) < 0)
        {
            printf("SDL IS NOT WORKING!!");
        }
        else
        {
         window  = SDL_CreateWindow("Application",10,20,800,600,SDL_WINDOW_SHOWN);
          img = SDL_LoadBMP("IMG.bmp");
          SDL_BlitSurface(img,NULL,scr_s,NULL);
          scr_s = SDL_GetWindowSurface(window);
         SDL_UpdateWindowSurface(window);
         SDL_Delay(1000);
        }
    }
bool load()
{


}
void close()
{
    SDL_FreeSurface(img);
    img = NULL;
    SDL_DestroyWindow(window);
    SDL_Quit();
}




Its a very simple program.
thanks

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org