NewSDLprogrammer

Hello,

I’ve been trying to modify existing SDL programs to learn as much as I can. I have currently succeeded in using a program that moves a bmp using the arrow keys and using the mouse. But, whenever the bmp is moved to the right or down, it doesn’t erase the old bmp position. It does when it goes to the left and up. I have provided some code that I suspect is where the prob may be. Can anyone help me on this?

void updateScene(int newx, int newy) {
/* since we’re updating multiple areas,
we store all rectangles in an array */
SDL_Rect rects[2];
SDL_Rect r;
/
this rectangle contains the old cursor image /
r = &(rects[0]);
r->x = x;
r->y = y;
//r->w = cursor->w;
//r->h = cursor->h;
/
overwrite old cursor image with background /
SDL_BlitSurface(background, r, screen, r);
/
this rectangle contains the new cursor image /
r = &(rects[1]);
r->x = newx;
r->y = newy;
//r->w = cursor->w;
//r->h = cursor->h;
/
draw new cursor /
SDL_BlitSurface(cursor, NULL, screen, r);
/
make sure screen is updated /
SDL_UpdateRects(screen, 2, rects);
/
store the new cursor coordinates */
x = newx;
y = newy;

//

SDL_Event event;
while(SDL_WaitEvent(&event)) {
keys=SDL_GetKeyState(NULL);
if(keys[SDLK_UP]){y -=1;}
if(keys[SDLK_DOWN]){y +=1;}
if(keys[SDLK_LEFT]){x -=1;}
if(keys[SDLK_RIGHT]){x +=1;}
drawScene();
//convertImages();
updateScene(x,y);

Also, theres a function called SDL_WarpCursor. I couldn’t find this in the SDL guide. What does it do exactly and why isn’t it in the guide?

Thanks!

Richard---------------------------------
Do You Yahoo!?
Yahoo! Sports - live college hoops coverage

All public functions are described in the SDL reference of the sdldoc project:
http://sdldoc.csn.ul.ie/
http://sdldoc.sf.net/

http://sdldoc.csn.ul.ie/sdlwarpmouse.phpOn Tuesday 19 March 2002 18:01, Richard Perrine wrote:

Also, theres a function called SDL_WarpCursor. I couldn’t find this in the
SDL guide. What does it do exactly and why isn’t it in the guide?


Johannes Schmidt

< http://libufo.sourceforge.net > Your widget set for OpenGL

Hello,

I’ve been trying to modify existing SDL programs to learn as much as I can. I have currently succeeded in using a program that moves a bmp using the arrow keys and using the mouse. But, whenever the bmp is moved to the right or down, it doesn’t erase the old bmp position. It does when it goes to the left and up. I have provided some code that I suspect is where the prob may be. Can anyone help me on this?

void updateScene(int newx, int newy) {
/* since we’re updating multiple areas,
we store all rectangles in an array */
SDL_Rect rects[2];
SDL_Rect r;
/
this rectangle contains the old cursor image */
r = &(rects[0]);
r->x = x;
r->y = y;
//r->w = cursor->w;
//r->h = cursor->h;

You should uncomment these. Otherwise, they could be any value, and you therefore don’t know how much of an area the blit below is going to draw.

/* overwrite old cursor image with background */
SDL_BlitSurface(background, r, screen, r);
/* this rectangle contains the new cursor image */
r = &(rects[1]);
r->x = newx;
r->y = newy;
//r->w = cursor->w;
//r->h = cursor->h;
/* draw new cursor */
SDL_BlitSurface(cursor, NULL, screen, r);
/* make sure screen is updated */
SDL_UpdateRects(screen, 2, rects);
/* store the new cursor coordinates */
x = newx;
y = newy;

//

SDL_Event event;
while(SDL_WaitEvent(&event)) {
keys=SDL_GetKeyState(NULL);
if(keys[SDLK_UP]){y -=1;}
if(keys[SDLK_DOWN]){y +=1;}
if(keys[SDLK_LEFT]){x -=1;}
if(keys[SDLK_RIGHT]){x +=1;}
drawScene();
//convertImages();
updateScene(x,y);

Also, theres a function called SDL_WarpCursor. I couldn’t find this in the SDL guide. What does it do exactly and why isn’t it in the guide?

Thanks!

Richard----- Original Message -----
From: Richard Perrine
To: SDLgroup
Sent: Tuesday, March 19, 2002 12:01 PM
Subject: [SDL] NewSDLprogrammer


Do You Yahoo!?
Yahoo! Sports - live college hoops coverage

[…]

//r->w = cursor->w;
//r->h = cursor->h;

You should uncomment these. Otherwise, they could be any value, and
you therefore don’t know how much of an area the blit below is going to
draw.

from ‘man SDL_BlitSurface’:

"Only the position is used in the dstrect (the width and height are
 ignored)."

and

"The final blit rectangle is saved in dstrect after all clipping is
 performed (srcrect is not modified)."

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Tuesday 19 March 2002 18:45, Jason Hoffoss wrote:

[…]

//r->w = cursor->w;
//r->h = cursor->h;

You should uncomment these. Otherwise, they could be any value, and
you therefore don’t know how much of an area the blit below is going to
draw.

from ‘man SDL_BlitSurface’:

“Only the position is used in the dstrect (the width and height are
ignored).”

and

“The final blit rectangle is saved in dstrect after all clipping is
performed (srcrect is not modified).”

Yes, but look at his code again. He’s using the same rect pointer for both
src and dest, and it is used in the src.

-Jason

----- Original Message -----
From: david.olofson@reologica.se (David Olofson)
To:
Sent: Tuesday, March 19, 2002 1:07 PM
Subject: Re: [SDL] NewSDLprogrammer
On Tuesday 19 March 2002 18:45, Jason Hoffoss wrote:

[…]

//r->w = cursor->w;
//r->h = cursor->h;

[…]

“Only the position is used in the dstrect (the width and height are
ignored).”
[…]
Yes, but look at his code again. He’s using the same rect pointer for
both src and dest, and it is used in the src.

Right - I didn’t look carefully enough at the first blit… Sorry.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |-------------------------------------> http://olofson.net -'On Tuesday 19 March 2002 19:46, Jason Hoffoss wrote: