Seemingly simple video errors

I am having a weird problem when I’m trying to do the simple thing of
loading a bitmap onto a screen. I included my program below. It will get
through all the checks, except for the last one in which it will always
return NULL to image, when I call the function SDL_LoadBMP. Can you help me
out? I’ve pondered for a while over this one. I know the program isn’t
complete, it doesn’t need to be.

#include <iostream.h>
#include <SDL.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
char *file_name = “testing.bmp”;

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << “Error initializing video.” << endl;
return 0;
}

atexit(SDL_Quit);

screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSurface);

cout << “Video mode has been set.” << endl;
cout << "The filename is " << file_name << endl;

image = SDL_LoadBMP(file_name);

if (image == NULL)
{
cout << “Error loading bmp.” << endl;
}

return 0;
}

Like I said, I always end up with the Error loading bmp. message.

///////////
// Leo //
///////////_________________________________________________________________
Make your home warm and cozy this winter with tips from MSN House & Home.
http://special.msn.com/home/warmhome.armx

This doesn’t totally answer your question but you could get more info by
doing something like this:

if (image == NULL)
{
cout << "Error loading bmp: " << SDL_GetError() << endl;
}

that’ll at least tell you why SDL is not loading your file (on linux I often
have problems path-wise since it never seems to look in the current
directory for the specified file).> ----- Original Message -----

From: sdl-admin@libsdl.org [mailto:sdl-admin at libsdl.org] On Behalf Of Leo .
Sent: Saturday, January 03, 2004 7:25 PM
To: sdl at libsdl.org
Subject: [SDL] Re: Seemingly simple video errors

I am having a weird problem when I’m trying to do the simple thing of
loading a bitmap onto a screen. I included my program below. It will get
through all the checks, except for the last one in which it will always
return NULL to image, when I call the function SDL_LoadBMP. Can you help me

out? I’ve pondered for a while over this one. I know the program isn’t
complete, it doesn’t need to be.

#include <iostream.h>
#include <SDL.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
char *file_name = “testing.bmp”;

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << “Error initializing video.” << endl;
return 0;
}

atexit(SDL_Quit);

screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSurface);

cout << “Video mode has been set.” << endl;
cout << "The filename is " << file_name << endl;

image = SDL_LoadBMP(file_name);

if (image == NULL)
{
cout << “Error loading bmp.” << endl;
}

return 0;
}

Like I said, I always end up with the Error loading bmp. message.

///////////
// Leo //
///////////


Make your home warm and cozy this winter with tips from MSN House & Home.
http://special.msn.com/home/warmhome.armx


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Leo . wrote:

I am having a weird problem when I’m trying to do the simple thing of
loading a bitmap onto a screen. I included my program below. It will
get through all the checks, except for the last one in which it will
always return NULL to image, when I call the function SDL_LoadBMP.
Can you help me out? I’ve pondered for a while over this one. I know
the program isn’t complete, it doesn’t need to be.

#include <iostream.h>
#include <SDL.h>

int main()
{
SDL_Surface *screen;
SDL_Surface *image;
char *file_name = “testing.bmp”;

if(SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << “Error initializing video.” << endl;
return 0;
}

atexit(SDL_Quit);

screen = SDL_SetVideoMode(640, 480, 8, SDL_SWSurface);

That should be SDL_SWSURFACE and not SDL_SWSurface

cout << “Video mode has been set.” << endl;
cout << "The filename is " << file_name << endl;

image = SDL_LoadBMP(file_name);

if (image == NULL)
{
cout << “Error loading bmp.” << endl;
}

return 0;
}

Like I said, I always end up with the Error loading bmp. message.

Your code works fine here !
Maybe you don’t have rights on the .bmp file or the file isn’t located
in the current path ?

Stephane