Blit Images

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 <SDL.h>
#include <stdio.h>
#include <SDL_image.h>
#include <SDL_mixer.h>
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

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

–PhilOn Wed, Mar 12, 2014 at 10:14 AM, theatron 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
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org