Getting an image on a screen problem... help please?

I started SDL 3 days ago. I copied the code, that was posted on the tutorial. I saved a picture in bmp… but whenever it compiles, all it shows is that black screen with the X on the top right. No picture. Here’s the code. I went on Google, saved an image in bmp for. I named it ‘line’. So after that I punched in the name of my new image, which was saved in BMP format, but it’s all black. What am I doing wrong?

Code:

#include<SDL/SDL.h>

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}

I started SDL 3 days ago. I copied the code, that was posted on the
tutorial. I saved a picture in bmp… but whenever it compiles, all it shows
is that black screen with the X on the top right. No picture. Here’s the
code. I went on Google, saved an image in bmp for. I named it ‘line’. So
after that I punched in the name of my new image, which was saved in BMP
format, but it’s all black. What am I doing wrong?

Code:

#include

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Check if SDL_LoadBMP is returning NULL:
if (hello == NULL)
error!

Check if your bmp is in the same place as you program.

CheersOn Wed, Sep 22, 2010 at 5:16 PM, Soap360 <adam_burn at hotmail.com> wrote:


David

What OS are you on? Some file browsers do not set the current working
directory properly when double-clicking on executables. Even if the file is
in the same directory as the executable, it would still fail. If you’re on
Windows, Explorer does it fine. Either way, some error checking is
advisable as per David’s suggestion.

Jonny DOn Thu, Sep 23, 2010 at 1:10 PM, David Roguin wrote:

On Wed, Sep 22, 2010 at 5:16 PM, Soap360 <adam_burn at hotmail.com> wrote:

I started SDL 3 days ago. I copied the code, that was posted on the
tutorial. I saved a picture in bmp… but whenever it compiles, all it shows
is that black screen with the X on the top right. No picture. Here’s the
code. I went on Google, saved an image in bmp for. I named it ‘line’. So
after that I punched in the name of my new image, which was saved in BMP
format, but it’s all black. What am I doing wrong?

Code:

#include

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Check if SDL_LoadBMP is returning NULL:
if (hello == NULL)
error!

Check if your bmp is in the same place as you program.

Cheers


David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

If the file loading function returns null, you can check what the error is
with the function SDL_GetError(void). That will give you an indication of
the problem. Likely it’s a file not found thing, as mentioned. If you want
to know if that is the problem, try replacing your “line.bmp” argument with
a string that has the entire path to the file, such as
"c:\programming\line.bmp".

Good luck.On Thu, Sep 23, 2010 at 3:04 PM, Jonathan Dearborn wrote:

What OS are you on? Some file browsers do not set the current working
directory properly when double-clicking on executables. Even if the file is
in the same directory as the executable, it would still fail. If you’re on
Windows, Explorer does it fine. Either way, some error checking is
advisable as per David’s suggestion.

Jonny D

On Thu, Sep 23, 2010 at 1:10 PM, David Roguin wrote:

On Wed, Sep 22, 2010 at 5:16 PM, Soap360 <adam_burn at hotmail.com> wrote:

I started SDL 3 days ago. I copied the code, that was posted on the
tutorial. I saved a picture in bmp… but whenever it compiles, all it shows
is that black screen with the X on the top right. No picture. Here’s the
code. I went on Google, saved an image in bmp for. I named it ‘line’. So
after that I punched in the name of my new image, which was saved in BMP
format, but it’s all black. What am I doing wrong?

Code:

#include

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to

line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Check if SDL_LoadBMP is returning NULL:
if (hello == NULL)
error!

Check if your bmp is in the same place as you program.

Cheers


David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Don’t forget to escape those backslashes or use forward slashes instead:
“c:\programming\line.bmp”
“c:/programming/line.bmp”

Jonny DOn Thu, Sep 23, 2010 at 11:20 PM, Christian Leger <chrism.leger at gmail.com>wrote:

If the file loading function returns null, you can check what the error is
with the function SDL_GetError(void). That will give you an indication of
the problem. Likely it’s a file not found thing, as mentioned. If you want
to know if that is the problem, try replacing your “line.bmp” argument with
a string that has the entire path to the file, such as
"c:\programming\line.bmp".

Good luck.

On Thu, Sep 23, 2010 at 3:04 PM, Jonathan Dearborn <@Jonathan_Dearborn>wrote:

What OS are you on? Some file browsers do not set the current working
directory properly when double-clicking on executables. Even if the file is
in the same directory as the executable, it would still fail. If you’re on
Windows, Explorer does it fine. Either way, some error checking is
advisable as per David’s suggestion.

Jonny D

On Thu, Sep 23, 2010 at 1:10 PM, David Roguin wrote:

On Wed, Sep 22, 2010 at 5:16 PM, Soap360 <adam_burn at hotmail.com> wrote:

I started SDL 3 days ago. I copied the code, that was posted on the
tutorial. I saved a picture in bmp… but whenever it compiles, all it shows
is that black screen with the X on the top right. No picture. Here’s the
code. I went on Google, saved an image in bmp for. I named it ‘line’. So
after that I punched in the name of my new image, which was saved in BMP
format, but it’s all black. What am I doing wrong?

Code:

#include

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to

line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Check if SDL_LoadBMP is returning NULL:
if (hello == NULL)
error!

Check if your bmp is in the same place as you program.

Cheers


David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

oops haha I forgot about escaping backslashes (linux programmer here -
forward slashes are my friends)

Please let us know if this advice is helpful, David.On Fri, Sep 24, 2010 at 12:46 AM, Jonathan Dearborn wrote:

Don’t forget to escape those backslashes or use forward slashes instead:
“c:\programming\line.bmp”
“c:/programming/line.bmp”

Jonny D

On Thu, Sep 23, 2010 at 11:20 PM, Christian Leger <@Christian_Leger>wrote:

If the file loading function returns null, you can check what the error is
with the function SDL_GetError(void). That will give you an indication of
the problem. Likely it’s a file not found thing, as mentioned. If you want
to know if that is the problem, try replacing your “line.bmp” argument with
a string that has the entire path to the file, such as
"c:\programming\line.bmp".

Good luck.

On Thu, Sep 23, 2010 at 3:04 PM, Jonathan Dearborn wrote:

What OS are you on? Some file browsers do not set the current working
directory properly when double-clicking on executables. Even if the file is
in the same directory as the executable, it would still fail. If you’re on
Windows, Explorer does it fine. Either way, some error checking is
advisable as per David’s suggestion.

Jonny D

On Thu, Sep 23, 2010 at 1:10 PM, David Roguin wrote:

On Wed, Sep 22, 2010 at 5:16 PM, Soap360 <adam_burn at hotmail.com> wrote:

I started SDL 3 days ago. I copied the code, that was posted on the
tutorial. I saved a picture in bmp… but whenever it compiles, all it shows
is that black screen with the X on the top right. No picture. Here’s the
code. I went on Google, saved an image in bmp for. I named it ‘line’. So
after that I punched in the name of my new image, which was saved in BMP
format, but it’s all black. What am I doing wrong?

Code:

#include

int main( int argc, char* args[] )
{

SDL_Surface* hello = NULL;
SDL_Surface* screen = NULL;

//Start SDL
SDL_Init(SDL_INIT_EVERYTHING);

//Set up screen
screen = SDL_SetVideoMode(640, 480, 32, SDL_SWSURFACE);

//Load image
hello = SDL_LoadBMP("line.bmp"); //all I changed here is hello to

line

//Apply image to screen
SDL_BlitSurface(hello, NULL, screen, NULL);

//Update screen
SDL_Flip(screen);

//Pause
SDL_Delay(4000);

//Free loaded image
SDL_FreeSurface(hello);

//Quit SDL
SDL_Quit();

return 0;

}


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Check if SDL_LoadBMP is returning NULL:
if (hello == NULL)
error!

Check if your bmp is in the same place as you program.

Cheers


David


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org