<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>[Please Help] Allegro 5 Text File Output</title>
		<link>http://www.allegro.cc/forums/view/618719</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 18 Aug 2022 02:54:42 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Hello,</p><p>I am trying to make it so that I am to upload a text file and to then display the text onto the display window, but I can&#39;t figure out how to do so. When I execute the program, there is just the red screen but no text. This is what I have so far:</p><p>int main()<br />{<br />	std::fstream myFile;</p><p>	myFile.open(&quot;chapter1.txt&quot;, std::ios::in);<br />        <br />        bool running = false;       <br /> <br />	al_init();<br />	al_init_image_addon();<br />	al_init_font_addon();<br />	al_init_ttf_addon();<br />	al_install_keyboard();<br />	al_install_audio();<br />	al_init_acodec_addon();<br />	al_install_mouse();<br />	al_reserve_samples(1);</p><p>	ALLEGRO_DISPLAY* display = al_create_display(SCREEN_WIDTH, SCREEN_HEIGHT);<br />	ALLEGRO_EVENT_QUEUE* event_queue = al_create_event_queue();<br />	ALLEGRO_FONT* font25 = al_load_ttf_font(&quot;orbitron.ttf&quot;, 25, 0);???</p><p>	al_register_event_source(event_queue, al_get_display_event_source(display));</p><p>	while (!running)<br />	{<br />		al_clear_to_color(al_map_rgb(255, 0, 0));</p><p>		if (myFile.is_open())<br />		{<br />			std::string line;</p><p>			while (std::getline(myFile, line))<br />			{<br />				const char* c = str.c_str();<br />                                al_draw_text(font25, al_map_rgb(WHITE), 0, 0, 0, c);<br />			}<br />			myFile.close();<br />		}					</p><p>		al_flip_display();<br />	}</p><p>}
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Wed, 17 Aug 2022 22:17:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>First thing, do not put a file load in the middle of your logic loop.</p><p>Second, did you verify everything was installed and loaded correctly?<br />Did your font even load?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 17 Aug 2022 22:38:39 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Yes it has loaded and I can write regular text and it can be displayed on the display window. Just having issues with loading text from a file
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Wed, 17 Aug 2022 22:44:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If everything is loaded correctly even your text file, I can&#39;t determine anything else <br />wrong.</p><p>Unless something is wrong with WHITE. How is it defined?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 17 Aug 2022 22:49:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>#define WHITE 255, 255, 255</p><p>The WHITE macro works with no issue; as I am able to use it, for example,</p><p>al_draw_text(font25, al_map_rgb(WHITE), 0, 0, 0, &quot;HEY&quot;); </p><p>Works perfectly fine and displays white text stating &quot;HEY&quot;
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Wed, 17 Aug 2022 23:07:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is your text file encoded?</p><p>also, increment the y value of the text draw as you go through draw text loop
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 17 Aug 2022 23:16:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The text files are encoded as &quot;ANSI&quot; is this a problem?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Wed, 17 Aug 2022 23:23:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Just making sure it didn&#39;t have a unicode char that was ending your string too early.</p><p>Sorry, I can&#39;t see what else it could be.</p><p>Just move your file load/read out of your main loop. Write a function that loads the file and puts it into a vector of strings. Then in your main loop, you can iterate through the vector.</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;vector&gt;</span>
<span class="number">  2</span><span class="p">#include &lt;string&gt;</span>
<span class="number">  3</span><span class="p">#include &lt;fstream&gt;</span>
<span class="number">  4</span>
<span class="number">  5</span><span class="c">// untested</span>
<span class="number">  6</span><span class="k1">bool</span> loadFile<span class="k2">(</span><span class="k1">const</span> std::string<span class="k3">&amp;</span> filename, std::vector<span class="k3">&lt;</span>std::string&gt;<span class="k3">&amp;</span> vec<span class="k2">)</span>
<span class="number">  7</span><span class="k2">{</span>
<span class="number">  8</span>     std::fstream myFile<span class="k2">;</span>
<span class="number">  9</span>     std::string <a href="http://www.allegro.cc/manual/line"><span class="a">line</span></a><span class="k2">;</span>
<span class="number"> 10</span>
<span class="number"> 11</span>     myFile.open<span class="k2">(</span>filename, std::ios::in<span class="k2">)</span><span class="k2">;</span>
<span class="number"> 12</span>
<span class="number"> 13</span>    <span class="k1">if</span> <span class="k2">(</span>myFile.is_open<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 14</span>    <span class="k2">{</span>
<span class="number"> 15</span>          <span class="k1">while</span> <span class="k2">(</span>std::getline<span class="k2">(</span>myFile, <a href="http://www.allegro.cc/manual/line"><span class="a">line</span></a><span class="k2">)</span><span class="k2">)</span>
<span class="number"> 16</span>          <span class="k2">{</span>
<span class="number"> 17</span>               vec.push_back<span class="k2">(</span><a href="http://www.allegro.cc/manual/line"><span class="a">line</span></a><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 18</span>          <span class="k2">}</span>
<span class="number"> 19</span>
<span class="number"> 20</span>        myFile.close<span class="k2">(</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 21</span>        <span class="k1">return</span> <span class="k1">true</span><span class="k2">;</span>
<span class="number"> 22</span>    <span class="k2">}</span>
<span class="number"> 23</span>
<span class="number"> 24</span>    <span class="k1">return</span> <span class="k1">false</span><span class="k2">;</span>
<span class="number"> 25</span><span class="k2">}</span>
</div></div><p>
</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>std::vector<span class="k3">&lt;</span>std::string&gt; vec<span class="k2">;</span>
<span class="number">  2</span>
<span class="number">  3</span><span class="k1">if</span> <span class="k2">(</span><span class="k3">!</span>loadFile<span class="k2">(</span><span class="s">"chapter1.txt"</span>, vec<span class="k2">)</span><span class="k2">)</span>
<span class="number">  4</span><span class="k2">{</span>
<span class="number">  5</span>    <span class="k1">return</span> <span class="k3">-</span><span class="n">1</span><span class="k2">;</span>
<span class="number">  6</span><span class="k2">}</span>
<span class="number">  7</span>
<span class="number">  8</span><span class="k1">while</span> <span class="k2">(</span><span class="k3">!</span>running<span class="k2">)</span>
<span class="number">  9</span><span class="k2">{</span>
<span class="number"> 10</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">255</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"> 11</span>
<span class="number"> 12</span><span class="k1">for</span> <span class="k2">(</span><span class="k1">auto</span> c <span class="k2">:</span> vec<span class="k2">)</span>
<span class="number"> 13</span><span class="k2">{</span>
<span class="number"> 14</span>    <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font25, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span>WHITE<span class="k2">)</span>, <span class="n">0</span>, <span class="n">0</span>, <span class="n">0</span>, c.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
<span class="number"> 15</span><span class="k2">}</span>
<span class="number"> 16</span>
<span class="number"> 17</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"> 18</span><span class="k2">}</span>
</div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Wed, 17 Aug 2022 23:42:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you very much, this worked! How can I make it so that instead of all of the text being congealed into one spot, I can make it look like this:</p><p>How many apples are in the bag?</p><p>A) 5           B) 6</p><p>C) 7           D) 8</p><p>Currently thats how it is formatted in the text file but all of the letters are bunched up. Thank you very much for your help <img src="http://www.allegro.cc/forums/smileys/smiley.gif" alt=":)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Thu, 18 Aug 2022 00:19:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Please attach text file.</p><p>Also, what do you mean by &quot;bunched up&quot;?</p><p>All on the same line?<br />You need to set a y value and increment it each line</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">int</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span>
<span class="k1">for</span> <span class="k2">(</span><span class="k1">auto</span> c <span class="k2">:</span> vec<span class="k2">)</span>
<span class="k2">{</span>
    <a href="http://www.allegro.cc/manual/al_draw_text"><span class="a">al_draw_text</span></a><span class="k2">(</span>font25, <a href="http://www.allegro.cc/manual/al_map_rgb"><span class="a">al_map_rgb</span></a><span class="k2">(</span>WHITE<span class="k2">)</span>, <span class="n">0</span>, y, <span class="n">0</span>, c.c_str<span class="k2">(</span><span class="k2">)</span><span class="k2">)</span><span class="k2">;</span>
    y <span class="k3">+</span><span class="k3">=</span> <span class="k2">(</span><a href="http://www.allegro.cc/manual/al_get_font_line_height"><span class="a">al_get_font_line_height</span></a><span class="k2">(</span>font25<span class="k2">)</span> <span class="k3">+</span> <span class="n">4</span><span class="k2">)</span><span class="k2">;</span>
    <span class="c">// 4 is extra padding between lines</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Thu, 18 Aug 2022 00:26:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The letters on the display window from the text file are all overlapping each other, is what I mean. I have attached the text file and an example of what I mean, thank you!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Thu, 18 Aug 2022 00:51:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You&#39;re drawing the text at the same y coordinate. change the y value every draw.</p><p>Increment it the height of the font plus a padding like I showed you above.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Thu, 18 Aug 2022 00:59:35 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you for your help. I added that specific line, and the text does not display anymore
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Thu, 18 Aug 2022 01:20:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>It should. </p><p>What value is SCREEN_HEIGHT? Is it big enough to draw all the lines of text?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Thu, 18 Aug 2022 01:33:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Thank you for your help.</p><p>SCREEN_WIDTH is 800<br />SCREEN_HEIGHT is 600
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Thu, 18 Aug 2022 01:51:21 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Something&#39;s not right. </p><p>Do you have <span class="source-code"><span class="k1">int</span> y <span class="k3">=</span> <span class="n">0</span><span class="k2">;</span></span> outside the for loop or inside?</p><p>Can you post your main function code again for what you currently have?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Thu, 18 Aug 2022 01:57:14 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Sorry, I had int y in the wrong place and now it works. Thank you very much for your help. I have one final question then I will stop bugging you. Let&#39;s say in my text file I have two questions. How do I make it so that each question is segmented to where it will only show question one, then once the user answers question one then it will show question two, and so forth?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (variancegears)</author>
		<pubDate>Thu, 18 Aug 2022 02:41:56 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There are a few ways? </p><p>If the number of answers are consistent, you could format the file as such:</p><p>question1<br />answer1<br />answer2<br />answer3<br />answer4<br />question2<br />answer1<br />answer2<br />answer3<br />answer4</p><p>Then you can print the question and the 4 answers. Then advance 5 lines to the next</p><p>If the number of questions vary, you can have a delimiter between question sets. They you can tell where each question ends and the new question starts.</p><p>question1<br />answer1<br />answer2<br />answer3<br />answer4<br />---<br />question2<br />answer1<br />answer2<br />---<br />question3<br />answer1<br />answer2<br />answer3
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (DanielH)</author>
		<pubDate>Thu, 18 Aug 2022 02:54:42 +0000</pubDate>
	</item>
</rss>
