Black Screen?

Hello everyone…

I am new here…
I am using wxDev-C++ and try doing Bitmap SDL. When I run the program and I get the black screen instead of the bitmap.

I have follow your tutorials on how Setup SDL on BloodShed C++ and it work fine but when come to bitmap…it doesnt work…

I going show you some picture if I doing the right way

When I make Bitmap c++ as I put in the Same folder with SDL.DLL and the bitmap image too.

please let me know what I am doing wrong…

Your images show your project setup (include directories and so forth), but it sounds like this is a run-time problem, correct? (That is, your program is compiling and linking correctly; it’s just not behaving as you expect.)

In any case, the first thing I’d recommend is to make sure you’re checking return values where appropriate. For example, make sure the function that loads the image isn’t returning null.

include stdio.h and add the following before you call SDL_BlitSurface:

if(hello == NULL)
{
printf(“Could not load “background.bmp” because %s\n\r”, SDL_GetError());
getchar();
SDL_Quit();
return -1;
}------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

C64 wrote:

It say

Could not Load “Background.bmp” because SDL_UpperBlit: passed a Null surface…

you added it after the call, not before it like I said. But that’s okay. Basically, SDL couldn’t load the bitmap. Are you sure it’s in the same folder as the executable, and that it’s actually a valid .bmp?------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

but where’s the executable? I didn’t see it in the picture.------------------------
EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/

can anyone help me please?

Hiya there,

I think it is the run time problem that I having…because the image suppose turn up but it doesnt…

here the code of SDL

Code:

#include “SDL/SDL.h”

int main( int argc, char* args[] )
{
//The images
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( "background.bmp" );

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

//Update Screen
SDL_Flip(screen);

//Pause
SDL_Delay( 2000 );

//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL
SDL_Quit();

return 0;

}

Here the Compiler Option picture that I have added as I have follow the tutorials

Should there be somethings in the compiler to compiler SDL Library or somethings?

Is just that one missing that stop from image working…do you know that one missing bit to make work?

It say

Could not Load “Background.bmp” because SDL_UpperBlit: passed a Null surface…

Here code on what I been told when you told me to add extra code which is

Code:

#include “stdio.h”

#include “SDL/SDL.h”

int main( int argc, char* args[] )
{
//The images
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( "background.bmp" );

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

//Update Screen
SDL_Flip(screen);

//Pause
SDL_Delay( 2000 );

if(hello == NULL)
{
  printf("Could not load \"background.bmp\" because %s\n\r", SDL_GetError());
  getchar();
  SDL_Quit();
  return -1;
 }
 
//Free the loaded image
SDL_FreeSurface( hello );

//Quit SDL
SDL_Quit();

return 0;

}

Are you sure it’s in the same folder as the executable, and that it’s actually a valid .bmp?

I got everythings in the same folder but Here the folder picture

I hoping that you might see where I going wrong in the folder picture…

but where’s the executable? I didn’t see it in the picture.

The executable in the MingW Folder

So I put Picture of Background in MingW folder and when I run the program and I got the picture Working! YAY :slight_smile:

Thank you Nathaniel J Fries :slight_smile:

C64 wrote:

but where’s the executable? I didn’t see it in the picture.

The executable in the MingW Folder
http://www5.picturepush.com/photo/a/5483383/img/Anonymous/eh.png

So I put Picture of Background in MingW folder and when I run the program and I got the picture Working! YAY :slight_smile:

Thank you Nathaniel J Fries :slight_smile:

P.S. IF you got any Good Tips about SDL then let me know please :slight_smile:

I do.

  1. Update to SDL 1.3, it’s way better. You won’t find a tutorial though, so maybe wait until you’re familiar with 1.2 first.
  2. Use SDL_Image and use PNGs. They’re smaller.
  3. Use RLE_ACCEL for surfaces in 1.2. You’ll get a few more frames.
  4. Your drawing code should be in an infinite loop that exits based on user input.
  5. If SDL is your first foray into real programming, you should be reading general programming tutorials first. You’ll understand SDL much better that way.
  6. There’s about a million open-source games using SDL. Reference them.------------------------
    EM3 Nathaniel Fries, U.S. Navy

http://natefries.net/