# Problem with CreateRGBSurface an blitting

**URL:** <https://discourse.libsdl.org/t/problem-with-creatergbsurface-an-blitting/9775>\
**Category:** SDL Development\
**Created:** [November 30, 2003, 6:09pm UTC](https://discourse.libsdl.org/t/problem-with-creatergbsurface-an-blitting/9775 "2003-11-30T18:09:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthias\_Rustler](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/m/cdc98d/32.png) [@Matthias\_Rustler](https://discourse.libsdl.org/u/Matthias_Rustler)\
**Post date:** [November 30, 2003, 6:09pm UTC](https://discourse.libsdl.org/t/problem-with-creatergbsurface-an-blitting/9775/1 "2003-11-30T18:09:01Z")

</div>

Hi,

I want to load a bitmap, blit it to a temporare surface and then blit the temp surface to the screen.  
But the screen keeps black.  
What am I doing wrong?

Bye, Matthias

#include \<stdlib.h\>  
#include \<stdio.h\>

#include “SDL.h”

#define SCREEN\_X (800)  
#define SCREEN\_Y (600)  
#define SCREEN\_DEPTH (8)

SDL\_Surface \*screen;  
SDL\_Surface \*tile\_surf;  
SDL\_Surface \*board\_surf;  
SDL\_Rect rect;

int  
main( void )  
{  
if (SDL\_Init (SDL\_INIT\_VIDEO) \< 0)  
{  
fprintf (stderr, “SDL konnte nicht initialisiert werden: %s\n”, SDL\_GetError ());  
exit( EXIT\_FAILURE );  
}

```
atexit (SDL_Quit);

screen = SDL_SetVideoMode (SCREEN_X, SCREEN_Y, 8, SDL_HWSURFACE|SDL_HWPALETTE);

if (screen == NULL)
{
	fprintf (stderr, "Couldn't set %dx%d video mode: %s\n", SCREEN_X , SCREEN_Y, SDL_GetError ());
	exit (EXIT_FAILURE);
}

tile_surf = SDL_LoadBMP ( "wall.bmp" );

if (tile_surf == NULL)
{
	fprintf (stderr, "Couldn't load %s\n", SDL_GetError ());
	exit (EXIT_FAILURE);
}

board_surf = SDL_CreateRGBSurface(SDL_HWSURFACE , SCREEN_X , SCREEN_Y ,
				SCREEN_DEPTH,
				screen->format->Rmask,
				screen->format->Gmask,
				screen->format->Bmask,
				screen->format->Amask);

if ( SDL_BlitSurface( tile_surf, NULL, board_surf, NULL) <0 )
{
	fprintf (stderr, "Couldn't blit surface %s\n", SDL_GetError ());
	exit (EXIT_FAILURE);
}

if ( SDL_BlitSurface( board_surf , NULL, screen, NULL) <0 )
{
	fprintf (stderr, "Couldn't blit surface %s\n", SDL_GetError ());
	exit (EXIT_FAILURE);
}

SDL_Flip( screen );
SDL_Delay(2000);
SDL_FreeSurface( tile_surf );
SDL_FreeSurface( board_surf );
return EXIT_SUCCESS;

```

}

---

<div class="post-metadata">

**Author:** ![Stephane\_Marchesin](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/a183cd/32.png) [@Stephane\_Marchesin](https://discourse.libsdl.org/u/Stephane_Marchesin)\
**Post date:** [December 2, 2003, 6:53am UTC](https://discourse.libsdl.org/t/problem-with-creatergbsurface-an-blitting/9775/2 "2003-12-02T06:53:00Z")

</div>

Matthias Rustler wrote:

[…]

> board\_surf = SDL\_CreateRGBSurface(SDL\_HWSURFACE , SCREEN\_X , SCREEN\_Y ,  
> SCREEN\_DEPTH,  
> screen-\>format-\>Rmask,  
> screen-\>format-\>Gmask,  
> screen-\>format-\>Bmask,  
> screen-\>format-\>Amask);

From the SDL\_CreateRGBSurface manpage :

> If depth is 8 bits an empty palette is allocated for the surface  
> notice you have an empty palette by default

Stephane
