<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[A5]</title>
		<link>http://www.allegro.cc/forums/view/606128</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 20 Jan 2011 18:24:00 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m having trouble with testing on Ubuntu inside a virtual machine and I am trying to figure out if the problem is with my VM setup or something else.  I am running Ubuntu 10.10 with Allegro 5.0 installed from SVN.</p><p>Whenever I try to run the program here is what is reported in the terminal window:</p><p>failed to create drawable<br />X Error of failed request:  BadDrawable (invalid Pixmap or Window parameter)<br />  Major opcode of failed request:  55 (X_CreateGC)<br />  Resource id in failed request:  0x4400002<br />  Serial number of failed request:  25<br />  Current serial number in output stream:  27</p><p>As of right now I&#39;m only setting a display and drawing a test image to it.  I see that the linux install has the allegro_main library, so does that mean I need to use END_OF_MAIN()?  I had thought this was only needed on OSX.</p><p>Here is the source code:</p><div class="source-code"><div class="toolbar"><span class="button numbers"><b>#</b></span><span class="button select">Select</span><span class="button expand">Expand</span></div><div class="inner"><span class="number">  1</span><span class="p">#include &lt;stdio.h&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;allegro5/allegro.h&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;allegro5/allegro_image.h&gt;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="k1">int</span> main<span class="k2">(</span><span class="k1">int</span> argc, <span class="k1">char</span> <span class="k3">*</span>argv<span class="k2">[</span><span class="k2">]</span><span class="k2">)</span>
<span class="number">  6</span><span class="k2">{</span>
<span class="number">  7</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_DISPLAY"><span class="a">ALLEGRO_DISPLAY</span></a> <span class="k3">*</span>scr<span class="k2">;</span>
<span class="number">  8</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_BITMAP"><span class="a">ALLEGRO_BITMAP</span></a> <span class="k3">*</span>bmp<span class="k2">;</span>
<span class="number">  9</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT_QUEUE"><span class="a">ALLEGRO_EVENT_QUEUE</span></a> <span class="k3">*</span>eventQueue<span class="k2">;</span>
<span class="number"> 10</span>    <a href="http://www.allegro.cc/manual/ALLEGRO_EVENT"><span class="a">ALLEGRO_EVENT</span></a> retEvent<span class="k2">;</span>
<span class="number"> 11</span>    <span class="k1">bool</span> exitFlag <span class="k3">=</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>    <a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span>    <a href="http://www.allegro.cc/manual/al_init_image_addon"><span class="a">al_init_image_addon</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span>    <a href="http://www.allegro.cc/manual/al_install_keyboard"><span class="a">al_install_keyboard</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 16</span>    eventQueue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_event_queue"><span class="a">al_create_event_queue</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 17</span>    <a href="http://www.allegro.cc/manual/al_register_event_source"><span class="a">al_register_event_source</span></a><span class="k2">(</span>eventQueue, <a href="http://www.allegro.cc/manual/al_get_keyboard_event_source"><span class="a">al_get_keyboard_event_source</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>    scr <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_create_display"><span class="a">al_create_display</span></a><span class="k2">(</span><span class="n">800</span>,<span class="n">600</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 19</span>    <span class="k1">if</span> <span class="k2">(</span>scr<span class="k3">=</span><span class="k3">=</span>NULL<span class="k2">)</span>
<span class="number"> 20</span>    <span class="k2">{</span>
<span class="number"> 21</span>        <a href="http://www.delorie.com/djgpp/doc/libc/libc_624.html" target="_blank">printf</a><span class="k2">(</span><span class="s">"Could not create display at 800x600"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 22</span>        <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span>
<span class="number"> 23</span>    <span class="k2">}</span>
<span class="number"> 24</span>    <a href="http://www.allegro.cc/manual/al_clear_to_color"><span class="a">al_clear_to_color</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span><span class="n">0</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 25</span>    bmp <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_load_bitmap"><span class="a">al_load_bitmap</span></a><span class="k2">(</span><span class="s">"test.jpg"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 26</span>    <span class="k1">if</span> <span class="k2">(</span>bmp<span class="k3">!</span><span class="k3">=</span>NULL<span class="k2">)</span>
<span class="number"> 27</span>        <a href="http://www.allegro.cc/manual/al_draw_scaled_bitmap"><span class="a">al_draw_scaled_bitmap</span></a><span class="k2">(</span>bmp, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_width"><span class="a">al_get_bitmap_width</span></a><span class="k2">(</span>bmp<span class="k2">)</span>, <a href="http://www.allegro.cc/manual/al_get_bitmap_height"><span class="a">al_get_bitmap_height</span></a><span class="k2">(</span>bmp<span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">800</span>, <span class="n">600</span>, <span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 28</span>    <span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>exitFlag<span class="k2">)</span>
<span class="number"> 29</span>    <span class="k2">{</span>
<span class="number"> 30</span>        <a href="http://www.allegro.cc/manual/al_flip_display"><span class="a">al_flip_display</span></a><span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 31</span>        <span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>al_event_queue_is_empty<span class="k2">(</span>eventQueue<span class="k2">)</span><span class="k2">)</span>
<span class="number"> 32</span>        <span class="k2">{</span>
<span class="number"> 33</span>            <a href="http://www.allegro.cc/manual/al_get_next_event"><span class="a">al_get_next_event</span></a><span class="k2">(</span>eventQueue, <span class="k3">&amp;</span>retEvent<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 34</span>            <span class="k1">if</span> <span class="k2">(</span>retEvent.type <span class="k3">=</span><span class="k3">=</span> ALLEGRO_EVENT_KEY_CHAR<span class="k2">)</span>
<span class="number"> 35</span>            <span class="k2">{</span>
<span class="number"> 36</span>                <span class="k1">if</span> <span class="k2">(</span>retEvent.keyboard.keycode <span class="k3">=</span><span class="k3">=</span> ALLEGRO_KEY_ESCAPE<span class="k2">)</span>
<span class="number"> 37</span>                    exitFlag <span class="k3">=</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 38</span>            <span class="k2">}</span>
<span class="number"> 39</span>        <span class="k2">}</span>
<span class="number"> 40</span>    <span class="k2">}</span>
<span class="number"> 41</span><span class="k2">}</span>
</div></div><p>

Is this just because I&#39;m running inside a VM?</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Thu, 20 Jan 2011 02:10:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Its most likely because you&#39;re running inside a VM. See if you can&#39;t setup OpenGL pass-through for your VM, as Allegro 5 has a hard dependency on OpenGL. It will not work without it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 20 Jan 2011 02:14:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606128/899497#target">wiseguy</a> said:</div><div class="quote"><p>I see that the linux install has the allegro_main library, so does that mean I need to use END_OF_MAIN()?  I had thought this was only needed on OSX.</p></div></div><p>
You never need END_OF_MAIN(). Allegro 5&#39;s magic main doesn&#39;t need it.<br />Yes, it&#39;s only needed on OS X, so on Linux allegro_main does nothing. I tend to link it in blindly, which means I can use the same build script on Linux as on OS X, which is nice (not essential though).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 20 Jan 2011 02:40:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thanks for the responses.  My test program works fine on my kids&#39; PC which is also running Ubuntu 10.10, so the problem has to be the virtual machine.  I&#39;ve been trying to figure out the opengl passthrough but so far VMWare seems to only support that for Windows guests.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Thu, 20 Jan 2011 03:00:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606128/899501#target">Evert</a> said:</div><div class="quote"><p>You never need END_OF_MAIN() [...] Yes, it&#39;s only needed on OS X</p></div></div><p>

<img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Thu, 20 Jan 2011 03:57:08 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Apparently, &quot;You&quot; meant WiseGuy.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Thu, 20 Jan 2011 03:58:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>END_OF_MAIN is never needed or is even valid. liballegro_main is only needed on OSX.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Fjellstrom)</author>
		<pubDate>Thu, 20 Jan 2011 03:58:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p></div></div><p>
Linking with allegro_main.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 20 Jan 2011 05:27:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Why <i>is</i> allegro_main required at all, anyway?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (X-G)</author>
		<pubDate>Thu, 20 Jan 2011 13:40:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I have since installed Linux as my main OS, so the above question no longer holds.  The intersting thing will be if I decide to install windows on this host as a VM and cross compile my sources.  Too bad I can&#39;t test it out on Mac OSX inside a VM.</p><p>WG
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (wiseguy)</author>
		<pubDate>Thu, 20 Jan 2011 16:42:02 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606128/899537#target">X-G</a> said:</div><div class="quote"><p>Why is allegro_main required at all, anyway?</p></div></div><p>
The message loop that gets messages from the OS needs to run from the main thread, meaning al_init() cannot return to the caller if we want to receive messages from the OS (which we obviously do). The easiest thing to do is to have our own main() function and call the user main from a separate thread.</p><p>If there&#39;s a way around that, I&#39;m sure we&#39;re all glad to hear it. SDL does (or at least did) more or less the same thing though, which suggests that there isn&#39;t.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Thu, 20 Jan 2011 18:02:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://www.allegro.cc/forums/thread/606128/899537#target">X-G</a> said:</div><div class="quote"><p>Why is allegro_main required at all, anyway?</p></div></div><p>

It only has any purpose under OSX - for Windows and Linux it&#39;s a completely empty library as far as I know. In OSX, allegro_main.dylib basically looks like this:</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <span class="k2">[</span><span class="k2">[</span><span class="k2">[</span>NSApplication alloc<span class="k2">]</span>init<span class="k2">]</span>run<span class="k2">]</span><span class="k2">;</span>
<span class="k2">}</span>

<span class="k3">-</span>OnAppLaunched <span class="k2">{</span>
    pthreads_run<span class="k2">(</span>user_main<span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>

That way an Allegro app is a normal Cocoa App, with objective C stuff and doing all events handling in the main thread (it seems it&#39;s not even possible to do things in any other way). It leaves no room for a C-style main() function in user code, so we fake that by having a &quot;#define main user_main&quot; in allegro.h and starting a separate thread when the Cocoa app is launched which runs that user_main.</p><p>Now, why did we put this in a separate allegro_main.dylib and not into the main allegro.dylib? The reason is that sometimes you can&#39;t rename the main() function. E.g. when you don&#39;t use C/C++ and therefore never include allegro.h. In such cases you would still use allegro.dylib (which does not have any main() function in it) and exclude allegro_main.dylib. Then from your real main you do whatever is needed and then use <span class="source-code"><a href="http://www.allegro.cc/manual/al_run_main"><span class="a">al_run_main</span></a></span> to run the user code. (The Python wrapper does this for example.)
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Elias)</author>
		<pubDate>Thu, 20 Jan 2011 18:24:00 +0000</pubDate>
	</item>
</rss>
