<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>textprintf help</title>
		<link>http://www.allegro.cc/forums/view/596288</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 14 May 2008 06:56:29 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m a newbie here and also a newbie to the allegro library.this is the code that I have problem with :</p><p>#include&quot;allegro.h&quot;<br />#include&lt;conio.h&gt;<br />#include&lt;stdlib.h&gt;<br />int main(){<br />    allegro_init();<br />    <br />    install_keyboard();<br />    <br />    int ret=set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);<br />    if(ret!=0){<br />    allegro_message(allegro_error);<br />    return 0;<br />    }<br />    <br />    textprintf(screen, font, 0, 0, makecol(100,255,125),&quot;%dx%d&quot;, SCREEN_W, SCREEN_H);<br />    <br />    while(! key[KEY_ESC]);<br />    <br />    allegro_exit();<br />    }<br />    END_OF_MAIN();</p><p>I copied it straight from the book yet it did not compiled perfectly.the compiler said there&#39;s an error in line 15, which is the &#39;textprintf line&#39;.any help would be greatly appreciated.thank you.</p><p>And could someone show me how to distinguish the code from the text?something like 
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (red_4900)</author>
		<pubDate>Sat, 10 May 2008 20:16:42 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Distinguish code from text using the [ code ] tags (but with no spaces). E.g.</p><p>[ code ]<br />code<br />[ /code ]</p><p>As to the real problem — are you sure your compiler gave an error, not a warning? Can you supply the text of the error?</p><p>In general textprintf is deprecated in favour of textprintf_ex — it&#39;s recommended that you use the latter instead. For you that should be as simple as:</p><p>textprintf(screen, font, 0, 0, makecol(100,255,125), -1, &quot;%dx%d&quot;, SCREEN_W, SCREEN_H);
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Sat, 10 May 2008 20:43:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>What error messages do you get?  textprintf is deprecated, textprintf_ex replaces it, but it should still work.</p><p>And you can enclose you code in code tags, like this:
</p><pre>&lt;code&gt;Your code here
&lt;/code&gt;</pre><p>

EDIT: Well, I guess two replies are better than one, eh?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (torhu)</author>
		<pubDate>Sat, 10 May 2008 20:45:30 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Thomas Harte said:</div><div class="quote"><p>
In general textprintf is deprecated in favour of textprintf_ex — it&#39;s recommended that you use the latter instead. For you that should be as simple as:</p><p>textprintf(screen, font, 0, 0, makecol(100,255,125), -1, &quot;%dx%d&quot;, SCREEN_W, SCREEN_H);
</p></div></div><p>

Pssst.... You forgot to rename the function:<br /> <br /><span class="source-code"><a href="http://www.allegro.cc/manual/textprintf_ex" target="_blank"><span class="a">textprintf_ex</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">100</span>,<span class="n">255</span>,<span class="n">125</span><span class="k2">)</span>, <span class="k3">-</span><span class="n">1</span>, <span class="s">"%dx%d"</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></p><p>edit:</p><div class="quote_container"><div class="title">red_4900 said:</div><div class="quote"><p>
I copied it straight from the book
</p></div></div><p>

Let me guess, the book was <i>Game Programming All in One</i>?  Unfortunately, that book is full of errors and bad coding practices (such as including <tt>conio.h</tt> when none of the functions in that library are used).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 10 May 2008 20:58:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh, yes, listen to LennyLen&#39;s correction to my post — don&#39;t listen to my original post.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Sat, 10 May 2008 21:44:12 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I did as what u guys told me but it showed this error:<br />Compiler: Default compiler<br />Building Makefile: &quot;C:\Dev-Cpp\Programming\Greet\Makefile.win&quot;<br />Executing  make...<br />mingw32-make -f &quot;C:\Dev-Cpp\Programming\Greet\Makefile.win&quot; all<br />g++.exe -c test2.c -o test2.o -I&quot;C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include&quot;  -I&quot;C:/Dev-Cpp/include/c++/3.4.2/backward&quot;  -I&quot;C:/Dev-Cpp/include/c++/3.4.2/mingw32&quot;  -I&quot;C:/Dev-Cpp/include/c++/3.4.2&quot;  -I&quot;C:/Dev-Cpp/include&quot;   </p><p>g++.exe test1.o test2.o Project1_private.res -o &quot;Project1.exe&quot; -L&quot;C:/Dev-Cpp/lib&quot; -mwindows -lalleg </p><p>test2.o(.text+0x0):test2.c: multiple definition of `_mangled_main()&#39;<br />test1.o(.text+0x0):test1.cpp: first defined here<br />test2.o(.text+0x146):test2.c: multiple definition of `WinMain@16&#39;<br />test1.o(.text+0x132):test1.cpp: first defined here<br />collect2: ld returned 1 exit status</p><p>mingw32-make: *** [Project1.exe] Error 1</p><p>Execution terminated</p><p>this is my code:
</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"allegro.h"</span></td></tr><tr><td class="number">2</td><td><span class="p">#include&lt;stdlib.h&gt;</span></td></tr><tr><td class="number">3</td><td><span class="k1">int</span> main<span class="k2">(</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">4</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">5</td><td>    </td></tr><tr><td class="number">6</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">7</td><td>    </td></tr><tr><td class="number">8</td><td>    <span class="k1">int</span> ret<span class="k3">=</span><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">9</td><td>    <span class="k1">if</span><span class="k2">(</span>ret<span class="k3">!</span><span class="k3">=</span><span class="n">0</span><span class="k2">)</span><span class="k2">{</span></td></tr><tr><td class="number">10</td><td>    <a href="http://www.allegro.cc/manual/allegro_message" target="_blank"><span class="a">allegro_message</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/allegro_error" target="_blank"><span class="a">allegro_error</span></a><span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">11</td><td>    <span class="k1">return</span> <span class="n">1</span><span class="k2">;</span></td></tr><tr><td class="number">12</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">13</td><td>    </td></tr><tr><td class="number">14</td><td>    <a href="http://www.allegro.cc/manual/textprintf_ex" target="_blank"><span class="a">textprintf_ex</span></a><span class="k2">(</span><a href="http://www.allegro.cc/manual/screen" target="_blank"><span class="a">screen</span></a>, <a href="http://www.allegro.cc/manual/font" target="_blank"><span class="a">font</span></a>, <span class="n">0</span>, <span class="n">0</span>, <a href="http://www.allegro.cc/manual/makecol" target="_blank"><span class="a">makecol</span></a><span class="k2">(</span><span class="n">255</span>,<span class="n">255</span>,<span class="n">255</span><span class="k2">)</span>,<span class="k3">-</span><span class="n">1</span>,<span class="s">"%dx%d"</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></td></tr><tr><td class="number">15</td><td>    </td></tr><tr><td class="number">16</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">17</td><td>    </td></tr><tr><td class="number">18</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">19</td><td>    <span class="k2">}</span></td></tr><tr><td class="number">20</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>

yes,I&#39;m using the &quot;Game Programming All In One&quot;.I cant find any other books that&#39;s noob-friendly.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (red_4900)</author>
		<pubDate>Sat, 10 May 2008 22:20:58 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
g++.exe <b>test1.o test2.o</b> Project1_private.res -o &quot;Project1.exe&quot; -L&quot;C:/Dev-Cpp/lib&quot; -mwindows -lalleg
</p></div></div><p>

There are two object files in your project, even though you appear to only have one source file. Did you originally have a file in your project called test1.c that you removed and replaced with a new file called test2.c?</p><p>Try creating a new project, as the code you just posted compiles as expected (no errors, just a warning).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (LennyLen)</author>
		<pubDate>Sat, 10 May 2008 22:32:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Don&#39;t use a semi-colon after END_OF_MAIN() , it&#39;s not supposed to be there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Sun, 11 May 2008 04:09:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hmmm that is weird... I have always put a semi-colon after END_OF_MAIN and it works fine.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Ryan Stover)</author>
		<pubDate>Wed, 14 May 2008 05:51:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><a href="http://www.allegro.cc/manual/api/using-allegro/end_of_main">END_OF_MAIN() manual entry</a> - It may work but it still doesn&#39;t belong there. It&#39;s a define , not a statement that needs to be ended with a semi-colon.
</p><div class="source-code snippet"><div class="inner"><pre><span class="p">#define SOME_CODE \</span>
<span class="p">for (int i = 0 ; i &lt; 10 ; i++) {do_stuff();} </span>

<span class="c">// Which of the next two statements would be correct?</span>
SOME_CODE

SOME_CODE<span class="k2">;</span>
</pre></div></div><p>

As you can see , the semi-colon would be inappropriate there.</p><p>END_OF_MAIN() is a platform specific #define so there are several possible definitions.<br />Here is the one from alwin.h :<br /> </p><div class="source-code"><div class="toolbar"></div><div class="inner"><table width="100%"><tbody><tr><td class="number">1</td><td>&#160;</td></tr><tr><td class="number">2</td><td><span class="p">#if (!defined ALLEGRO_NO_MAGIC_MAIN) &amp;&amp; (!defined ALLEGRO_SRC)</span></td></tr><tr><td class="number">3</td><td>&#160;</td></tr><tr><td class="number">4</td><td>   <span class="p">#define ALLEGRO_MAGIC_MAIN</span></td></tr><tr><td class="number">5</td><td>   <span class="p">#define main _mangled_main</span></td></tr><tr><td class="number">6</td><td>   <span class="p">#undef END_OF_MAIN</span></td></tr><tr><td class="number">7</td><td>&#160;</td></tr><tr><td class="number">8</td><td>   <span class="c">/* disable strict pointer typing because of the vague prototype below */</span></td></tr><tr><td class="number">9</td><td>   <span class="p">#define NO_STRICT</span></td></tr><tr><td class="number">10</td><td>&#160;</td></tr><tr><td class="number">11</td><td>   <span class="p">#ifdef __cplusplus</span></td></tr><tr><td class="number">12</td><td>      <span class="k1">extern</span> <span class="s">"C"</span> <span class="k1">int</span> __stdcall WinMain<span class="k2">(</span><span class="k1">void</span> <span class="k3">*</span>hInst, <span class="k1">void</span> <span class="k3">*</span>hPrev, <span class="k1">char</span> <span class="k3">*</span>Cmd, <span class="k1">int</span> nShow<span class="k2">)</span><span class="k2">;</span></td></tr><tr><td class="number">13</td><td>   <span class="p">#endif</span></td></tr><tr><td class="number">14</td><td>&#160;</td></tr><tr><td class="number">15</td><td>   <span class="p">#define END_OF_MAIN()                                                     \</span></td></tr><tr><td class="number">16</td><td><span class="p">                                                                             \ </span></td></tr><tr><td class="number">17</td><td><span class="p">      int __stdcall WinMain(void *hInst, void *hPrev, char *Cmd, int nShow)  \ </span></td></tr><tr><td class="number">18</td><td><span class="p">      {                                                                      \ </span></td></tr><tr><td class="number">19</td><td><span class="p">         return _WinMain((void *)_mangled_main, hInst, hPrev, Cmd, nShow);   \ </span></td></tr><tr><td class="number">20</td><td><span class="p">      } </span></td></tr><tr><td class="number">21</td><td>&#160;</td></tr><tr><td class="number">22</td><td><span class="p">#endif</span></td></tr></tbody></table></div></div><p>

So you can see that it doesn&#39;t need a semi-colon there.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Edgar Reynaldo)</author>
		<pubDate>Wed, 14 May 2008 06:56:29 +0000</pubDate>
	</item>
</rss>
