<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Making color variables</title>
		<link>http://www.allegro.cc/forums/view/613043</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Tue, 30 Jul 2013 02:39:05 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I know to make the variable itself is something like this </p><p><span class="source-code"><a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> red <span class="k3">=</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">255</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span></span></p><p>but I notice if I put that line at the top the color will not appear to something in drawing in the game loop.  Also, when i move that line right above the gameloop it works.  </p><p>I am wondering if I can make the above line a global variable because im using it all over the place </p><p>I did try making a separate header and putting that above line in it and trying to call it in the main function but it didnt appear. Also, putting it outside above the main function didnt work either.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (imgregduh)</author>
		<pubDate>Mon, 29 Jul 2013 03:52:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>This the general idea:
</p><div class="source-code snippet"><div class="inner"><pre><span class="c">/* define it outside of any function */</span>
<span class="k1">static</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> red<span class="k2">;</span>

<span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span> <span class="k2">{</span>
    <span class="c">/* initialize before first use (and after calling al_init()) */</span>
    red <span class="k3">=</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">255</span>,<span class="n">0</span>,<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="k2">}</span>
</pre></div></div><p>
You might want to give it a name that isn&#39;t tied to the color though, like &quot;line_color&quot; or &quot;rocket_color&quot;. But it depends on how you use it.</p><p>If you want it to be available to more than just a single file, remove &quot;static&quot; from the definition and put <span class="source-code"><span class="k1">extern</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> red<span class="k2">;</span></span> in some header file that you then include where you want to use the symbol.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Mon, 29 Jul 2013 04:34:16 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You can&#39;t call Allegro functions before initializing the library, which happens after main() is run, so any lines like that cannot be made global.  You can make the variable global and have a function that runs after you initialize Allegro that contains color assignments.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Mon, 29 Jul 2013 04:36:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Allegro functions must run after you call <span class="source-code"><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a></span>, so that precludes initializing them globally. You could make the variable global and initialize it after <span class="source-code"><a href="http://www.allegro.cc/manual/al_init"><span class="a">al_init</span></a></span> though.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 29 Jul 2013 04:38:33 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s also <span class="source-code"><a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"red"</span><span class="k2">)</span></span> using the <a href="http://en.wikipedia.org/wiki/X11_color_names">x11 color names</a>.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 29 Jul 2013 05:12:52 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Alright, thanks guys for the info
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (imgregduh)</author>
		<pubDate>Mon, 29 Jul 2013 05:22:32 +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/613043/988037#target">LennyLen</a> said:</div><div class="quote"><p>You can&#39;t call Allegro functions before initializing the library, which happens after main() is run, so any lines like that cannot be made global.</p></div></div><p>I use the color functions to define symbols globally, they work prior to initialization.</p><p>I have:
</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="k1">namespace</span> color
<span class="number">  2</span><span class="k2">{</span>
<span class="number">  3</span>
<span class="number">  4</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> null_color <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgba_f"><span class="a">al_map_rgba_f</span></a><span class="k2">(</span><span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">1</span>.<span class="n">0</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  5</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> transparent <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_map_rgba_f"><span class="a">al_map_rgba_f</span></a><span class="k2">(</span><span class="n">0</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="number">  6</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> aliceblue <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"aliceblue"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  7</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> antiquewhite <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"antiquewhite"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  8</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> aqua <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"aqua"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number">  9</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> aquamarine <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"aquamarine"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 10</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> azure <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"azure"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 11</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> beige <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"beige"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> bisque <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"bisque"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 13</span><span class="k1">const</span> <a href="http://www.allegro.cc/manual/ALLEGRO_COLOR"><span class="a">ALLEGRO_COLOR</span></a> black <span class="k3">=</span> <a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a><span class="k2">(</span><span class="s">"black"</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 14</span><span class="c">//..</span>
<span class="number"> 15</span>
<span class="number"> 16</span><span class="k2">}</span>
</div></div><p>

with a bunch of other color stuff.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Mon, 29 Jul 2013 05:25:56 +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/613043/988041#target">Mark Oates</a> said:</div><div class="quote"><p> I use the color functions to define symbols globally, they work prior to initialization.</p></div></div><p>I haven&#39;t looked at how those functions are implemented, but I&#39;d say that you&#39;re simply lucky that they do work for you prior to initializing Allegro.  Such behavior isn&#39;t guaranteed to work, and clearly doesn&#39;t for imgregduh.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Mon, 29 Jul 2013 17:58:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Those do happen not to require initialization, but it&#39;s undocumented and shouldn&#39;t be relied on. I could very easily change <span class="source-code"><a href="http://www.allegro.cc/manual/al_color_name"><span class="a">al_color_name</span></a></span> to require Allegro to be initialized without breaking any valid programs by simply using a slightly different code path.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Mon, 29 Jul 2013 18:12:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">LennyLen</a> said:</div><div class="quote"><p>Mark Oates said:<br />I use the color functions to define symbols globally, they work prior to initialization.<br />I haven&#39;t looked at how those functions are implemented, but I&#39;d say that you&#39;re simply lucky that they do work for you prior to initializing Allegro. Such behavior isn&#39;t guaranteed to work, and clearly doesn&#39;t for imgregduh.</p></div></div><p>


Actually, the way that Mark did it, it works.  It seems that namespace is doing the trick
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (imgregduh)</author>
		<pubDate>Tue, 30 Jul 2013 02:12:59 +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/613043/988107#target">imgregduh</a> said:</div><div class="quote"><p> Actually, the way that Mark did it, it works.  It seems that namespace is doing the trick</p></div></div><p>No, it is not. As I said, it just so happens that the functions Mark Oates use are currently implemented not to require Allegro to be initialized (a fact that should not be relied upon). <span class="source-code"><a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a></span> requires Allegro to be initialized, and there&#39;s no way around it.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Tue, 30 Jul 2013 02:21:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">SiegeLord</a> said:</div><div class="quote"><p>No, it is not. As I said, it just so happens that the functions Mark Oates use are current implemented not to require Allegro to be initialize (a fact that should not be relied upon). al_map_rgb requires Allegro to be initialized, and there&#39;s no way around it.</p></div></div><p>

So, what is recommended?  Do I just redeclare the variable for white with this  al_map_rgb(0,0,0) function in each file i need it in ?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (imgregduh)</author>
		<pubDate>Tue, 30 Jul 2013 02:24:58 +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/613043/988108#target">SiegeLord</a> said:</div><div class="quote"><p>.... just so happens that the functions Mark Oates use are currently implemented not to require Allegro to be initialized...</p></div></div><p>mwahahaa mWAAHAHAHAHAH!! <img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" /><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" /><img src="http://www.allegro.cc/forums/smileys/angry.gif" alt="&gt;:(" /><img src="http://www.allegro.cc/forums/smileys/cheesy.gif" alt=":D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mark Oates)</author>
		<pubDate>Tue, 30 Jul 2013 02:28:51 +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/613043/988109#target">imgregduh</a> said:</div><div class="quote"><p> So, what is recommended?  Do I just redeclare the variable for white with this  al_map_rgb(0,0,0) function in each file i need it in ?</p></div></div><p>Either that or reread my post <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Tue, 30 Jul 2013 02:33:55 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title"><a href="http://">torhu</a> said:</div><div class="quote"><p>Either that or reread my post <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" /></p></div></div><p>

k got it
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (imgregduh)</author>
		<pubDate>Tue, 30 Jul 2013 02:39:05 +0000</pubDate>
	</item>
</rss>
