Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » video buffers not initialising properly for paging

This thread is locked; no one can reply to it. rss feed Print
video buffers not initialising properly for paging
Neil Walker
Member #210
April 2000
avatar

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.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Simon Parzer
Member #3,330
March 2003
avatar

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
Member #476
June 2000
avatar

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".

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Simon Parzer
Member #3,330
March 2003
avatar

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
Member #476
June 2000
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Simon Parzer
Member #3,330
March 2003
avatar

ok then

Neil Walker
Member #210
April 2000
avatar

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?

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Thomas Fjellstrom
Member #476
June 2000
avatar

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

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Neil Walker
Member #210
April 2000
avatar

[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 :)

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

ImLeftFooted
Member #3,935
October 2003
avatar

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
Member #210
April 2000
avatar

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.

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

ImLeftFooted
Member #3,935
October 2003
avatar

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

Neil Walker
Member #210
April 2000
avatar

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;

Neil.
MAME Cabinet Blog / AXL LIBRARY (a games framework) / AXL Documentation and Tutorial

wii:0356-1384-6687-2022, kart:3308-4806-6002. XBOX:chucklepie

Go to: