draw_sprite failure
Neil Walker

For the same image, if I draw_sprite, stretch_sprite, masked_blit or blit a bitmap onto the drawing buffer (whether it is a memory or a video or system bitmap) it is fine. However, if the image is a sub-bitmap of a system or video bitmap it doesn't show the correct image. This is literally my code, after each loop 'graphic' points to the next graphic in the list.

blit(graphic,Buffer,0,0,270,270,w,h);
stretch_sprite(Buffer, graphic, 100,240,w*2,h*2);
draw_sprite(Buffer, graphic,570,270);
masked_blit(graphic,Buffer,0,0,670,270,w,h);

As mentioned above, draw_sprite() fails if it is a sub-bitmap of a video or system, but works fine for any other type.

What seems to be happening is every time it is called, stretch_sprite/blit/masked is showing the correct bitmap but draw_sprite is showing the one after next image (or a completely black image for one graphic and if I change graphic it is completely white!). This is when y=0 on the master image, if y is not 0 then it seems to double it's start position.

ReyBrujo

Can you post the minimun code, and the bitmaps you use, to reproduce this?

Neil Walker

I'll have to redo things as it's all part of a large bit of code to create sub-bitmaps, etc, so it will be tomorrow the earliest. I've just editted my post to say GFX_HW_VRAM_BLIT_MASKED is set ok, btw.

Looking at the source code, draw_sprite is calling masked_blit with a bit of coding first to get the offsets. As a side issue, I guess this means masked_blit is faster than draw_sprite?

Anyway, I'm off to bed now, but there must be something wrong with this bit of code within draw_sprite when the video/system bitmap is a sub-bitmap? If it helps the images in my bitmap are on the same y-position just are one after the other in the x, as attached bitmap.

1 if (is_video_bitmap(sprite) || is_system_bitmap(sprite)) {
2 sx = sprite->x_ofs;
3 sy = sprite->y_ofs;
4 w = sprite->w;
5 h = sprite->h;
6 
7 if (bmp->clip) {
8 if (x < bmp->cl) {
9 sx += bmp->cl - x;
10 w -= bmp->cl - x;
11 x = bmp->cl;
12 }
13 
14 if (y < bmp->ct) {
15 sy += bmp->ct - y;
16 h -= bmp->ct - y;
17 y = bmp->ct;
18 }
19 
20 if (x + w > bmp->cr)
21 w = bmp->cr - x;
22 
23 if (w <= 0)
24 return;
25 
26 if (y + h > bmp->cb)
27 h = bmp->cb - y;
28 
29 if (h <= 0)
30 return;
31 }

After this it calls masked_blit.

[edit]
If you look at my attached image, when I show the first image (the alien) it jumps by two, if I show my second image (fuel) it actually shows the wavy black line below it!

Thread #558393. Printed from Allegro.cc