Getting Devc++ compile errors on SDL_BlitSurface (n00bie question)

Here is my code. The errors are all on SDL_Blitsurface, and they are:
45 D:\Pyro\main.cpp:31 [Warning] unknown escape sequence '\P’
45 D:\Pyro\main.cpp:31 [Warning] unknown escape sequence ‘\i’
D:\Pyro\main.cpp In function int SDL_main(int, char**)': 40 D:\Pyro\main.cpp cannot convertSDL_Rect’ to SDL_Rect*' for argument4’
to `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*)'
D:\Pyro\Makefile.win [Build Error] [main.o] Error 1

Can anyone please tell me what is wrong?

#include
#include <stdlib.h>

#include <SDL/SDL.h>

#define width 320;
#define height 200;
#define BPP 16;

void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);

using namespace std;

SDL_Surface *screen;
SDL_Surface *tile;

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

SDL_Rect dest;

if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) <0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);

screen = SDL_SetVideoMode(320, 200, 32,
SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
tile = SDL_LoadBMP(“D:\Pyro\img\brick.bmp”);
if ( screen == NULL )
{
cout << "Unable to set "<< “320” << “x” << “200” << “x” << “16” << "
video: " << SDL_GetError() << endl;
return 1;
}
Slock(screen);

dest.x = 0; dest.y=0;
SDL_BlitSurface(screen, NULL, tile, dest);

Sulock(screen);
SDL_Flip(screen);
for (int uhu=0; uhu<1000000000; uhu++);

return 0;
}

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}

tile = SDL_LoadBMP(“D:\Pyro\img\brick.bmp”);

You have to make sure to escape the backslashes like this:

tile = SDL_LoadBMP(“D:\Pyro\img\brick.bmp”);

or this will usually work as well:

tile = SDL_LoadBMP(“D:/Pyro/img/brick.bmp”);

otherwise it’ll think you are trying to use the string escape sequence \P, \i, \b.

  • brian

Ihateusernames wrote:>Here is my code. The errors are all on SDL_Blitsurface, and they are:

45 D:\Pyro\main.cpp:31 [Warning] unknown escape sequence '\P’
45 D:\Pyro\main.cpp:31 [Warning] unknown escape sequence ‘\i’
D:\Pyro\main.cpp In function int SDL_main(int, char**)': 40 D:\Pyro\main.cpp cannot convertSDL_Rect’ to SDL_Rect*' for argument4’
to `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*)'
D:\Pyro\Makefile.win [Build Error] [main.o] Error 1

Can anyone please tell me what is wrong?

#include
#include <stdlib.h>

#include <SDL/SDL.h>

#define width 320;
#define height 200;
#define BPP 16;

void Slock(SDL_Surface *screen);
void Sulock(SDL_Surface *screen);

using namespace std;

SDL_Surface *screen;
SDL_Surface *tile;

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

SDL_Rect dest;

if( SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) <0 )
{
printf(“Unable to init SDL: %s\n”, SDL_GetError());
return 1;
}
atexit(SDL_Quit);

screen = SDL_SetVideoMode(320, 200, 32,
SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
tile = SDL_LoadBMP(“D:\Pyro\img\brick.bmp”);
if ( screen == NULL )
{
cout << "Unable to set "<< “320” << “x” << “200” << “x” << “16” << "
video: " << SDL_GetError() << endl;
return 1;
}
Slock(screen);

dest.x = 0; dest.y=0;
SDL_BlitSurface(screen, NULL, tile, dest);

Sulock(screen);
SDL_Flip(screen);
for (int uhu=0; uhu<1000000000; uhu++);

return 0;
}

void Slock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
if ( SDL_LockSurface(screen) < 0 )
{
return;
}
}
}

void Sulock(SDL_Surface *screen)
{
if ( SDL_MUSTLOCK(screen) )
{
SDL_UnlockSurface(screen);
}
}


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

D:\Pyro\main.cpp In function int SDL_main(int, char**)': 40 D:\Pyro\main.cpp cannot convertSDL_Rect’ to SDL_Rect*' for argument4’
to `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*, SDL_Surface*, SDL_Rect*)'
D:\Pyro\Makefile.win [Build Error] [main.o] Error 1

As to that error [code snipped somewhat]:

[…]
SDL_Rect dest;
[…]
dest.x = 0; dest.y=0;
SDL_BlitSurface(screen, NULL, tile, dest);
[…]

You are passing the actual struct “dest” to the function
SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);

The last argument should be a pointer. Change the line to
SDL_BlitSurface(screen, NULL, tile, &dest);
and it should work.

(As an aside: I don’t know why your compiler complains about
"SDL_UpperBlit", it must be a Windows-SDL internal thing…)

Hope this helps,
Benjamin

Benjamin Deutsch wrote:

D:\Pyro\main.cpp In function int SDL_main(int, char**)': 40 D:\Pyro\main.cpp cannot convertSDL_Rect’ to SDL_Rect*' for argument4’ to `int SDL_UpperBlit(SDL_Surface*, SDL_Rect*,
SDL_Surface*, SDL_Rect*)’ D:\Pyro\Makefile.win [Build Error]
[main.o] Error 1

As to that error [code snipped somewhat]:

[…] SDL_Rect dest;
[…]
dest.x = 0; dest.y=0;
SDL_BlitSurface(screen, NULL, tile, dest);
[…]

You are passing the actual struct “dest” to the function
SDL_BlitSurface(SDL_Surface *src, SDL_Rect *srcrect,
SDL_Surface *dst, SDL_Rect *dstrect);

The last argument should be a pointer. Change the line to
SDL_BlitSurface(screen, NULL, tile, &dest);
and it should work.

(As an aside: I don’t know why your compiler complains about
"SDL_UpperBlit", it must be a Windows-SDL internal thing…)

SDL_BlitSurface is #defined as SDL_UpperBlit in SDL_video.h

Stephane