<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>video buffers not initialising properly for paging</title>
		<link>http://www.allegro.cc/forums/view/588789</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 01 Dec 2006 14:53:39 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,<br />I&#39;m sure this&#39;ll become obvious after some sleep but I&#39;ve noticed a problem with video paging/triple buffering in my code.</p><p>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:</p><div class="source-code snippet"><div class="inner"><pre>draw<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span> <span class="c">//draws to the 'DrawingSurface' which is BitmapPages[0] first run</span>
<a href="http://www.allegro.cc/manual/show_video_bitmap" target="_blank"><span class="a">show_video_bitmap</span></a><span class="k2">(</span>BitmapPages<span class="k2">[</span>BitmapPagesActive<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
BitmapPagesActive<span class="k3">=</span><span class="n">1</span><span class="k3">-</span>BitmapPagesActive<span class="k2">;</span>
DrawingSurface<span class="k3">=</span>BitmapPages<span class="k2">[</span>BitmapPagesActive<span class="k2">]</span><span class="k2">;</span>
</pre></div></div><p>

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.</p><p>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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 29 Nov 2006 06:36:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AFAIK the first video bitmap allocated is in the same memory area as the screen memory.</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> video <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>,<a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a>,...<span class="k2">)</span><span class="k2">;</span> <span class="c">// This is gonna be screen memory</span>
<a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a><span class="k3">*</span> real_video01 <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span>...<span class="k2">)</span><span class="k2">;</span>
.....
<a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>video<span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Simon Parzer)</author>
		<pubDate>Wed, 29 Nov 2006 15:11:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
BITMAP* video = create_video_bitmap(SCREEN_W,SCREEN_H,...); // This is gonna be screen memory<br />BITMAP* real_video01 = create_video_bitmap(...);<br />.....<br />destroy_bitmap(video);
</p></div></div><p>Why the hell would you do that?</p><p>Just use the video and video1 pointers after and forget about &quot;screen&quot;.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 29 Nov 2006 15:13:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Why the hell would you do that?</p><p>Just use the video and video1 pointers after and forget about &quot;screen&quot;.
</p></div></div><p>

Memory leak? dunno..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Simon Parzer)</author>
		<pubDate>Wed, 29 Nov 2006 15:16:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Not a leak. screen is taken care of by allegro, and you free video and video1 when you&#39;re done with them.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 29 Nov 2006 15:17:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>ok then
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Simon Parzer)</author>
		<pubDate>Wed, 29 Nov 2006 16:40:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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:</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>video_page<span class="k2">[</span><span class="n">2</span><span class="k2">]</span><span class="k2">;</span>
      video_page<span class="k2">[</span><span class="n">0</span><span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span>
      video_page<span class="k2">[</span><span class="n">1</span><span class="k2">]</span> <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_video_bitmap" target="_blank"><span class="a">create_video_bitmap</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/SCREEN_W" target="_blank"><span class="a">SCREEN_W</span></a>, <a href="http://www.allegro.cc/manual/SCREEN_H" target="_blank"><span class="a">SCREEN_H</span></a><span class="k2">)</span><span class="k2">;</span>
      current_page <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
      ...
      draw_screen<span class="k2">(</span>video_page<span class="k2">[</span>current_page<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
      <a href="http://www.allegro.cc/manual/show_video_bitmap" target="_blank"><span class="a">show_video_bitmap</span></a><span class="k2">(</span>video_page<span class="k2">[</span>current_page<span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
      current_page <span class="k3">=</span> <span class="k2">(</span>current_page<span class="k3">+</span><span class="n">1</span><span class="k2">)</span>%<span class="n">2</span><span class="k2">;</span>
</pre></div></div><p>

Following that, the same is happening with triple buffering, should I carry on the same principle and start using page 2?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Wed, 29 Nov 2006 18:31:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Pretty much I think. the first fullscreen sized page takes the space the visible screen did. and I believe its in the docs somewhere.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Wed, 29 Nov 2006 18:35:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[edit]That did the trick, I vote the manual should be updated <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /></p><p>Thanks both of you.</p><p>[OLD]<br />Well my code snippet was from here<br /><a href="http://allegro.cc/manual/api/graphics-modes/show_video_bitmap">http://allegro.cc/manual/api/graphics-modes/show_video_bitmap</a></p><p>and</p><p><a href="http://allegro.cc/manual/api/graphics-modes/request_video_bitmap">http://allegro.cc/manual/api/graphics-modes/request_video_bitmap</a></p><p>I&#39;ll give my code a try later as it&#39;s just a config change to swap between double/paging/triple. I&#39;m also getting a bizarre problem with the allegro trans blender doing the wrong thing at certain alpha levels with paging/triple, but that&#39;s another thing for me check once I try out the above <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 30 Nov 2006 06:03:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>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?</p><p>IIRC its in the create_video_bitmap docs.  Maybe show_video_bitmap and request_video_bitmap should also mention this fact.</p><p>[edit]
</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m also getting a bizarre problem with the allegro trans blender doing the wrong thing at certain alpha levels with paging/triple
</p></div></div><p>
While I don&#39;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).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 30 Nov 2006 07:17:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>So that&#39;s why my fades seem better in double buffer mode <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" /> I need to re-test my code using fblend, maybe that&#39;ll look better given it&#39;s slightly faster.</p><p>As for the manual, I know it&#39;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.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Thu, 30 Nov 2006 17:55:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah yes, that example should definitely be changed, that makes sense.  I&#39;ll make a post on AD
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 01 Dec 2006 07:25:47 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>According to another thread I already started, to branch this finding, evert mentioned you can&#39;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.</p><p>video paging:
</p><div class="source-code snippet"><div class="inner"><pre>        clear<span class="k2">(</span>BitmapPages<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
        <a href="http://www.allegro.cc/manual/show_video_bitmap" target="_blank"><span class="a">show_video_bitmap</span></a><span class="k2">(</span>BitmapPages<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
  activePage<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>
</pre></div></div><p>

triple buffers:
</p><div class="source-code snippet"><div class="inner"><pre>        clear<span class="k2">(</span>BitmapPages<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
  <span class="k1">do</span><span class="k2">{</span><span class="k2">}</span><span class="k1">while</span><span class="k2">(</span><a href="http://www.allegro.cc/manual/poll_scroll" target="_blank"><span class="a">poll_scroll</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
  <a href="http://www.allegro.cc/manual/request_video_bitmap" target="_blank"><span class="a">request_video_bitmap</span></a><span class="k2">(</span>BitmapPages<span class="k2">[</span><span class="n">1</span><span class="k2">]</span><span class="k2">)</span><span class="k2">;</span>
  activePage<span class="k3">=</span><span class="n">0</span><span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Neil Walker)</author>
		<pubDate>Fri, 01 Dec 2006 14:53:39 +0000</pubDate>
	</item>
</rss>
