BMP is not drawed

Hello

I’ve got a little problem with my first project with SDL

Theres a class “CPlayer” (short version):-------------------------------------------------------------------
class CPlayer {
public:
/* Spielerbitmap laden /
int LoadBMP();
/
Spieler zeichnen */
void Draw(SDL_Surface target);
private:
/
SDL_Surface f?r das Bitmap */
SDL_Surface bmp;
/
Muss der Spieler geupdatet werden */
bool update;
};

int CPlayer::LoadBMP() {
bmp = SDL_LoadBMP(“gfx/player.bmp”);
if (!bmp) {
fprintf(stderr, “Bitmap konnte nicht geladen werden: %s\n”,
SDL_GetError());
exit(4);
}
return 0;
}

void CPlayer::Draw(SDL_Surface *target) {
if(update) {
SDL_BlitSurface(bmp, 0, target, 0);
SDL_UpdateRect(target, 0, 0, 0, 0);
}
}

n
With this class i create a player named “testi”. “testi” gets some
information with a konstruktor (position, update or no update, LoadBMP()
etc.).

Then i try to draw the picture with “testi.draw(screen)” but nothing
happens. The variable update hast the value true and the Surface screen
does exist.

If i do the whole thing without a class it works.
can you help me?

maybe it’s an obvious thing, but did you call testi.loadBMP() before
calling to testi.draw(…) ?++++++++++++++++++++++++++++++++
ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

-----Mensaje original-----
De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de
sebastian at barfoot.mine.nu
Enviado el: mi?rcoles, 07 de septiembre de 2005 17:23
Para: sdl at libsdl.org
Asunto: [SDL] BMP is not drawed

Hello

I’ve got a little problem with my first project with SDL

Theres a class “CPlayer” (short version):

class CPlayer {
public:
/* Spielerbitmap laden /
int LoadBMP();
/
Spieler zeichnen */
void Draw(SDL_Surface target);
private:
/
SDL_Surface f?r das Bitmap */
SDL_Surface bmp;
/
Muss der Spieler geupdatet werden */
bool update;
};

int CPlayer::LoadBMP() {
bmp = SDL_LoadBMP(“gfx/player.bmp”);
if (!bmp) {
fprintf(stderr, “Bitmap konnte nicht geladen werden: %s\n”,
SDL_GetError());
exit(4);
}
return 0;
}

void CPlayer::Draw(SDL_Surface *target) {
if(update) {
SDL_BlitSurface(bmp, 0, target, 0);
SDL_UpdateRect(target, 0, 0, 0, 0);
}
}

n
With this class i create a player named “testi”. “testi” gets some
information with a konstruktor (position, update or no update, LoadBMP()
etc.).

Then i try to draw the picture with “testi.draw(screen)” but nothing
happens. The variable update hast the value true and the Surface screen
does exist.

If i do the whole thing without a class it works.
can you help me?


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

And did you refresh the screen with SDL_Flip or SDL_UpdateRect(0,0,0,0) ? (I
dont exactly remember the names of the functions sorry.)–

P.O.M.P.E.I. du 47-20

Yes i do call LoadBMP() in the konstruktor of the class.>

maybe it’s an obvious thing, but did you call testi.loadBMP() before
calling to testi.draw(…) ?

++++++++++++++++++++++++++++++++
ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

-----Mensaje original-----
De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de
@sebastian_at_barfoot
Enviado el: mi?rcoles, 07 de septiembre de 2005 17:23
Para: sdl at libsdl.org
Asunto: [SDL] BMP is not drawed

Hello

I’ve got a little problem with my first project with SDL

Theres a class “CPlayer” (short version):

class CPlayer {
public:
/* Spielerbitmap laden /
int LoadBMP();
/
Spieler zeichnen */
void Draw(SDL_Surface target);
private:
/
SDL_Surface f?r das Bitmap */
SDL_Surface bmp;
/
Muss der Spieler geupdatet werden */
bool update;
};

int CPlayer::LoadBMP() {
bmp = SDL_LoadBMP(“gfx/player.bmp”);
if (!bmp) {
fprintf(stderr, “Bitmap konnte nicht geladen werden: %s\n”,
SDL_GetError());
exit(4);
}
return 0;
}

void CPlayer::Draw(SDL_Surface *target) {
if(update) {
SDL_BlitSurface(bmp, 0, target, 0);
SDL_UpdateRect(target, 0, 0, 0, 0);
}
}

n
With this class i create a player named “testi”. “testi” gets some
information with a konstruktor (position, update or no update, LoadBMP()
etc.).

Then i try to draw the picture with “testi.draw(screen)” but nothing
happens. The variable update hast the value true and the Surface screen
does exist.

If i do the whole thing without a class it works.
can you help me?


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


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

Do I need to use SDL_Flip if im not using doublebuffer?

SDL_UpdateRect is called in the function CPlayer::Draw(SDL_Surface *target)
(void CPlayer::Draw(SDL_Surface *target) {
SDL_BlitSurface(bmp, 0, target, 0);
SDL_UpdateRect(target, 0, 0, 0, 0);
})> And did you refresh the screen with SDL_Flip or SDL_UpdateRect(0,0,0,0) ?

(I
dont exactly remember the names of the functions sorry.)

P.O.M.P.E.I. du 47-20


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

AFAIK SDL_Flip will do an SDL_UpdateRect( /entire screen/); if the screen
surface isn’t doublebuffered.

sebastian at barfoot.mine.nu wrote:

Do I need to use SDL_Flip if im not using doublebuffer?

SDL_UpdateRect(screen, 0,0,0,0) is identical to SDL_Flip(screen).

It would be more helpful if we had an actual working program rather than
a code snippet…the code you posted looks reasonable, but even though
you say “update is true”, maybe it’s not…we can’t tell without the
full source, and can only be helpful as far as throwing common guesses
at it and hoping for the right answer…since you say it’s working when
not a C++ class, we have to assume that this isn’t an SDL issue, but an
unrelated C++ mistake beyond our vision. Can you post the whole source?

Thanks,
–ryan.

Hmmm strange.

I’ve got a header named main.h in this header is a function:------------------------------------------------------------
/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

/* Videomodus setzen */
target = SDL_SetVideoMode(640, 480, 0, 0);
if (!target) {
fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,
SDL_GetError());
exit(2);
}

/* Netzwerkunterst?tzung aktivieren */
if(SDLNet_Init() < 0) {
fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
exit(3);
}
return 0;
}


It’s called in main() with “initgame(screen)”. If I use these funtion the
screen stays black, no bmp is drawed. If I don’t us the function and do
write the orders in the function directly to main() the bmp is drawed. I
can’t say why.

By the way do you know a good debugger for windows?

SDL-announce)"

Hmmm strange.

I’ve got a header named main.h in this header is a function:


/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

/* Videomodus setzen */
target = SDL_SetVideoMode(640, 480, 0, 0);
if (!target) {
fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,
SDL_GetError());
exit(2);
}

/* Netzwerkunterst?tzung aktivieren */
if(SDLNet_Init() < 0) {
fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
exit(3);
}
return 0;
}


It’s called in main() with “initgame(screen)”. If I use these funtion the
screen stays black, no bmp is drawed. If I don’t us the function and do
write the orders in the function directly to main() the bmp is drawed. I
can’t say why.

By the way do you know a good debugger for windows?

----- Original Message -----
Subject: Re: [SDL] BMP is not drawed
From: @sebastian_at_barfoot
Date: Thu, September 8, 2005 7:55 am
To: "A list for developers using the SDL library. (includes

Hmmm strange.

I’ve got a header named main.h in this header is a function:------------------------------------------------------------
/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

/* Videomodus setzen */
target = SDL_SetVideoMode(640, 480, 0, 0);
if (!target) {
fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,
SDL_GetError());
exit(2);
}

/* Netzwerkunterst?tzung aktivieren */
if(SDLNet_Init() < 0) {
fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
exit(3);
}
return 0;
}


It’s called in main() with “initgame(screen)”. If I use these funtion the
screen stays black, no bmp is drawed. If I don’t us the function and do
write the orders in the function directly to main() the bmp is drawed. I
can’t say why.

By the way do you know a good debugger for windows?

Well, this time I think I know the answer :).

the function should look like:

int initgame(SDL_Surface **target) // Notice de *pointer to pointer*

parametere!!!
(…)
*target = SDL_SetVideoMode(…); // the call to SDL_SetVideoMode
will look like this

otherwise, the pointer is not modified!

Hope this time is the right answer.++++++++++++++++++++++++++++++++

ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

-----Mensaje original-----
De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de
sebastian at barfoot.mine.nu
Enviado el: jueves, 08 de septiembre de 2005 7:55
Para: A list for developers using the SDL library. (includes SDL-announce)
Asunto: Re: [SDL] BMP is not drawed

Hmmm strange.

I’ve got a header named main.h in this header is a function:


/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

/* Videomodus setzen */
target = SDL_SetVideoMode(640, 480, 0, 0);
if (!target) {
fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,
SDL_GetError());
exit(2);
}

/* Netzwerkunterst?tzung aktivieren */
if(SDLNet_Init() < 0) {
fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
exit(3);
}
return 0;
}


It’s called in main() with “initgame(screen)”. If I use these funtion the
screen stays black, no bmp is drawed. If I don’t us the function and do
write the orders in the function directly to main() the bmp is drawed. I
can’t say why.

By the way do you know a good debugger for windows?


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

O Thursday 08 September 2005 07:55, vostede escribiu:

/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {

Try to change target type to a pointer to a pointer:
int initgame(SDL_Surface **target) {

? ?if (SDL_Init(SDL_INIT_VIDEO) < 0) {
? ? ? fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
? ? ? ? ? ? ? ? ? ? ? ?SDL_GetError());
? ? ? exit(1);
? ?}

? ?/* Videomodus setzen */
? ?target = SDL_SetVideoMode(640, 480, 0, 0);

? ?*target = SDL_SetVideoMode(640, 480, 0, 0);

? ?if (!target) {

? ?if (! *target) {> ? ? ? fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,

? ? ? ? ? ? ? ? ? ? ? ?SDL_GetError());
? ? ? exit(2);
? ?}

? ?/* Netzwerkunterst?tzung aktivieren */
? ?if(SDLNet_Init() < 0) {
? ? ? fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
? ? ? exit(3);
? ?}
? ?return 0;
}


La patria es dicha, dolor y cielo de todos y no feudo ni capellan?a de
nadie.
– Jos? Mart?.


I’d never join any club that would have the likes of me as a member.
– Groucho Marx
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20050908/f30279a3/attachment.pgp

Thanks :slight_smile: It works fine.>

Well, this time I think I know the answer :).

the function should look like:

int initgame(SDL_Surface **target) // Notice de pointer to pointer
parametere!!!
(…)
*target = SDL_SetVideoMode(…); // the call to SDL_SetVideoMode
will look like this

otherwise, the pointer is not modified!

Hope this time is the right answer.

++++++++++++++++++++++++++++++++
ALBERT FERNANDEZ MARSAL
CIRSA INTERACTIVE CORP. SL
Analista senior y programador
++++++++++++++++++++++++++++++++

-----Mensaje original-----
De: sdl-bounces+afmarsal=cirsa.com at libsdl.org
[mailto:sdl-bounces+afmarsal=cirsa.com at libsdl.org] En nombre de
@sebastian_at_barfoot
Enviado el: jueves, 08 de septiembre de 2005 7:55
Para: A list for developers using the SDL library. (includes SDL-announce)
Asunto: Re: [SDL] BMP is not drawed

Hmmm strange.

I’ve got a header named main.h in this header is a function:


/* Diese Funktion initalisiert SDL und setzte den Videomodus. */
int initgame(SDL_Surface *target) {
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
fprintf(stderr, “SDL konnte nicht initialisiert werden: %s\n”,
SDL_GetError());
exit(1);
}

/* Videomodus setzen */
target = SDL_SetVideoMode(640, 480, 0, 0);
if (!target) {
fprintf(stderr, “Konnte Bildschirmmodus nicht setzen: %s\n”,
SDL_GetError());
exit(2);
}

/* Netzwerkunterst?tzung aktivieren */
if(SDLNet_Init() < 0) {
fprintf(stderr, “Konnte Netzwerk nicht initialisieren: %s\n”,
SDLNet_GetError());
exit(3);
}
return 0;
}


It’s called in main() with “initgame(screen)”. If I use these funtion the
screen stays black, no bmp is drawed. If I don’t us the function and do
write the orders in the function directly to main() the bmp is drawed. I
can’t say why.

By the way do you know a good debugger for windows?


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


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