video buffers not initialising properly for paging
Neil Walker

Hello,
I'm sure this'll become obvious after some sleep but I've noticed a problem with video paging/triple buffering in my code.

Basically, I draw to my active video back buffer then invoke the video paging code (BitmapPages is an array of two video bitmaps), as below:

draw(); //draws to the 'DrawingSurface' which is BitmapPages[0] first run
show_video_bitmap(BitmapPages[BitmapPagesActive]);
BitmapPagesActive=1-BitmapPagesActive;
DrawingSurface=BitmapPages[BitmapPagesActive];

But the first time I call draw() and draw to DrawingSurface (which is bitmappages[0] first time) it is drawing to the screen and not the video buffer but then subsequently is ok.

I guess the daft thing to rule out is will my BitmapPages[0] ever be the screen, and if so how do I avoid this.

Simon Parzer

AFAIK the first video bitmap allocated is in the same memory area as the screen memory.

BITMAP* video = create_video_bitmap(SCREEN_W,SCREEN_H,...); // This is gonna be screen memory
BITMAP* real_video01 = create_video_bitmap(...);
.....
destroy_bitmap(video);

Thomas Fjellstrom
Quote:

BITMAP* video = create_video_bitmap(SCREEN_W,SCREEN_H,...); // This is gonna be screen memory
BITMAP* real_video01 = create_video_bitmap(...);
.....
destroy_bitmap(video);

Why the hell would you do that?

Just use the video and video1 pointers after and forget about "screen".

Simon Parzer
Quote:

Why the hell would you do that?

Just use the video and video1 pointers after and forget about "screen".

Memory leak? dunno..

Thomas Fjellstrom

Not a leak. screen is taken care of by allegro, and you free video and video1 when you're done with them.

Simon Parzer

ok then

Neil Walker

Are you sure? If so, are you re saying when I create page1, page2 video bitmaps I should initially set my drawing buffer pointer to page2? perhaps someone could take a note to update the documentation as below from the manual is using video page 0 first:

BITMAP *video_page[2];
      video_page[0] = create_video_bitmap(SCREEN_W, SCREEN_H);
      video_page[1] = create_video_bitmap(SCREEN_W, SCREEN_H);
      current_page = 0;
      ...
      draw_screen(video_page[current_page]);
      show_video_bitmap(video_page[current_page]);
      current_page = (current_page+1)%2;

Following that, the same is happening with triple buffering, should I carry on the same principle and start using page 2?

Thomas Fjellstrom

Pretty much I think. the first fullscreen sized page takes the space the visible screen did. and I believe its in the docs somewhere.

Neil Walker

[edit]That did the trick, I vote the manual should be updated :)

Thanks both of you.

[OLD]
Well my code snippet was from here
http://allegro.cc/manual/api/graphics-modes/show_video_bitmap

and

http://allegro.cc/manual/api/graphics-modes/request_video_bitmap

I'll give my code a try later as it's just a config change to swap between double/paging/triple. I'm also getting a bizarre problem with the allegro trans blender doing the wrong thing at certain alpha levels with paging/triple, but that's another thing for me check once I try out the above :)

Dustin Dettmer

The docs mention that the first video bitmap is actually the screen. Maybe it should be said in more places so it is easily found?

IIRC its in the create_video_bitmap docs. Maybe show_video_bitmap and request_video_bitmap should also mention this fact.

[edit]

Quote:

I'm also getting a bizarre problem with the allegro trans blender doing the wrong thing at certain alpha levels with paging/triple

While I don't have an answer for that effect, generally doing transparency or alpha blending is a bad idea for anything but a double buffer setup. Reading from the video memory is generally considered a bad idea (which alpha / trans must do).

Neil Walker

So that's why my fades seem better in double buffer mode :) I need to re-test my code using fblend, maybe that'll look better given it's slightly faster.

As for the manual, I know it's mentioned, in places, but if people are copying the example code like I did they should change the starting buffer from the 0 index to the 1 index buffer created.

Dustin Dettmer

Ah yes, that example should definitely be changed, that makes sense. I'll make a post on AD

Neil Walker

According to another thread I already started, to branch this finding, evert mentioned you can't guarantee this either. The only way is to draw to a buffer so you know which one is active. I changed my code to this, which now works a treat.

video paging:

        clear(BitmapPages[1]);
        show_video_bitmap(BitmapPages[1]);
  activePage=0;

triple buffers:

        clear(BitmapPages[1]);
  do{}while(poll_scroll());
  request_video_bitmap(BitmapPages[1]);
  activePage=0;

Thread #588789. Printed from Allegro.cc