# Black Screen?

**URL:** <https://discourse.libsdl.org/t/black-screen/18146>\
**Category:** SDL Development\
**Created:** [April 15, 2011, 7:26pm UTC](https://discourse.libsdl.org/t/black-screen/18146 "2011-04-15T19:26:30Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 15, 2011, 7:26pm UTC](https://discourse.libsdl.org/t/black-screen/18146/1 "2011-04-15T19:26:30Z")

</div>

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

[![](https://www3.picturepush.com/photo/a/5460926/img/Anonymous/eh.png) ](https://www3.picturepush.com/photo/a/5460926/img/Anonymous/eh.png)

[![](https://www5.picturepush.com/photo/a/5460933/img/Anonymous/eh2.png) ](https://www5.picturepush.com/photo/a/5460933/img/Anonymous/eh2.png)

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…

---

<div class="post-metadata">

**Author:** ![Jesse\_A](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/ecae2f/32.png) [@Jesse\_A](https://discourse.libsdl.org/u/Jesse_A)\
**Post date:** [April 18, 2011, 1:46am UTC](https://discourse.libsdl.org/t/black-screen/18146/2 "2011-04-18T01:46:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Nathaniel\_J\_Fries](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nathaniel\_J\_Fries](https://discourse.libsdl.org/u/Nathaniel_J_Fries)\
**Post date:** [April 18, 2011, 8:35pm UTC](https://discourse.libsdl.org/t/black-screen/18146/3 "2011-04-18T20:35:55Z")

</div>

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/](http://natefries.net/)

---

<div class="post-metadata">

**Author:** ![Nathaniel\_J\_Fries](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nathaniel\_J\_Fries](https://discourse.libsdl.org/u/Nathaniel_J_Fries)\
**Post date:** [April 18, 2011, 9:55pm UTC](https://discourse.libsdl.org/t/black-screen/18146/4 "2011-04-18T21:55:36Z")

</div>

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/](http://natefries.net/)

---

<div class="post-metadata">

**Author:** ![Nathaniel\_J\_Fries](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nathaniel\_J\_Fries](https://discourse.libsdl.org/u/Nathaniel_J_Fries)\
**Post date:** [April 18, 2011, 11:06pm UTC](https://discourse.libsdl.org/t/black-screen/18146/5 "2011-04-18T23:06:52Z")

</div>

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

[http://natefries.net/](http://natefries.net/)

---

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 18, 2011, 12:13am UTC](https://discourse.libsdl.org/t/black-screen/18146/6 "2011-04-18T00:13:01Z")

</div>

can anyone help me please?

---

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 18, 2011, 7:41pm UTC](https://discourse.libsdl.org/t/black-screen/18146/7 "2011-04-18T19:41:22Z")

</div>

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

[![](https://www5.picturepush.com/photo/a/5481843/img/Anonymous/eh2.png) ](https://www5.picturepush.com/photo/a/5481843/img/Anonymous/eh2.png)[![](https://www2.picturepush.com/photo/a/5481855/img/Anonymous/eh3.png) ](https://www2.picturepush.com/photo/a/5481855/img/Anonymous/eh3.png)

Should there be somethings in the compiler to compiler SDL Library or somethings?  
[![](https://www2.picturepush.com/photo/a/5481820/img/Anonymous/eh.png) ](https://www2.picturepush.com/photo/a/5481820/img/Anonymous/eh.png)

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

---

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 18, 2011, 9:02pm UTC](https://discourse.libsdl.org/t/black-screen/18146/8 "2011-04-18T21:02:08Z")

</div>

It say

Could not Load “Background.bmp” because SDL\_UpperBlit: passed a Null surface…

---

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 18, 2011, 10:21pm UTC](https://discourse.libsdl.org/t/black-screen/18146/9 "2011-04-18T22:21:13Z")

</div>

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

[![](https://www2.picturepush.com/photo/a/5483055/img/Anonymous/eh.png) ](https://www2.picturepush.com/photo/a/5483055/img/Anonymous/eh.png)

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

---

<div class="post-metadata">

**Author:** ![C64](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/858c86/32.png) [@C64](https://discourse.libsdl.org/u/C64)\
**Post date:** [April 18, 2011, 11:57pm UTC](https://discourse.libsdl.org/t/black-screen/18146/10 "2011-04-18T23:57:31Z")

</div>

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

The executable in the MingW Folder  
[![](https://www5.picturepush.com/photo/a/5483383/img/Anonymous/eh.png) ](https://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 🙂

Thank you Nathaniel J Fries 🙂

---

<div class="post-metadata">

**Author:** ![Nathaniel\_J\_Fries](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/n/ccd318/32.png) [@Nathaniel\_J\_Fries](https://discourse.libsdl.org/u/Nathaniel_J_Fries)\
**Post date:** [April 19, 2011, 9:45pm UTC](https://discourse.libsdl.org/t/black-screen/18146/11 "2011-04-19T21:45:15Z")

</div>

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](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 🙂
> 
> Thank you Nathaniel J Fries 🙂
> 
> P.S. IF you got any Good Tips about SDL then let me know please 🙂

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/](http://natefries.net/)
