<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>mouse flickering: old question, vague answer</title>
		<link>http://www.allegro.cc/forums/view/557828</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Sun, 08 Jan 2006 07:10:10 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hi all,<br />I&#39;m using Dev-C++ and coding in C. </p><p>Like everyone else, I&#39;ve got mouse icon flickering issues when i&#39;m blitting my backbuffer to the screen every 50 ms. Its a simple game, so I don&#39;t really want to have a triple buffer going on here. I suppose DRS might work but that means I gotta blit every ms, which I&#39;m trying to avoid now (trying to inhibit blitting backbuffer to screen every 50ms or so only). I&#39;m working in a windowed mode game, and hardware mouse is enabled. The best I could get that removed flickering was this code:</p><p>    scare_mouse();<br />    show_mouse(buffer);<br />    blit(buffer, screen, 0, 0, 0, 0, buffer-&gt;w, buffer-&gt;h);    <br />    show_mouse(screen);<br />    unscare_mouse();</p><p>It works, but since I&#39;m only blitting every 50ms, i&#39;m getting shadows left behind from the recent blitting.</p><p>Any thoughts on this? Or does everyone just go the distance and let the computer blit buffers to the screen like crazy?</p><p>thanks<br />=Han=
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Fri, 06 Jan 2006 12:27:31 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why not just use<br />scare_mouse();<br />blit<br />unscare_mouse();</p><p>and never call show_mouse (so it always draw to the screen)</p><p>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Billybob)</author>
		<pubDate>Fri, 06 Jan 2006 12:35:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/scare_mouse" target="_blank"><span class="a">scare_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/show_mouse" target="_blank"><span class="a">show_mouse</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, buffer-&gt;w, buffer-&gt;h<span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/show_mouse" target="_blank"><span class="a">show_mouse</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a><span class="k2">)</span><span class="k2">;</span>
<a href="http://www.allegro.cc/manual/unscare_mouse" target="_blank"><span class="a">unscare_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
Hm, why would you call show_mouse on your buffer, and then again on the screen? thats going to come out very weird.  Take Williams advice.  And btw, using the hardware mouse means the OS handles the mouse drawing, not you.</p><p>Take out the line show_mouse(screen);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 06 Jan 2006 13:50:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
show_mouse(buffer);
</p></div></div><p>
Never, ever, use show_mouse() on a memory backbuffer. It doesn&#39;t make sense.<br />Just call show_mouse(screen) once and use scare_mouse()/unscare_mouse() (they do nothing if you&#39;re using a hardware cursor, but that&#39;s ok).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;m working in a windowed mode game, and hardware mouse is enabled.
</p></div></div><p>
Not if you&#39;re doing something other than show_mouse(screen).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 06 Jan 2006 14:50:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just use your own mouse bitmap.<br />assuming BITMAP *mouspr is the picture of your pointer<br />blit it as:
</p><div class="source-code snippet"><div class="inner"><pre><a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span> mouspr , buffer , <span class="n">0</span> , <span class="n">0</span> , <a href="http://www.allegro.cc/manual/mouse_x" target="_blank"><span class="a">mouse_x</span></a> , <a href="http://www.allegro.cc/manual/mouse_y" target="_blank"><span class="a">mouse_y</span></a> , mouspr <span class="k3">-</span><span class="k3">&gt;</span> w , mouspr <span class="k3">-</span><span class="k3">&gt;</span> h <span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>
You could add some X and Y to center the mouspr on the mouse coordinate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Fri, 06 Jan 2006 14:53:05 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Just use your own mouse bitmap.
</p></div></div><p>
That is sometimes a good idea, but Allegro&#39;s mouse API is there for a reason, you know?<br />Also, if you can get the OS to draw the mouse cursor for you (which you normally can at least in windowed mode) that is absolutely the best way to do it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 06 Jan 2006 15:02:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yeah. But the blit avoir flickering. All flickering. If there is still, it&#39;s vsync &amp; | refresh rate faults. GfxDriver parameters can be culprites too.<br />And a simple call to a simple blit is one line less than too show_mouse call ;-)<br />(for the last i&#39;m joking you know ;-p )
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (GullRaDriel)</author>
		<pubDate>Fri, 06 Jan 2006 15:08:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
But the blit avoir flickering. All flickering.
</p></div></div><p>
So should using a hardware cursur. At least, I never see severe mouse cursor flickering when a window (<i>any</i> window) is updated.<br />The blit also limits the update rate of the on-screen cursor to your current framerate, which is in general not good for various reasons. The mouse cursor is logically part of the input system, not the display.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 06 Jan 2006 15:39:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Well the reason I typed that convulted code (I chucked the double show_mouse in there coz a single wasnt helping). </p><p>Like i said earlier on, with my original show_mouse(screen) and only a</p><p>scare_mouse();<br />blit(buffer, screen, ...);<br />unscare_mouse();</p><p>to do any blitting, since I&#39;m doing this every 50ms (interrupt timer), it seems to cause my mouse to flicker. Anyway at the moment I&#39;m just doing a show_mouse(buffer) and doing a </p><p>while (something)   {<br />  show_mouse(NULL);<br />// game loop code in here<br />  show_mouse(buffer);<br />  blit(buffer, screen, ....);<br />}</p><p>Which means I&#39;m just gonna do a massive amount of buffer-&gt;screen blitting in my game. Is that what people normally do to avoid flickering mouse icons?</p><p>Btw, I read in another post that show_mouse(NULL) disingages the hardware mousedrawing. Is that true?</p><p>And I don&#39;t intend to write my own code to check mouse_x and y to handle my own mouse icon because the API is there, and its messy to clear my screen or backbuffer to reblit the icon and the image behind it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Fri, 06 Jan 2006 18:32:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
to do any blitting, since I&#39;m doing this every 50ms (interrupt timer), it seems to cause my mouse to flicker.
</p></div></div><p>
Are you sure the hardware mouse cursr is in use? Can you post a sample programme that reproduces the problem?<br />What happens if you remove the scare_mouse() and unscare_mouse() calls? (As said, they should do nothing for hardware cursors).</p><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Btw, I read in another post that show_mouse(NULL) disingages the hardware mousedrawing. Is that true?
</p></div></div><p>
It hides the mouse cursor, if that&#39;s what you mean.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Fri, 06 Jan 2006 18:52:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I tried this with a 15x15 cursor and it wasn&#39;t visible. So i used what i&#39;m using in my game: 75x75 cursor. And sure enough, flickering icon.</p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td><span class="p">#include &lt;allegro.h&gt;</span></td></tr><tr><td class="number">2</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>buffer<span class="k2">;</span></td></tr><tr><td class="number">3</td><td>    </td></tr><tr><td class="number">4</td><td><span class="k1">void</span> timer_routine <span class="k2">(</span><span class="k2">)</span>   <span class="k2">{</span></td></tr><tr><td class="number">5</td><td>        <a href="http://www.allegro.cc/manual/scare_mouse" target="_blank"><span class="a">scare_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">6</td><td>        <a href="http://www.allegro.cc/manual/blit" target="_blank"><span class="a">blit</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, buffer-&gt;w, buffer-&gt;h<span class="k2">)</span><span class="k2">;</span>    </td></tr><tr><td class="number">7</td><td>        <a href="http://www.allegro.cc/manual/unscare_mouse" target="_blank"><span class="a">unscare_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">8</td><td><span class="k2">}</span></td></tr><tr><td class="number">9</td><td>&#160;</td></tr><tr><td class="number">10</td><td><span class="k1">void</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span></td></tr><tr><td class="number">11</td><td>    <a href="http://www.allegro.cc/manual/allegro_init" target="_blank"><span class="a">allegro_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>    <a href="http://www.allegro.cc/manual/install_keyboard" target="_blank"><span class="a">install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>    <a href="http://www.allegro.cc/manual/install_timer" target="_blank"><span class="a">install_timer</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">14</td><td>    <a href="http://www.allegro.cc/manual/install_mouse" target="_blank"><span class="a">install_mouse</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">15</td><td>    </td></tr><tr><td class="number">16</td><td>    <a href="http://www.allegro.cc/manual/set_color_depth" target="_blank"><span class="a">set_color_depth</span></a><span class="k2">(</span><span class="n">24</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">17</td><td>    <a href="http://www.allegro.cc/manual/set_gfx_mode" target="_blank"><span class="a">set_gfx_mode</span></a><span class="k2">(</span>GFX_AUTODETECT_WINDOWED, <span class="n">640</span>, <span class="n">480</span>, <span class="n">0</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">18</td><td>    </td></tr><tr><td class="number">19</td><td>    buffer <span class="k3">=</span> <a href="http://www.allegro.cc/manual/create_bitmap" target="_blank"><span class="a">create_bitmap</span></a><span class="k2">(</span>screen-&gt;w, screen-&gt;h<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">20</td><td>    <a href="http://www.allegro.cc/manual/BITMAP" target="_blank"><span class="a">BITMAP</span></a> <span class="k3">*</span>cursor <span class="k3">=</span> <a href="http://www.allegro.cc/manual/load_bitmap" target="_blank"><span class="a">load_bitmap</span></a><span class="k2">(</span><span class="s">"cursor.bmp"</span>, NULL<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">21</td><td>    </td></tr><tr><td class="number">22</td><td>    <a href="http://www.allegro.cc/manual/clear_to_color" target="_blank"><span class="a">clear_to_color</span></a><span class="k2">(</span>buffer, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">200</span>, <span class="n">200</span>, <span class="n">255</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">23</td><td>    <a href="http://www.allegro.cc/manual/set_mouse_sprite" target="_blank"><span class="a">set_mouse_sprite</span></a><span class="k2">(</span>cursor<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">24</td><td>    <a href="http://www.allegro.cc/manual/set_mouse_sprite_focus" target="_blank"><span class="a">set_mouse_sprite_focus</span></a><span class="k2">(</span>cursor-&gt;w<span class="k3">/</span><span class="n">2</span>, cursor-&gt;h<span class="k3">/</span><span class="n">2</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">25</td><td>    <a href="http://www.allegro.cc/manual/show_mouse" target="_blank"><span class="a">show_mouse</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">26</td><td>    </td></tr><tr><td class="number">27</td><td>    <a href="http://www.allegro.cc/manual/install_int" target="_blank"><span class="a">install_int</span></a><span class="k2">(</span>timer_routine, <span class="n">50</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">28</td><td>    <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span><a href="http://www.allegro.cc/manual/key" target="_blank"><span class="a">key</span></a><span class="k2">[</span>KEY_ESC<span class="k2">]</span><span class="k2">)</span>    <span class="k2">{</span></td></tr><tr><td class="number">29</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">30</td><td>    </td></tr><tr><td class="number">31</td><td>    <a href="http://www.allegro.cc/manual/remove_int" target="_blank"><span class="a">remove_int</span></a><span class="k2">(</span>timer_routine<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">32</td><td>    <a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>buffer<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">33</td><td>    <a href="http://www.allegro.cc/manual/destroy_bitmap" target="_blank"><span class="a">destroy_bitmap</span></a><span class="k2">(</span>cursor<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">34</td><td>    <a href="http://www.allegro.cc/manual/allegro_exit" target="_blank"><span class="a">allegro_exit</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">35</td><td><span class="k2">}</span></td></tr><tr><td class="number">36</td><td><a href="http://www.allegro.cc/manual/END_OF_MAIN" target="_blank"><span class="a">END_OF_MAIN</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span></td></tr></tbody></table></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Fri, 06 Jan 2006 21:09:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
So i used what i&#39;m using in my game: 75x75 cursor.
</p></div></div><p>
When I tried last, Windows couldn&#39;t do more than 32x32 pixel cursors. In that case, Allegro is not using a hardware cursor (and gfx_capabilities should tell you so).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sat, 07 Jan 2006 00:42:40 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ah... nowonder. So without hardware cursoring, I&#39;m stuck with a flickering icon unless I do something else. Thanks! I&#39;ve worked around it by show_mouse(buffer) and blitting buffer to screen every game loop. Not very resource-friendly I guess, but it works.</p><p>=Han=
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Sat, 07 Jan 2006 12:59:32 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
I&#39;ve worked around it by show_mouse(buffer) and blitting buffer to screen every game loop.
</p></div></div><p>
Don&#39;t. I recommend against using show_mouse() on a memory bitmap. If that&#39;s what you want to do, then draw the mouse pointer manually with trans_blit().<br />Also, it&#39;s best to check if you can do a hardware cursor and only draw the mouse yourself if you cannot.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sat, 07 Jan 2006 15:35:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why shouldn&#39;t I use show_mouse(buffer)? What is the badness of doing it on a memory bitmap? Sorry I think I read it somewhere but forgot where, and its not in the manual.</p><p>I guess the reason I don&#39;t want to draw my mouse on my buffer is that it will draw over something on my buffer that I don&#39;t want overwritten or it will take some re-coding to figure out how to redraw the thing behind it. maybe dirty rectangles. But I thought this show_mouse(buffer) thing seemed to solve all my problems. Thats why I would like to know what so bad about it.</p><p>Thanks<br />=Han=
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Sat, 07 Jan 2006 21:52:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Threading issues, and there are some things that don&#39;t actually work properly (but I need to look up the discussion on AD to tell you what exactly gets broken under what circumstances).<br />The end of the discussion was that it&#39;s pointless to do continuus asynchronous updates of the mouse cursor on a non-visible surface (which is quite true if you think about it) and that for that reason it doesn&#39;t make sense to do it. I think the idea was also to discourage doing this and drop active support in the 4.3 branch.<br />But I may be remembering more than was actually discussed at the time.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 08 Jan 2006 01:46:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Ooo.. ok. That makes perfect sense. I&#39;ll keep that in mind and do a dirty rectangle then. Peace out.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ju-Han Soon)</author>
		<pubDate>Sun, 08 Jan 2006 07:10:10 +0000</pubDate>
	</item>
</rss>
